50 lines
1.1 KiB
GDScript
50 lines
1.1 KiB
GDScript
class_name Entity extends CharacterBody2D
|
|
|
|
signal health_changed(new_amount)
|
|
signal died
|
|
|
|
@export var current_mask_data: MaskData
|
|
@export var max_health: int = 3
|
|
@export var move_speed: float = 50.0
|
|
@export var friction: float = 0.7
|
|
@export var death_scene : PackedScene
|
|
|
|
@onready var health: int = max_health
|
|
var mask_use_cd = 0
|
|
|
|
var can_attack: bool = true
|
|
|
|
func use_mask(target : Vector2):
|
|
if mask_use_cd <= 0:
|
|
current_mask_data.activate(self, target)
|
|
mask_use_cd = current_mask_data.cooldown
|
|
|
|
func damage(amount: int = 1) -> void:
|
|
health -= amount
|
|
health_changed.emit(health)
|
|
|
|
_play_hit_flash()
|
|
|
|
if health <= 0:
|
|
die()
|
|
|
|
func die():
|
|
if death_scene:
|
|
var death : Node2D = death_scene.instantiate()
|
|
get_parent().add_child(death)
|
|
death.global_position = global_position
|
|
died.emit()
|
|
|
|
|
|
func _apply_movement(_delta: float) -> void:
|
|
velocity *= friction
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
mask_use_cd -= delta
|
|
_apply_movement(delta)
|
|
move_and_slide()
|
|
|
|
func _play_hit_flash():
|
|
var tween = create_tween()
|
|
tween.tween_property(self, "modulate", Color.CRIMSON, 0.1)
|
|
tween.tween_property(self, "modulate", Color.WHITE, 0.3)
|