diff --git a/player/player.gd b/player/player.gd index 312d369..6cf787c 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() @@ -123,6 +133,8 @@ func use_backpack_slot(n): return func equip(gear: Gear): + if suspended: + return var gear_name = gear.gear_name() # do we have the gear equipped? if gear_name == $Pivot/Container/Gear.gear_name(): @@ -185,16 +197,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 +240,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