40 lines
958 B
GDScript
40 lines
958 B
GDScript
extends CharacterBody2D
|
|
|
|
signal health_depleted
|
|
signal player_takes_damage
|
|
signal shooted
|
|
signal level_up
|
|
|
|
@export var SPEED := 600
|
|
@export var DAMAGE_RATE := 10.0
|
|
|
|
var health := 100.0
|
|
|
|
@onready var happy_boo = $HappyBoo
|
|
@onready var hurt_box: Area2D = %HurtBox
|
|
@onready var progress_bar: ProgressBar = %ProgressBar
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
var direction = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
|
velocity = direction * SPEED
|
|
move_and_slide()
|
|
|
|
if velocity.length() > 0.0:
|
|
happy_boo.play_walk_animation()
|
|
else:
|
|
happy_boo.play_idle_animation()
|
|
|
|
var overlapping_mobs = hurt_box.get_overlapping_bodies()
|
|
if overlapping_mobs.size() > 0:
|
|
player_takes_damage.emit()
|
|
health -= DAMAGE_RATE * overlapping_mobs.size() * delta
|
|
progress_bar.value = health
|
|
if health <= 0.0:
|
|
health_depleted.emit()
|
|
|
|
func _on_gun_shooted() -> void:
|
|
shooted.emit()
|
|
|
|
func _on_game_level_up() -> void:
|
|
level_up.emit()
|