-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathField.gd
124 lines (99 loc) · 2.55 KB
/
Field.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
extends Area2D
export (PackedScene) var Aircraft
signal tank_removed(tank)
signal game_over
var candidates
var state = [0,0,0]
func _ready():
candidates = [ $Tank1, $Tank2, $Tank3 ]
$Tank1.setOthers([$Tank2, $Tank3])
$Tank2.setOthers([$Tank1, $Tank3])
$Tank3.setOthers([$Tank2, $Tank1])
var winner = null
func update():
if len(candidates) < 2:
if len(candidates) == 1 and not candidates[0].robot:
winner = candidates[0]
$Airfcrafts.stop()
emit_signal("game_over")
else:
var zeroes=0
var maybeWinner = null
var humans=0
for c in candidates:
if c == null or c.robot:
continue
if c.points <= 0:
zeroes += 1
else:
maybeWinner = c
humans += 1
if zeroes > humans-1:
winner = maybeWinner
$Airfcrafts.stop()
emit_signal("game_over")
func _on_Tank1_dead():
candidates.erase($Tank1)
state[0] = $Tank1.type
emit_signal("tank_removed", 1)
update()
func _on_Tank1_zero():
update()
func _on_Tank2_dead():
candidates.erase($Tank2)
state[1] = $Tank2.type
emit_signal("tank_removed", 2)
update()
func _on_Tank2_zero():
update()
func _on_Tank3_dead():
candidates.erase($Tank3)
state[2] = $Tank3.type
emit_signal("tank_removed", 3)
update()
func _on_Tank3_zero():
update()
func spawnAircraft():
var spawn_location
if randf() > 0.5:
spawn_location = $Airfcrafts/UpperAircraftSpawner/PathFollow2D
else:
spawn_location = $Airfcrafts/LowerAircraftSpawner/PathFollow2D
spawn_location.offset = randi()
var aircraft = Aircraft.instance()
add_child(aircraft)
# Set the direction perpendicular to the path direction.
var direction = spawn_location.rotation + PI
# Set the position to a random location.
aircraft.position = spawn_location.position
# Add some randomness to the direction.
direction += rand_range(-PI / 8, PI / 8)
aircraft.rotation = direction
func _on_Airfcrafts_timeout():
spawnAircraft()
func _on_PathCalculation_paths_updated(paths):
if $Tank1 != null:
$Tank1.updatePaths(paths)
if $Tank2 != null:
$Tank2.updatePaths(paths)
if $Tank3 != null:
$Tank3.updatePaths(paths)
func getState():
return [
$Tank1.type if $Tank1 != null else state[0],
$Tank2.type if $Tank2 != null else state[1],
$Tank3.type if $Tank3 != null else state[2]
]
func setState(state):
$Tank1.setType(state[0])
$Tank2.setType(state[1])
$Tank3.setType(state[2])
func _on_Tank1_robot():
state[0] = $Tank1.type
emit_signal("tank_removed", 1)
func _on_Tank2_robot():
state[1] = $Tank2.type
emit_signal("tank_removed", 2)
func _on_Tank3_robot():
state[2] = $Tank3.type
emit_signal("tank_removed", 3)