21 lines
486 B
GDScript
21 lines
486 B
GDScript
extends CharacterBody2D
|
|
signal health_depleted
|
|
|
|
var health = 100.0
|
|
const DAMAGE_RATE = 5.0
|
|
|
|
|
|
func _physics_process(delta):
|
|
var direction = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
|
velocity = direction * 200
|
|
move_and_slide()
|
|
|
|
|
|
var overlappong_mobs = %Hurtbox.get_overlapping_bodies()
|
|
|
|
if overlappong_mobs.size() > 0 :
|
|
health -= DAMAGE_RATE * overlappong_mobs.size() * delta
|
|
%ProgressBar.value = health
|
|
if health <= 0.0:
|
|
health_depleted.emit()
|