summaryrefslogtreecommitdiff
path: root/Scenes/Entities/Enemies/Balloon.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-04-14 21:49:20 +0200
committerDaniel Weipert <git@mail.dweipert.de>2024-04-14 21:49:20 +0200
commitf27937e6e9b6a7146dd09fc711d2d293ecf5abbf (patch)
treee0ddd5e6d356000e4f29af6211a736284a4972ee /Scenes/Entities/Enemies/Balloon.gd
parent96d36cee33d6321834565f0a5d412ef95c5ceffd (diff)
update
Diffstat (limited to 'Scenes/Entities/Enemies/Balloon.gd')
-rw-r--r--Scenes/Entities/Enemies/Balloon.gd43
1 files changed, 43 insertions, 0 deletions
diff --git a/Scenes/Entities/Enemies/Balloon.gd b/Scenes/Entities/Enemies/Balloon.gd
new file mode 100644
index 0000000..bc79f24
--- /dev/null
+++ b/Scenes/Entities/Enemies/Balloon.gd
@@ -0,0 +1,43 @@
+extends CharacterBody2D
+
+
+@export var health: int
+
+
+func _ready():
+ add_to_group("enemies")
+
+ get_node("Collision").init()
+
+ get_node("Movement").connect("direction_changed", func(current_direction):
+ var frame = $AnimatedSprite2D.frame
+ var progress = $AnimatedSprite2D.frame_progress
+ if current_direction == Vector2.UP:
+ $AnimatedSprite2D.play("up")
+ elif current_direction == Vector2.DOWN:
+ $AnimatedSprite2D.play("down")
+ elif current_direction == Vector2.LEFT:
+ $AnimatedSprite2D.play("left")
+ elif current_direction == Vector2.RIGHT:
+ $AnimatedSprite2D.play("right")
+ $AnimatedSprite2D.set_frame_and_progress(frame, progress)
+ )
+
+ get_node("Collision").connect("collided", func(area):
+ if area.is_in_group("explosions"):
+ health -= 1
+ if health <= 0:
+ set_physics_process(false)
+ remove_child(get_node("Movement"))
+
+ $AnimatedSprite2D.play("death")
+ await $AnimatedSprite2D.animation_finished
+ # todo shrink to 0
+ queue_free()
+ )
+
+
+func _physics_process(delta):
+ get_node("Movement").physics_process(delta)
+
+ # todo: animation shadow