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().
This commit is contained in:
Jeremy Baxter 2026-01-24 12:43:28 +13:00
parent 6342b751f8
commit e549788fcd

View file

@ -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,6 +195,7 @@ func do_movement(delta):
var mx = 0
var mz = 0
if not suspended:
if Input.is_action_pressed("move_forward"):
mz -= 1
if Input.is_action_pressed("move_back"):
@ -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