-
Notifications
You must be signed in to change notification settings - Fork 0
/
IncomingMissileWarning.gd
65 lines (52 loc) · 1.8 KB
/
IncomingMissileWarning.gd
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
extends Node2D
@onready var icon = $Icon
@onready var typed_label = $TypedLabel
var tween
var weapons = []
var language
signal on_dismiss
func _ready() -> void:
_configure_typed_label_side()
var initial_scale = icon.scale
var bounce_scale = initial_scale + Vector2.ONE * 0.2
icon.scale = Vector2.ZERO
tween = create_tween()
tween.tween_property(icon, "scale", initial_scale, 0.3) \
.set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_IN_OUT)
await tween.finished
tween = create_tween()
tween.tween_property(icon, "scale", bounce_scale, 0.7) \
.set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_IN)
tween.tween_property(icon, "scale", initial_scale, 0.7) \
.set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_OUT)
tween.set_loops(999)
func _configure_typed_label_side():
$TypedLabel.position = Vector2(40 * sign(global_position.x), 0)
if global_position.x > 0:
typed_label.set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT)
else:
typed_label.set_horizontal_alignment(HORIZONTAL_ALIGNMENT_LEFT)
func init(language: Language, color: Color, text: String, weapon: Node2D, parent: Node2D) -> void:
typed_label.set_text(text)
typed_label.set_language(language)
self.language = language
icon.modulate = color
add_weapon(weapon)
typed_label.correctly_typed.connect(parent._on_correctly_typed)
typed_label.set_color(color)
func add_weapon(weapon):
self.weapons.append(weapon)
weapon.destroyed.connect(_on_weapon_destroyed)
func dismiss_warning():
if tween.is_running:
tween.kill()
tween = create_tween()
tween.tween_property(icon, "scale", Vector2.ZERO, 0.5) \
.set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_OUT)
await tween.finished
on_dismiss.emit(self)
self.queue_free()
func _on_weapon_destroyed(_weapon_ref):
self.weapons.erase(_weapon_ref)
if self.weapons.is_empty():
dismiss_warning()