-
Notifications
You must be signed in to change notification settings - Fork 0
/
powerup.gd
84 lines (73 loc) · 2.12 KB
/
powerup.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
extends Area2D
var screensize: Vector2 = Vector2.ZERO
func _ready() -> void:
position = Vector2(
randf_range(GLOBAL.BOUNDS.Left, GLOBAL.BOUNDS.Right),
randf_range(GLOBAL.BOUNDS.Top, GLOBAL.BOUNDS.Bottom)
)
func _on_tree_entered() -> void:
var our_rect:Rect2
var player_rect:Rect2
hide()
position = Vector2(
randf_range(GLOBAL.BOUNDS.Left, GLOBAL.BOUNDS.Right),
randf_range(GLOBAL.BOUNDS.Top, GLOBAL.BOUNDS.Bottom)
)
our_rect = Rect2(
position.x,
position.y,
GJ.image_size($AnimatedSprite2D).x,
GJ.image_size($AnimatedSprite2D).y
)
player_rect = Rect2(
$/root/Main/Player.global_position.x,
$/root/Main/Player.global_position.y,
GJ.image_size($/root/Main/Player/SpawnCheck).x,
GJ.image_size($/root/Main/Player/SpawnCheck).y
)
while our_rect.intersects(player_rect):
#printerr("POWERUP INTERSECTS PLAYER")
position = Vector2(
randf_range(GLOBAL.BOUNDS.Left, GLOBAL.BOUNDS.Right),
randf_range(GLOBAL.BOUNDS.Top, GLOBAL.BOUNDS.Bottom)
)
our_rect = Rect2(
position.x,
position.y,
GJ.image_size($AnimatedSprite2D).x,
GJ.image_size($AnimatedSprite2D).y
)
show()
func pickup() -> bool:
# prevents multiple collisions
$CollisionShape2D.set_deferred("disabled", true)
# stop the timer
$Lifetime.stop()
# play the sound
$/root/Main/PowerupSound.play()
# tween setup for scale and alpha
var tw = create_tween()
# tween multiple properties at the same time (parallel)
tw.set_parallel()
# set transition function to quadratic curve
tw.set_trans(Tween.TRANS_QUAD)
# tween scale
tw.tween_property(self, "scale", scale * 10, 0.3)
# tween alpha - modulate:a = alpha
tw.tween_property(self, "modulate:a", 0.0, 0.3)
# wait for tween to be finished
await tw.finished
# removes node and children when ready at end of current frame
queue_free()
# return true since we are awaiting the pickup
return true
func _on_lifetime_timeout() -> void:
queue_free()
func animate_in() -> bool:
$/root/Main/SpawnCoinSound.play()
var tw = create_tween()
tw.set_trans(Tween.TRANS_QUAD)
self.scale = Vector2(0.2, 0.2)
tw.tween_property(self, "scale", Vector2(1.0, 1.0), 0.1)
await tw.finished
return true