Files
ShootahGame2D/player.gd

25 lines
638 B
GDScript

extends CharacterBody2D
signal health_depleted
var health = 100.0
var move_speed := 400.0
func _physics_process(delta: float) -> void:
var direction = Input.get_vector("move_left", "move_right", "move_up", "move_down")
velocity = (direction * move_speed)
move_and_slide()
if velocity.length() > 0.0:
%HappyBoo.play_walk_animation()
else:
%HappyBoo.play_idle_animation()
const DAMAGE_RATE = 15.0
var overlapping_mobs = %Hitbox.get_overlapping_bodies()
if overlapping_mobs.size() > 0:
health -= (DAMAGE_RATE * overlapping_mobs.size()) * delta
%ProgressBar.value = health
if health <= 0.0:
health_depleted.emit()