-
Notifications
You must be signed in to change notification settings - Fork 0
/
Aircraft.gd
54 lines (43 loc) · 1.12 KB
/
Aircraft.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
extends Area2D
export (PackedScene) var Box
var speed = 400
var obstacles = 0
var dropAllowed = false
var dropped = false
func _ready():
$DropTimer.start(0.9 + (0.2 - randf()*0.4))
func _physics_process(delta):
position += -transform.y * speed * delta
if not dropped and dropAllowed and obstacles == 0:
drop()
func _on_VisibilityNotifier2D_screen_exited():
queue_free()
func drop():
var box = Box.instance()
box.global_position = global_position
box.apply_central_impulse(-transform.y * 500)
box.rotation = rotation + rand_range(-PI / 2, PI / 2)
var rnd = randf()
if rnd > 0.8:
box.setContent(4) # health
elif rnd > 0.7:
box.setContent(3) # spring
elif rnd > 0.5:
box.setContent(2) # big
elif rnd > 0.2:
box.setContent(1) # small
else:
box.setContent(0) # shell
box.z_index = z_index - 1
box.collision_layer = 128
box.collision_mask = 128
box.set_angular_velocity(5)
get_parent().add_child(box)
box.setScale(Vector2(1.5, 1.5))
dropped = true
func _on_DropTimer_timeout():
dropAllowed = true
func _on_Aircraft_body_entered(body):
obstacles += 1
func _on_Aircraft_body_exited(body):
obstacles -= 1