summaryrefslogtreecommitdiff
path: root/whispy_woods.gd
blob: 71fe5a45ceaa2cdc483b3ffc982f91c70c02a15e (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
extends Area2D


var hp: int = 6 :
	set(value):
		hp = value
		Game.boss_hp_changed.emit(hp)


func _ready() -> void:
	Game.boss_initialized.emit(hp)


func _process(_delta: float) -> void:
	# TODO: spawn apples
	# TODO: blow wind
	pass


func blow_wind():
	$BlinkTimer.paused = true
	
	for i in range(3):
		$Mouth.play("mouth_shoot")
		
		var shot = preload("res://air_shot.tscn").instantiate() as Area2D
		shot.global_position = $Mouth.global_position + Vector2(0, randi() % 8)
		shot.direction = -1
		shot.collision_layer = 0
		shot.set_collision_layer_value(2, true)
		shot.set_collision_layer_value(10, true)
		shot.collision_mask = 0
		shot.set_collision_mask_value(1, true)
		shot.add_to_group("enemy")
		get_tree().current_scene.add_child(shot)
		shot.hit.connect(func(_node):
			if is_instance_valid(shot):
				shot.queue_free()
		)
		shot.end_of_life.connect(func():
			await get_tree().create_timer(0.2).timeout
			if is_instance_valid(shot):
				shot.queue_free()
		)
		
		await get_tree().create_timer(0.25).timeout
		$Mouth.play("hole_idle")
		await get_tree().create_timer(0.25).timeout
	
	$BlinkTimer.paused = false


func hit_by_projectile(hit_position: Vector2):
	var effect_star_scene := preload("res://effect_star.tscn")
	for direction in [Vector2(1, 1), Vector2(1, -1), Vector2(-1, -1), Vector2(-1, 1)]:
		var effect_star := effect_star_scene.instantiate()
		effect_star.global_position = hit_position
		get_tree().current_scene.add_child(effect_star)
		var effect_tween := get_tree().create_tween()
		effect_tween.tween_property(
			effect_star,
			"global_position",
			effect_star.global_position + direction * 16,
			0.1
		)
		effect_tween.tween_callback(func():
			effect_star.queue_free()
		)
	
	SoundManager.play_sound("Hurt")
	
	hp -= 1
	
	$EyeLeft.play("eye_closed")
	$EyeRight.play("eye_closed")
	$Tear.visible = true
	var tween = get_tree().create_tween()
	tween.tween_property(self, "modulate", Color(1, 1, 1, 0.2), 0.1)
	tween.tween_property(self, "modulate", Color(1, 1, 1, 0.8), 0.1)
	tween.tween_property(self, "modulate", Color(1, 1, 1, 0.2), 0.1)
	tween.tween_property(self, "modulate", Color(1, 1, 1, 0.8), 0.1)
	
	if hp > 0:
		tween.tween_callback(func():
			modulate = Color(1, 1, 1, 1.0)
			$EyeLeft.play("hole_idle")
			$EyeRight.play("hole_idle")
			$Tear.visible = false
		)
	elif hp <= 0:
		Game.boss_defeated.emit()


func _on_blink_timer_timeout() -> void:
	$EyeLeft.play("blink")
	$EyeRight.play("blink")
	await $EyeRight.animation_finished
	$EyeLeft.play("hole_idle")
	$EyeRight.play("hole_idle")
	
	blow_wind()