summaryrefslogtreecommitdiff
path: root/Scenes/Entities/Enemies/Balloon.gd
blob: bc79f24054b1f440ed3838fda2c3dcf48e6bb7b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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