1
1
extends Node2D
2
2
3
+ # Declare onready variables for various game elements
4
+
3
5
@onready var foreground = $Level/ Foreground
4
6
5
7
@onready var camera = $Camera
@@ -21,17 +23,21 @@ extends Node2D
21
23
@onready var plate = $Level/ Foreground/ Top/ FoodChoice/ Plate
22
24
@onready var mouth = $Level/ Foreground/ Top/ FoodChoice/ Mouth
23
25
26
+ # Constants for positions
27
+
24
28
const BAR_POS: Vector2 = Vector2(350.0 , 285.0 ) # min 280, intially 250 (but bar top is visible which is meh)
25
29
const RESTAURANT_POS: Vector2 = Vector2(350.0 , - 160.0 )
26
30
31
+ # Game state variables
32
+
27
33
var game_started = false
28
34
var food_names = [ " hamburger" , " pizza" , " sandwich" , " hotdog" , " fries" , " eggs" , " chicken" , " butter" , " cheese" , " bread" , " rice" , " noodles" , " salt" , " pepper" , " fish" , " jam" , " icewater" , " orangejuice" , " soda" , " coffee" ]
29
35
var served = []
30
36
var head_anim = " "
31
37
var game_count = 0
32
38
var is_fullscreen: bool = false
33
39
34
- func set_globals_to_default ():
40
+ func set_default_global_values ():
35
41
Global.is_hovering = false
36
42
Global.score = 0
37
43
Global.is_bar = true
@@ -44,7 +50,7 @@ func set_globals_to_default():
44
50
Global.random_food_list = []
45
51
46
52
func _ready():
47
- set_globals_to_default ()
53
+ set_default_global_values ()
48
54
AudioManager.connect(" talk_finished" , outro)
49
55
walker.hide()
50
56
score_label.text = str(Global.score)
@@ -56,12 +62,15 @@ func make_random_list() -> Array:
56
62
57
63
return shuffled_list
58
64
65
+ # Function to update the cursor based on user interaction
59
66
func update_cursor():
60
67
if !Global.is_hovering:
61
68
Input.set_default_cursor_shape(Input.CURSOR_ARROW)
62
69
else :
63
70
Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND)
64
71
72
+ # Function to switch the view between bar and restaurant
73
+ # Only used once tho, might rename it or simplify, maybe even remove :O
65
74
func change_view():
66
75
if Global.is_bar:
67
76
Global.is_bar = false
@@ -97,6 +106,7 @@ func _process(_delta):
97
106
elif user_pick != Global.ordered:
98
107
handle_incorrect_food(user_pick)
99
108
109
+ # Event handler for walker's animation player
100
110
func _on_animation_player_animation_finished(anim_name):
101
111
match anim_name:
102
112
" intro" :
@@ -124,6 +134,7 @@ func add_score() -> void:
124
134
score_label.text = str(Global.score)
125
135
pumpkin_head.scale += Vector2(0.0075 , 0.0075 )
126
136
137
+ # Function to serve a single food item
127
138
func serve_one(food, slot) -> void:
128
139
var food_scene = ResourceLoader.load(" res://scenes/food/" + food + " .tscn" )
129
140
var food_instance = food_scene.instantiate()
@@ -140,6 +151,7 @@ func serve_one(food, slot) -> void:
140
151
141
152
served.append(food)
142
153
154
+ # Function to serve a set of food items
143
155
func serve() -> void:
144
156
var i = 1
145
157
while i <= 4 :
@@ -149,19 +161,22 @@ func serve() -> void:
149
161
Global.can_pick = false
150
162
after_serve()
151
163
164
+ # Function called after serving food
152
165
func after_serve() -> void:
153
166
Global.ordered = served.pick_random()
154
167
AudioManager.play_giveme_sound(Global.ordered)
155
168
pumpkin_head.play(" order" )
156
169
head_anim = " order"
157
170
Global.game_state = " choice"
158
171
172
+ # Function called when Mr. Pumpkin says "No. >:O"
159
173
func try_again() -> void:
160
174
AudioManager.play_giveme_sound(Global.ordered)
161
175
pumpkin_head.play(" order" )
162
176
head_anim = " order"
163
177
Global.game_state = " choice"
164
178
179
+ # Function to handle correct food selection by the player
165
180
func handle_correct_food(user_pick):
166
181
Global.can_pick = false
167
182
Global.ordered = " "
@@ -173,6 +188,8 @@ func handle_correct_food(user_pick):
173
188
food = " IceWater"
174
189
175
190
food = foreground.get_node_or_null(food)
191
+ # For some reason this function is sometimes being called multiple times
192
+ # Causing game breaking bugs, so I had to make a check
176
193
if food == null:
177
194
return
178
195
@@ -186,6 +203,7 @@ func handle_correct_food(user_pick):
186
203
food.move_to_mouth()
187
204
served.erase(user_pick)
188
205
206
+ # Function to handle incorrect food selection by the player
189
207
func handle_incorrect_food(user_pick):
190
208
Global.can_pick = false
191
209
var food = user_pick.capitalize()
@@ -196,6 +214,7 @@ func handle_incorrect_food(user_pick):
196
214
food = " IceWater"
197
215
198
216
food = foreground.get_node_or_null(food)
217
+ # Same here as in previous 'handle_correct_food' function
199
218
if food == null:
200
219
return
201
220
@@ -210,6 +229,7 @@ func handle_incorrect_food(user_pick):
210
229
food.move_to_trash()
211
230
served.erase(user_pick)
212
231
232
+ # Function to handle the ending of the game
213
233
func ending():
214
234
Global.game_state = " end"
215
235
Global.is_no = true
@@ -223,11 +243,15 @@ func ending():
223
243
else :
224
244
AudioManager.play_pumpkin_sound(" fantastic" )
225
245
246
+ # Function to handle the outro animation, called after Mr. Pumpkin
247
+ # Finishes talking in the end
226
248
func outro():
227
249
pumpkin.hide()
228
250
walker_anim.play(" end" )
229
251
Global.can_pick = false
230
252
253
+ # Event handler for head animation, it's funny to me that
254
+ # Almost the most important logic is in this function
231
255
func _on_head_animation_finished():
232
256
if head_anim == " eat" :
233
257
head_anim = " "
0 commit comments