Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions scenes/main.tscn
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
[gd_scene load_steps=4 format=3 uid="uid://c1ibyecb1dmow"]
[gd_scene load_steps=3 format=3 uid="uid://c1ibyecb1dmow"]

[ext_resource type="PackedScene" uid="uid://cc2n5bb6al7qg" path="res://scenes/game.tscn" id="1_0xm2m"]
[ext_resource type="Script" uid="uid://c8qyieqgdrge2" path="res://scripts/main.gd" id="1_h2yge"]
[ext_resource type="PackedScene" uid="uid://dax0hhxr4xyjj" path="res://ui/menu.tscn" id="2_h2yge"]

[node name="Main" type="Node2D"]
script = ExtResource("1_h2yge")

[node name="GameScene" parent="." instance=ExtResource("1_0xm2m")]

[node name="GameMenu" parent="." instance=ExtResource("2_h2yge")]
anchors_preset = 0
anchor_right = 0.0
Expand Down
10 changes: 9 additions & 1 deletion scripts/gamemanager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ class Score extends Resource:
self.score = score_
self.initials = initials_

@export var high_scores: Array[Score] = []
@export var high_scores: Array[Score] = []

func reset_game() -> void:
# Reset game state - placeholder for actual game logic
pass

func restart_level() -> void:
# Restart current level - placeholder for actual game logic
pass
36 changes: 30 additions & 6 deletions scripts/main.gd
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
extends Node2D

@onready var game_menu := $GameMenu
@onready var game_scene := $GameScene
@onready var music_player := $MusicAudioStreamPlayer

# Dynamic game scene management
var game_scene: Node2D = null
var game_scene_packed: PackedScene = preload("res://scenes/game.tscn")

func _ready() -> void:
GameManager.game_over.connect(_on_game_manager_game_over)

Expand All @@ -13,7 +16,8 @@ func _on_game_manager_game_over(player_won: bool) -> void:
get_tree().paused = true
# Load the game over screen
game_menu.show()
game_scene.hide()
if game_scene:
game_scene.hide()

func _input(event: InputEvent) -> void:
if event.is_action_pressed("ui_cancel"):
Expand All @@ -32,10 +36,14 @@ func is_game_paused() -> bool:


func pause_game() -> void:
game_menu.pause()
# Only pause if there's an active game scene
if game_scene:
game_menu.pause()

func resume_game() -> void:
game_menu.unpause()
# Only unpause if there's an active game scene
if game_scene:
game_menu.unpause()


func _on_game_menu_exit_game() -> void:
Expand All @@ -47,7 +55,11 @@ func _on_game_menu_return_main_menu() -> void:
# Return to the main menu
get_tree().paused = true
game_menu.show()
game_scene.hide()

# Unload the game scene completely
if game_scene:
game_scene.queue_free()
game_scene = null


func _on_game_menu_start_game() -> void:
Expand All @@ -56,7 +68,12 @@ func _on_game_menu_start_game() -> void:
# Hide the game menu
game_menu.hide()

# Start the game scene
# Load and instantiate the game scene
if not game_scene:
game_scene = game_scene_packed.instantiate()
add_child(game_scene)

# Show the game scene
game_scene.show()

# start the music
Expand All @@ -67,5 +84,12 @@ func _on_game_menu_start_game() -> void:

func _on_game_menu_restart_game() -> void:
print("Restarting game")

# Ensure game scene is loaded before restarting
if not game_scene:
game_scene = game_scene_packed.instantiate()
add_child(game_scene)
game_scene.show()

GameManager.restart_level()
resume_game()