My first 2D game in Godot 4.4
This commit is contained in:
24
player.gd
Normal file
24
player.gd
Normal file
@@ -0,0 +1,24 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user