Skip to content

Commit e361198

Browse files
committed
Added comments to game.gd
1 parent dc320ae commit e361198

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

scripts/game.gd

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
extends Node2D
22

3+
# Declare onready variables for various game elements
4+
35
@onready var foreground = $Level/Foreground
46

57
@onready var camera = $Camera
@@ -21,17 +23,21 @@ extends Node2D
2123
@onready var plate = $Level/Foreground/Top/FoodChoice/Plate
2224
@onready var mouth = $Level/Foreground/Top/FoodChoice/Mouth
2325

26+
# Constants for positions
27+
2428
const BAR_POS: Vector2 = Vector2(350.0, 285.0) # min 280, intially 250 (but bar top is visible which is meh)
2529
const RESTAURANT_POS: Vector2 = Vector2(350.0, -160.0)
2630

31+
# Game state variables
32+
2733
var game_started = false
2834
var food_names = ["hamburger", "pizza", "sandwich", "hotdog", "fries", "eggs", "chicken", "butter", "cheese", "bread", "rice", "noodles", "salt", "pepper", "fish", "jam", "icewater", "orangejuice", "soda", "coffee"]
2935
var served = []
3036
var head_anim = ""
3137
var game_count = 0
3238
var is_fullscreen: bool = false
3339

34-
func set_globals_to_default():
40+
func set_default_global_values():
3541
Global.is_hovering = false
3642
Global.score = 0
3743
Global.is_bar = true
@@ -44,7 +50,7 @@ func set_globals_to_default():
4450
Global.random_food_list = []
4551

4652
func _ready():
47-
set_globals_to_default()
53+
set_default_global_values()
4854
AudioManager.connect("talk_finished", outro)
4955
walker.hide()
5056
score_label.text = str(Global.score)
@@ -56,12 +62,15 @@ func make_random_list() -> Array:
5662

5763
return shuffled_list
5864

65+
# Function to update the cursor based on user interaction
5966
func update_cursor():
6067
if !Global.is_hovering:
6168
Input.set_default_cursor_shape(Input.CURSOR_ARROW)
6269
else:
6370
Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND)
6471

72+
# Function to switch the view between bar and restaurant
73+
# Only used once tho, might rename it or simplify, maybe even remove :O
6574
func change_view():
6675
if Global.is_bar:
6776
Global.is_bar = false
@@ -97,6 +106,7 @@ func _process(_delta):
97106
elif user_pick != Global.ordered:
98107
handle_incorrect_food(user_pick)
99108

109+
# Event handler for walker's animation player
100110
func _on_animation_player_animation_finished(anim_name):
101111
match anim_name:
102112
"intro":
@@ -124,6 +134,7 @@ func add_score() -> void:
124134
score_label.text = str(Global.score)
125135
pumpkin_head.scale += Vector2(0.0075, 0.0075)
126136

137+
# Function to serve a single food item
127138
func serve_one(food, slot) -> void:
128139
var food_scene = ResourceLoader.load("res://scenes/food/" + food + ".tscn")
129140
var food_instance = food_scene.instantiate()
@@ -140,6 +151,7 @@ func serve_one(food, slot) -> void:
140151

141152
served.append(food)
142153

154+
# Function to serve a set of food items
143155
func serve() -> void:
144156
var i = 1
145157
while i <= 4:
@@ -149,19 +161,22 @@ func serve() -> void:
149161
Global.can_pick = false
150162
after_serve()
151163

164+
# Function called after serving food
152165
func after_serve() -> void:
153166
Global.ordered = served.pick_random()
154167
AudioManager.play_giveme_sound(Global.ordered)
155168
pumpkin_head.play("order")
156169
head_anim = "order"
157170
Global.game_state = "choice"
158171

172+
# Function called when Mr. Pumpkin says "No. >:O"
159173
func try_again() -> void:
160174
AudioManager.play_giveme_sound(Global.ordered)
161175
pumpkin_head.play("order")
162176
head_anim = "order"
163177
Global.game_state = "choice"
164178

179+
# Function to handle correct food selection by the player
165180
func handle_correct_food(user_pick):
166181
Global.can_pick = false
167182
Global.ordered = ""
@@ -173,6 +188,8 @@ func handle_correct_food(user_pick):
173188
food = "IceWater"
174189

175190
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
176193
if food == null:
177194
return
178195

@@ -186,6 +203,7 @@ func handle_correct_food(user_pick):
186203
food.move_to_mouth()
187204
served.erase(user_pick)
188205

206+
# Function to handle incorrect food selection by the player
189207
func handle_incorrect_food(user_pick):
190208
Global.can_pick = false
191209
var food = user_pick.capitalize()
@@ -196,6 +214,7 @@ func handle_incorrect_food(user_pick):
196214
food = "IceWater"
197215

198216
food = foreground.get_node_or_null(food)
217+
# Same here as in previous 'handle_correct_food' function
199218
if food == null:
200219
return
201220

@@ -210,6 +229,7 @@ func handle_incorrect_food(user_pick):
210229
food.move_to_trash()
211230
served.erase(user_pick)
212231

232+
# Function to handle the ending of the game
213233
func ending():
214234
Global.game_state = "end"
215235
Global.is_no = true
@@ -223,11 +243,15 @@ func ending():
223243
else:
224244
AudioManager.play_pumpkin_sound("fantastic")
225245

246+
# Function to handle the outro animation, called after Mr. Pumpkin
247+
# Finishes talking in the end
226248
func outro():
227249
pumpkin.hide()
228250
walker_anim.play("end")
229251
Global.can_pick = false
230252

253+
# Event handler for head animation, it's funny to me that
254+
# Almost the most important logic is in this function
231255
func _on_head_animation_finished():
232256
if head_anim == "eat":
233257
head_anim = ""

0 commit comments

Comments
 (0)