From a677a3e8ed63241e7931265941d562284a15d16a Mon Sep 17 00:00:00 2001 From: bd Date: Fri, 23 May 2025 11:44:21 -0400 Subject: Move enemy logic to base_crawler, add crawler flip animation --- scripts/base_crawler.gd | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 scripts/base_crawler.gd (limited to 'scripts/base_crawler.gd') diff --git a/scripts/base_crawler.gd b/scripts/base_crawler.gd new file mode 100644 index 0000000..3525e97 --- /dev/null +++ b/scripts/base_crawler.gd @@ -0,0 +1,44 @@ +extends CharacterBody2D + +@onready var sprite_node = $Sprite2D + +var damage : int +var speed : float +var max_health : float +var worth : int + +var _health : float +var _timer : Timer + +func _ready() -> void: + _health = max_health + + _timer = Timer.new() + _timer.wait_time = speed / 60 + _timer.autostart = true + _timer.connect("timeout", Callable(self, "_on_animate_timeout")) + add_child(_timer) + + +func _process(delta): + get_parent().set_progress(get_parent().get_progress() + speed * delta) + if get_parent().get_progress_ratio() == 1: + GameData.subtract_morale(damage) + queue_free() + +func deal_damage(tower_damage): + _health -= tower_damage + if _health <= 0: + GameData.add_life(worth) + queue_free() + else: + _update_color() + +func _update_color(): + var ratio : float = _health / max_health + var target_color = Color(1, ratio, ratio) + + sprite_node.modulate = target_color + +func _on_animate_timeout(): + sprite_node.scale.x = -sprite_node.scale.x -- cgit v1.2.3