fuzzyworld

godot-shooter / commit

Start the player off with no weapon at all.

a5758228a10da50cc629fa2cd3a6d0d2f86b6ab2 · Pavel Safronov · 2023-11-30 11:22:29 -0800 · parents 023ec2fb81f2

Start the player off with no weapon at all.
 actors/Player.gd   |  3 +--
 scenes/HUD.gd      |  9 +++++++--
 weapons/Weapons.gd | 11 +++++++++++
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/actors/Player.gd b/actors/Player.gd
index ab16946..0b5c1a9 100644
--- a/actors/Player.gd
+++ b/actors/Player.gd
@@ -40,7 +40,6 @@ const Utils = preload("res://utils/Utils.gd")
 const PopupControl = preload("res://utils/Popup.tscn")
 
 var weapon: Weapon
-var default_weapon: Weapon = Weapons.create_smg_gun()
 var dead = false
 var velocity: Vector2
 var can_fire = true
@@ -48,7 +47,7 @@ var settings: Settings
 
 func _ready() -> void:
 	velocity= Vector2.UP * move_speed
-	weapon = Weapons.create_basic_gun()
+	weapon = Weapons.create_non_gun()
 
 #	Utils.remove_user_settings()
 	settings = Utils.load_user_settings()
diff --git a/scenes/HUD.gd b/scenes/HUD.gd
index f4cb76f..108cc55 100644
--- a/scenes/HUD.gd
+++ b/scenes/HUD.gd
@@ -86,5 +86,10 @@ func _on_PauseButton_pressed() -> void:
 	emit_signal("paused")
 
 func set_current_weapon(weapon: Weapon) -> void:
-	weapon_label.text = "%s:" % weapon.name
-	ammo_label.text = "%s" % weapon.ammo
+	var is_non_weapon = weapon.name == ""
+	if is_non_weapon:
+		weapon_label.text = ""
+		ammo_label.text = ""
+	else:
+		weapon_label.text = "%s:" % weapon.name
+		ammo_label.text = "%s" % weapon.ammo
diff --git a/weapons/Weapons.gd b/weapons/Weapons.gd
index 15589e1..fc4981f 100644
--- a/weapons/Weapons.gd
+++ b/weapons/Weapons.gd
@@ -3,6 +3,17 @@ tool
 
 const Constants = preload("res://utils/Constants.gd")
 
+static func create_non_gun() -> Weapon:
+	var weapon = Weapon.new()
+	weapon.shooting_range = 0
+	weapon.particle_lifetime_secs = 0
+	weapon.cooldown_seconds = 0
+	weapon.damage_amount = 10
+	weapon.name = ""
+	weapon.ammo = 0
+	weapon.reload_size = 0
+	return weapon
+
 static func create_basic_gun() -> Weapon:
 	var weapon = Weapon.new()
 	weapon.particle = preload("res://weapons/Bullet.tscn")