stamina and health bar
This commit is contained in:
parent
d17b16ad5b
commit
5b417b540b
9 changed files with 184 additions and 10 deletions
|
|
@ -11,6 +11,7 @@ enum State {
|
|||
|
||||
const MOVE_SPEED := 7.5
|
||||
const DASH_SPEED := 25.
|
||||
const DASH_COST := .5
|
||||
|
||||
static var instance: Player
|
||||
|
||||
|
|
@ -25,6 +26,7 @@ var health := 3:
|
|||
health = v
|
||||
if is_node_ready():
|
||||
%HealthLabel.text = "Health: %d" % v
|
||||
%HealthBar.update(v)
|
||||
|
||||
var state := State.NORMAL
|
||||
var dash_direction: Vector2
|
||||
|
|
@ -59,8 +61,8 @@ func _process_movement(delta: float) -> void:
|
|||
velocity = exp_lerp(velocity, desired_velocity, 20, delta)
|
||||
move_and_slide()
|
||||
|
||||
if Input.is_action_just_pressed("dash") and stamina >= 1. and not input.is_zero_approx():
|
||||
stamina = 0.
|
||||
if Input.is_action_just_pressed("dash") and stamina >= DASH_COST and not input.is_zero_approx():
|
||||
stamina -= DASH_COST
|
||||
dash_direction = input
|
||||
state = State.DASHING
|
||||
await get_tree().create_timer(.25, false).timeout
|
||||
|
|
@ -139,6 +141,7 @@ func _process(delta: float) -> void:
|
|||
gun_index += 1
|
||||
|
||||
func damage(damager: Node3D) -> void:
|
||||
if health <= 0: return
|
||||
if state == State.DASHING:
|
||||
damager.queue_free()
|
||||
else:
|
||||
|
|
@ -147,5 +150,5 @@ func damage(damager: Node3D) -> void:
|
|||
damage_clock = 3
|
||||
shake_duration = .25
|
||||
|
||||
if health == 0:
|
||||
if health <= 0:
|
||||
died.emit()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue