-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.gd
184 lines (133 loc) · 3.98 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
extends Node
export (PackedScene) var Mob
var score
var sheep_score = 0
var show_next_goal = false
var mob_randomness = false
var bug = true # to toggle bug game configuration
# starting point for game
func _ready():
randomize()
# new_game()
pass
func new_game():
score = 0 # reset score
$StartTimer.start() # start the starttimer
$HUD.update_score(score)
$HUD.show_message("Ready...")
$Music.play() # start music
if(bug == true):
$StepGrassSound.play() # start grass sound effect
pass
# called when player is hit with Mob - game ends
func game_over():
#stop these timers
$ScoreTimer.stop()
$MobTimer.stop()
# call gameover from HUD
$HUD.show_game_over()
# clear all objects belonging to the "mobs" group
# does so by calling the queue_free function on every mode in the group
get_tree().call_group("mobs", "queue_free")
$Music.stop()
if(bug == true):
$StepGrassSound.stop()
pass
$GameoverSound.play()
$SheepHitSound.play()
pass
# called when Player lands on Moon
func next_stage():
$ScoreTimer.stop()
$MobTimer.stop()
# clear all objects belonging to the "mobs" group
# does so by calling the queue_free function on every mode in the group
get_tree().call_group("mobs", "queue_free")
### SET DIFFICULTY - scale player, increase mob spawn ###
print("Main: sheep score = %s" % sheep_score)
mob_randomness = !mob_randomness
if(sheep_score < 1):
$Player.scale = Vector2(1, 1)
elif(sheep_score < 4):
$Player.scale = Vector2(1.2, 1.2)
$MobTimer.wait_time = 0.3
elif(sheep_score < 7):
$Player.scale = Vector2(1.3, 1.3)
$MobTimer.wait_time = 0.4
elif(sheep_score < 10):
$Player.scale = Vector2(1.4, 1.4)
$MobTimer.wait_time = 0.3
elif(sheep_score < 13):
$Player.scale = Vector2(1.5, 1.5)
$MobTimer.wait_time = 0.3
elif(sheep_score < 16):
$Player.scale = Vector2(1.6, 1.6)
$MobTimer.wait_time = 0.3
elif(sheep_score < 19):
$Player.scale = Vector2(2.3, 2.3)
$MobTimer.wait_time = 0.3
elif(sheep_score < 25):
$Player.scale = Vector2(2.5, 2.5)
$MobTimer.wait_time = 0.2
else:
$Player.scale = Vector2(3.0, 3.0)
$MobTimer.wait_time = 0.1
pass
# when sheep arrives
# update the sheep score in HUD
sheep_score += 1
$HUD.update_sheep_score(sheep_score)
# play sheep sound
$SheepWinSound.play()
# decide when we should show next goal to player
if ((sheep_score == 1 ) or (sheep_score % 5 == 0)):
show_next_goal = true
else:
show_next_goal = false
if (show_next_goal == true):
$Music.stop()
if(bug == true):
$StepGrassSound.stop()
pass
$WinSound.play()
# call next stage from HUD and show start button
$HUD.show_next_stage(sheep_score)
else:
# manually call to start next stage
_on_StartTimer_timeout()
# this timer is used to set a delay before game starts
func _on_StartTimer_timeout():
$MobTimer.start()
$ScoreTimer.start()
$PlayerStartTimer.start()
pass
# use to delay before player can begin
func _on_PlayerStartTimer_timeout():
# enable the player and set position
$Player.start($StartPosition.position)
pass
# increment score by 1 on timeout
func _on_ScoreTimer_timeout():
score += 1
# update the score showing on the HUB
$HUD.update_score(score)
pass
func _on_MobTimer_timeout():
# Chose a random location on Path2D
$MobPath/MobSpawnLocation.offset = randi()
# create a mob instance and add to scene
var mob = Mob.instance()
add_child(mob)
# set mob direction perpendicular to path direction
# Why PI? In functions requiring angles, GDScript uses radians, not degrees.
var direction = $MobPath/MobSpawnLocation.rotation + PI / 2
# Set the mobs position to a random location
mob.position = $MobPath/MobSpawnLocation.position
# Add some randomness to the direction
#if(mob_randomness == true):
#direction += rand_range(-PI / 4, PI / 4)
#mob.rotation = direction
#set the velocitiy (speed & direction)
mob.linear_velocity = Vector2(rand_range(mob.min_speed, mob.max_speed), 0)
mob.linear_velocity = mob.linear_velocity.rotated(direction)
pass