From e549788fcdc266480f2e7453c675859a32ffa60f Mon Sep 17 00:00:00 2001 From: Jeremy Baxter Date: Sat, 24 Jan 2026 12:43:28 +1300 Subject: [PATCH] player: add protected and suspended members `suspended' is now for suspending a player's movement input keys; `protected' is for preventing a player's death except for special cases such as when health goes below 1 or the player drops out of the world. To kill a player without checking `protected', use _die(). --- player/player.gd | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/player/player.gd b/player/player.gd index 312d369..4b712e6 100644 --- a/player/player.gd +++ b/player/player.gd @@ -10,6 +10,8 @@ const gear_slots = ["1", "2", "3"] var starting_gear = preload("res://gears/gear.tscn") +var dead = false +var protected = false var suspended = false var direction = Vector3.ZERO var target_velocity = Vector3.ZERO @@ -45,6 +47,8 @@ func message(string): # State functions func harm(hp): + if protected: + return assert(hp >= 0) _health -= hp make_hud() @@ -57,7 +61,8 @@ func heal(hp): func health(): return _health -func die(): +func _die(): + dead = true suspended = true visible = false $HUD.visible = false @@ -72,12 +77,17 @@ func die(): $RespawnTimer.start() message("Le gone") +func die(): + if protected: + return + _die() + func respawn(): position = Vector3(spawn) $CameraGimbal.reset() _health = 100 visible = true - suspended = false + dead = false # add starting gear var gear = starting_gear.instantiate() @@ -185,16 +195,17 @@ func do_movement(delta): var mx = 0 var mz = 0 - if Input.is_action_pressed("move_forward"): - mz -= 1 - if Input.is_action_pressed("move_back"): - mz += 1 - if Input.is_action_pressed("move_left"): - mx -= 1 - if Input.is_action_pressed("move_right"): - mx += 1 - if Input.is_action_pressed("jump") and is_on_floor(): - target_velocity.y = jump_power + if not suspended: + if Input.is_action_pressed("move_forward"): + mz -= 1 + if Input.is_action_pressed("move_back"): + mz += 1 + if Input.is_action_pressed("move_left"): + mx -= 1 + if Input.is_action_pressed("move_right"): + mx += 1 + if Input.is_action_pressed("jump") and is_on_floor(): + target_velocity.y = jump_power if !(mx == 0 and mz == 0): move_player(mx, mz) @@ -227,12 +238,12 @@ func _ready(): respawn() func _physics_process(delta): - if health() < 1 or position.y <= -1000: - die() - - if suspended: + if dead: return + if health() < 1 or position.y <= -1000: + _die() + # Backpack keys do_backpack_keys() # Movement