-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBox.gd
85 lines (73 loc) · 1.88 KB
/
Box.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
85
extends RigidBody2D
export (PackedScene) var Shell
enum Content { SHELL=0, SMALL_SHELLS=1, BIG_SHELL=2, SPRING=3, HEALTH=4 }
var content = null
var targetScale = Vector2(1, 1)
var scaleDelta = Vector2(0.4, 0.4)
var blinks = 5
var shells = 0
var life = 8
func _ready():
content = $Sprite/Content.frame
func setScale(scale):
self.scale = scale
scaleDelta = scale - targetScale
func _physics_process(delta):
if scale.length() > 1:
var ratio = $FallTimer.time_left / $FallTimer.wait_time
scale = targetScale + ratio * scaleDelta
func setContent(content):
$Sprite/Content.frame = content
self.content = content
if content == Content.SHELL:
shells = 15
elif content == Content.HEALTH:
$Sprite/Content.rotation = 0
life = 30
func hit(damage, source):
life -= damage
if life < 0:
if content != Content.SPRING and content != Content.HEALTH:
fire(source)
queue_free()
func fire(source, angle=0):
var s = Shell.instance()
if content == Content.BIG_SHELL:
s.setBig()
elif content == Content.SMALL_SHELLS:
s.setSmall()
if angle == 0:
fire(source, randf() * PI + PI / 3)
fire(source, -randf() * PI + PI / 3)
s.transform = transform
s.rotate(angle)
get_parent().add_child(s)
s.setSource(source)
func _on_PickArea_body_entered(body):
if body.is_in_group("tank") and body.life > 0:
collision_layer = 256
collision_mask = 256
$PickTimer.start()
z_index = 0
if content == Content.SPRING:
body.addSpring()
if content == Content.SHELL:
body.addPoints(shells)
if content == Content.BIG_SHELL:
body.addBigShell()
if content == Content.SMALL_SHELLS:
body.addSmallShells()
if content == Content.HEALTH:
body.addLife(0.6)
func _on_FallTimer_timeout():
z_index = 1
collision_layer = 1
set_angular_velocity(0)
func _on_PickTimer_timeout():
if blinks % 2:
modulate.a = 0
else:
modulate.a = 1
blinks -= 1
if blinks == 0:
queue_free()