-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.gd
149 lines (127 loc) · 4.19 KB
/
Main.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
extends Node
var score
export (PackedScene) var Enemy
export (PackedScene) var Coin
export (PackedScene) var Boss
var bcount = 0
# Called when the node enters the scene tree for the first time.
func _ready():
randomize()
$Player.hide()
func _process(_delta):
if Input.is_action_just_pressed("ui_cancel"):
get_tree().quit()
func game_over():
print("Dead")
get_tree().call_group("enemies", "queue_free")
get_tree().call_group("coins", "queue_free")
get_tree().call_group("boss", "queue_free")
$Player.playing = false
$Player.hide()
$Menu.show_game_over()
$EnemySpawnTimer.stop()
$CoinsSpawnTimer.stop()
$BossSpawnTimer.stop()
func new_game():
score = 0
$Player.bulletcount = 5
$Player.start($PlayerPosition.position)
$StartDelay.start()
$Menu.update_score(score)
$Menu.update_bulletcount($Player.bulletcount)
$Menu.show_message("Get ready")
$Player.playing = true
$Player.show()
$Player/Sprite.show()
func _on_EnemySpawnTimer_timeout():
print("Spawn enemy")
# Choose a random location on Path2D. --> 2142 and 170
$EnemyPath/EnemySpawnLocation.offset = rand_range(1, 760)
# Create a Mob instance and add it to the scene.
var mob = Enemy.instance()
add_child(mob)
mob.set_owner(self)
# Set the mob's direction perpendicular to the path direction.
var direction = $EnemyPath/EnemySpawnLocation.rotation + PI / 2
# Set the mob's position to a random location.
mob.position = $EnemyPath/EnemySpawnLocation.position
# Add some randomness to the direction.
direction *= 100
mob.rotation = direction
connect_to_enemy(mob)
func connect_to_enemy(enemy_node):
enemy_node.connect("enemy_hit",self,"_on_Player_point")
enemy_node.connect("enemy_escaped", self, "_on_Enemy_escaped")
func _on_CoinsSpawnTimer_timeout():
print("Coin spawned")
# Choose a random location on Path2D. --> 2142 and 170
$CoinsPath/CoinsSpawnLocation.offset = rand_range(1, 760)
# Create a Mob instance and add it to the scene.
var coin = Coin.instance()
add_child(coin)
bcount = coin.value
# Set the mob's direction perpendicular to the path direction.
var direction = $CoinsPath/CoinsSpawnLocation.rotation + PI / 2
# Set the mob's position to a random location.
coin.position = $CoinsPath/CoinsSpawnLocation.position
# Add some randomness to the direction.
direction *= 100
coin.rotation = direction
connect_to_coin(coin)
func connect_to_coin(coin_node):
coin_node.connect("coin_hit", self, "_on_Player_coin_collected")
func _on_BossSpawnTimer_timeout():
print("Boss spawn")
$EnemySpawnTimer.stop()
# Choose a random location on Path2D. --> 2142 and 170
$EnemyPath/EnemySpawnLocation.offset = rand_range(1, 760)
# Create a Mob instance and add it to the scene.
var boss = Boss.instance()
add_child(boss)
boss.set_owner(self)
# Set the mob's direction perpendicular to the path direction.
var direction = $EnemyPath/EnemySpawnLocation.rotation + PI / 2
# Set the mob's position to a random location.
boss.position = $EnemyPath/EnemySpawnLocation.position
# Add some randomness to the direction.
direction *= 100
boss.rotation = direction
connect_to_boss(boss)
func connect_to_boss(boss_node):
boss_node.connect("boss_escaped", self, "game_over")
boss_node.connect("boss_died", self, "_on_Boss_died")
func _on_StartDelay_timeout():
$EnemySpawnTimer.start()
$CoinsSpawnTimer.start()
$BossSpawnTimer.start()
func _on_Player_coin_collected():
if $Player.is_visible_in_tree():
print("Coin hit")
$Player.bulletcount += bcount
$Menu.update_bulletcount($Player.bulletcount)
func _on_Player_point():
if $Player.is_visible_in_tree():
print("Plane hitted")
score += 1
$Player.bulletcount += 1
$Menu.update_score(score)
$Menu.update_bulletcount($Player.bulletcount)
func _on_Boss_died():
if $Player.is_visible_in_tree():
print("Boss died")
score += 5
$Player.bulletcount += 10
$Menu.update_score(score)
$Menu.update_bulletcount($Player.bulletcount)
$EnemySpawnTimer.start()
func _on_Enemy_escaped():
if $Player.is_visible_in_tree():
print("Enemy escaped")
if ($Player.bulletcount - 1 == 0):
$Player.bulletcount = 0
else:
$Player.bulletcount -= 1
$Menu.update_bulletcount($Player.bulletcount)
func _on_Player_shooting():
$Player.bulletcount -= 1
$Menu.update_bulletcount($Player.bulletcount)