Skip to content

Commit

Permalink
chore: add comments on the main script
Browse files Browse the repository at this point in the history
  • Loading branch information
florianvazelle committed Dec 30, 2023
1 parent a5156a6 commit 4e77e48
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions scripts/main.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class_name Main

extends Node

enum State { MODE_START, MODE_PAUSE, MODE_MARBLE }
Expand Down Expand Up @@ -77,7 +76,7 @@ func _unhandled_input(event):
)

else:
print("Could not place start marble")
printerr("No marble to focus on!")

KEY_ESCAPE:
if _mode != State.MODE_START and _mode != State.MODE_PAUSE:
Expand Down Expand Up @@ -114,19 +113,21 @@ func _unhandled_input(event):
break


# Reset marble positions
func reset_position() -> void:
_positions = []
for i in range(7):
for j in range(2):
_positions.append([i, j])


# Try placing a new marble on the start line
func try_place_start_marble() -> Marble:
var piece = get_highest_piece()
if piece == null:
return null
if len(_positions) == 0:
print("There are limited places to ensure equality among the marbles.")
printerr("There are limited places to ensure equality among the marbles.")
return null
randomize()
var position = _positions.pop_at(randi() % len(_positions))
Expand All @@ -150,6 +151,7 @@ func try_place_start_marble() -> Marble:
return new_marble


# Get the highest piece in the race
func get_highest_piece() -> Piece:
var pieces = _race.get_children()
if len(pieces) == 0:
Expand All @@ -161,8 +163,9 @@ func get_highest_piece() -> Piece:
return highest_piece


# Replace cameras with a new one
func replace_camera(new_camera, old_cameras) -> void:
# Ensure old cameras are remove from the current scene
# Ensure old cameras are removed from the current scene
for camera in old_cameras:
if camera.is_inside_tree():
remove_from_tree(camera)
Expand All @@ -171,6 +174,7 @@ func replace_camera(new_camera, old_cameras) -> void:
add_child(new_camera)


# Set the game mode
func set_mode(mode):
var start_a_new_race = false

Expand All @@ -182,19 +186,19 @@ func set_mode(mode):
for marble in _marbles:
marble.pause()

# Ensure timer is reset
# Ensure the timer is reset
_race_has_started = false
_timer.set_wait_time(10)
_timer.stop()

# Ensure that the pause menu is close
# Ensure that the pause menu is closed
if _pause_menu.visible:
_pause_menu.close()

_mode = mode

if _mode == State.MODE_MARBLE:
# If no marbles exists
# If no marbles exist
if start_a_new_race:
await Fade.fade_out(1, Color.BLACK, "Diamond", false, false).finished

Expand Down Expand Up @@ -250,6 +254,7 @@ func set_mode(mode):
replace_camera(_rotation_camera, [_cinematic_camera])


# Remove a node from the scene tree
static func remove_from_tree(node):
node.get_parent().remove_child(node)

Expand Down Expand Up @@ -311,6 +316,7 @@ func _process(delta):
replace_camera(_rotation_camera, [_cinematic_camera])


# Handle victory conditions on explosion mode
func explosion_victory(_last_marble: Marble) -> bool:
var marble_exploded_count := 0
var tmp_marble = null
Expand Down

0 comments on commit 4e77e48

Please sign in to comment.