-
Notifications
You must be signed in to change notification settings - Fork 0
/
cactus.gd
58 lines (51 loc) · 1.52 KB
/
cactus.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
extends Area2D
var screensize: Vector2 = Vector2.ZERO
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($Sprite2D).x,
GJ.image_size($Sprite2D).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("CACTUS 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($Sprite2D).x,
GJ.image_size($Sprite2D).y
)
show()
func animate_in() -> bool:
await get_viewport().get_tree().create_timer(0.03).timeout
$/root/Main/SpawnCactusSound.play()
var tw = create_tween()
tw.set_trans(Tween.TRANS_BOUNCE)
self.scale = Vector2(1.0, 0.2)
tw.tween_property(self, "scale", Vector2(1.0, 1.0), 0.2)
await tw.finished
return true
func _on_area_entered(area: Area2D) -> void:
if area.is_in_group("coin") || area.is_in_group("powerup"):
#print_debug(str(area.name).to_upper() + " COLLIDES WITH CACTUS")
area.position = Vector2(
randf_range(GLOBAL.BOUNDS.Left, GLOBAL.BOUNDS.Right),
randf_range(GLOBAL.BOUNDS.Top, GLOBAL.BOUNDS.Bottom)
)