summaryrefslogtreecommitdiff
path: root/scenes/crawlers
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-05-21 17:20:21 -0400
committerbd <bdunahu@operationnull.com>2025-05-21 17:20:21 -0400
commita00b14bcf2084a1e68f57620e27956813d469aad (patch)
tree5f061482110634a81d3124e3d9977853a8d467e9 /scenes/crawlers
parent515a81c313d83195ea77c5ae5e222b0118276279 (diff)
Make enemy color turn to red with missing health
Diffstat (limited to 'scenes/crawlers')
-rw-r--r--scenes/crawlers/soldier.gd15
1 files changed, 13 insertions, 2 deletions
diff --git a/scenes/crawlers/soldier.gd b/scenes/crawlers/soldier.gd
index 2db3f60..1bd7549 100644
--- a/scenes/crawlers/soldier.gd
+++ b/scenes/crawlers/soldier.gd
@@ -1,12 +1,23 @@
extends CharacterBody2D
@export var speed = 50.0
-@export var health = 40
+@export var max_health = 40
+var _health = max_health
func _process(delta):
get_parent().set_progress(get_parent().get_progress() + speed * delta)
if get_parent().get_progress_ratio() == 1:
queue_free()
- if health <= 0:
+func deal_damage(damage):
+ _health -= damage
+ if _health <= 0:
queue_free()
+ else:
+ _update_color()
+
+func _update_color():
+ var ratio : float = float(_health) / max_health
+ var target_color = Color(1, ratio, ratio)
+
+ $Sprite2D.modulate = target_color