Added basic player health and damage taking timeout
This commit is contained in:
@@ -17,6 +17,12 @@ var desired_rotation: float = 0
|
||||
# Resources / money
|
||||
var resources: int = 0
|
||||
|
||||
# Health
|
||||
var healthPoints: int = 100
|
||||
var isAlive: bool = true
|
||||
@onready var invulnerable_cooldown_timer: Timer = $InvulnerableCooldownTimer
|
||||
var hasiframes: bool = false # only used for iframe after collision for now
|
||||
|
||||
func _ready() -> void:
|
||||
var screen_size = get_viewport_rect().size
|
||||
GameManager.init_screen_size(screen_size.x, screen_size.y)
|
||||
@@ -27,17 +33,19 @@ func _ready() -> void:
|
||||
|
||||
|
||||
func _process(delta):
|
||||
velocity = Vector2.ZERO
|
||||
if Input.is_action_pressed("move_right"):
|
||||
velocity.x += 1
|
||||
if Input.is_action_pressed("move_left"):
|
||||
velocity.x -= 1
|
||||
if Input.is_action_pressed("move_down"):
|
||||
velocity.y += 1
|
||||
if Input.is_action_pressed("move_up"):
|
||||
velocity.y -= 1
|
||||
if Input.is_action_pressed("try_attack"):
|
||||
try_attack()
|
||||
# TODO: Connects this to some respawn screen
|
||||
if isAlive:
|
||||
velocity = Vector2.ZERO
|
||||
if Input.is_action_pressed("move_right"):
|
||||
velocity.x += 1
|
||||
if Input.is_action_pressed("move_left"):
|
||||
velocity.x -= 1
|
||||
if Input.is_action_pressed("move_down"):
|
||||
velocity.y += 1
|
||||
if Input.is_action_pressed("move_up"):
|
||||
velocity.y -= 1
|
||||
if Input.is_action_pressed("try_attack"):
|
||||
try_attack()
|
||||
|
||||
|
||||
if not velocity.is_zero_approx():
|
||||
@@ -66,7 +74,7 @@ func _on_attack_timeout() -> void:
|
||||
sprite.play("default")
|
||||
attack_cooldown_timer.start()
|
||||
|
||||
func _on_cooldown_timeout() -> void:
|
||||
func _on_attack_cooldown_timeout() -> void:
|
||||
can_attack = true
|
||||
|
||||
func _on_attack_hit(body: Node2D) -> void:
|
||||
@@ -81,10 +89,19 @@ func _on_attack_hit(body: Node2D) -> void:
|
||||
await get_tree().create_timer(0.2).timeout
|
||||
sprite.play("default")
|
||||
# TODO: resource handling logic
|
||||
|
||||
func _on_invulnerable_cooldown_timeout() -> void:
|
||||
hasiframes = false
|
||||
|
||||
func handle_damage(dmg: int, src: Node) -> void:
|
||||
# TODO: damage logic
|
||||
pass
|
||||
# TODO: enhanced damage logic (src entity effects?)
|
||||
if not hasiframes:
|
||||
print("Player took %d damage." % dmg)
|
||||
healthPoints -= dmg
|
||||
hasiframes = true
|
||||
invulnerable_cooldown_timer.start()
|
||||
if healthPoints <= 0:
|
||||
isAlive = false
|
||||
|
||||
func collect_resource(damnt: int) -> void:
|
||||
resources += damnt
|
||||
|
||||
Reference in New Issue
Block a user