summaryrefslogtreecommitdiff
path: root/whispy_woods.gd
blob: b5f4058ece8f9dce8ff05b7a84623d64ca0d69af (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
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 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 tween := get_tree().create_tween()
		tween.tween_property(
			effect_star,
			"global_position",
			effect_star.global_position + direction * 16,
			0.1
		)
		tween.tween_callback(func():
			effect_star.queue_free()
		)
	
	SoundManager.play_sound("Hurt")
	
	hp -= 1
	
	$EyeRight.play("eye_closed")
	$Mouth.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)
			$EyeRight.play("eye_open")
			$Mouth.play("mouth_idle")
			$Tear.visible = false
		)
	elif hp <= 0:
		Game.boss_defeated.emit()