diff --git a/main.tscn b/main.tscn index 6c67f5f..c2e9bf0 100644 --- a/main.tscn +++ b/main.tscn @@ -137,7 +137,8 @@ texture_hover = ExtResource("16_d13ii") [node name="CursorManager" parent="." instance=ExtResource("20_82xsv")] -[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] +[node name="BackgroundMusic" type="AudioStreamPlayer" parent="."] +unique_name_in_owner = true stream = ExtResource("22_ryguw") volume_db = -14.0 autoplay = true diff --git a/project.godot b/project.godot index cec1639..c341708 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="ld58" -run/main_scene="uid://q1x5v4q6uxsj" +run/main_scene="uid://bnb1i0y0fls7b" config/features=PackedStringArray("4.5", "Forward Plus") config/icon="res://icon.svg" @@ -19,10 +19,6 @@ config/icon="res://icon.svg" general/text_to_speech=true -[autoload] - -World="*res://world.gd" - [display] window/size/viewport_width=1280 diff --git a/score_screen.tscn b/score_screen.tscn index 339ba4e..0a7ebf9 100644 --- a/score_screen.tscn +++ b/score_screen.tscn @@ -4,7 +4,7 @@ [ext_resource type="Texture2D" uid="uid://cabsfveh1oc6i" path="res://assets/menus/final score/morshu-happy-large.png" id="1_juxjb"] [ext_resource type="Texture2D" uid="uid://d24dlalqmr6r0" path="res://assets/menus/final score/morshu-anger-large.png" id="2_3r2db"] -[node name="Node2D" type="Node2D"] +[node name="ScoreScreen" type="Node2D"] [node name="Control" type="Control" parent="."] layout_mode = 3 diff --git a/world.gd b/world.gd index 7a8b3a5..557fde3 100644 --- a/world.gd +++ b/world.gd @@ -1,35 +1,56 @@ -extends Node3D +extends Control -enum GameState { MAIN_MENU, GAME, LOSS, SUCCESS } +enum GameState { MAIN_MENU, GAME, LOSS, WIN } var current_game_state: GameState = GameState.MAIN_MENU var manager +var main_menu_scene = preload("res://main_menu.tscn") +var game_scene = preload("res://main.tscn") +var score_screen_scene = preload("res://score_screen.tscn") + func _ready(): $MainMenu.main_menu_interacted.connect(_on_main_menu_interacted) -func transition(): - if current_game_state == GameState.MAIN_MENU: - current_game_state = GameState.GAME - %MenuMusic.stop() - %BackGroundMusic.play() - elif current_game_state == GameState.GAME: - current_game_state = GameState.LOSS - manager.queue_free() - %BackGroundMusic.stop() - %TheEndSound.play() - $ScrollingBackgroundEngine.end_it() - elif current_game_state == GameState.LOSS: - current_game_state = GameState.GAME - %MenuMusic.stop() - %BackGroundMusic.play() +func transition(new_state: GameState): + # Clean up current scene + + if new_state == GameState.MAIN_MENU: + var main_menu_instance = main_menu_scene.instantiate() + add_child(main_menu_scene) + elif new_state == GameState.GAME: + var game_instance = game_scene.instantiate() + add_child(game_instance) + elif new_state == GameState.LOSS: + var score_screen_instance = score_screen_scene.instantiate() + add_child(score_screen_instance) + score_screen_instance.win() + elif new_state == GameState.WIN: + pass + + # Clean up old scene + match (current_game_state): + GameState.MAIN_MENU: + var main_menu_instance = $MainMenu + var main_menu_instance.destroy() + GameState.GAME: + var main_instance = $Main + main_instance.destroy() + GameState.LOSS: + var score_screen_instance = $ScoreScreen + score_screen_instance.destroy() + GameState.WIN: + var score_screen_instance = $ScoreScreen + score_screen_instance.destroy() + + current_game_state = new_state func _on_main_menu_interacted(): - transition() + transition(GameState.GAME) add_child(manager) manager.failed.connect(_on_loss) func _on_loss(): - transition() + transition(GameState.LOSS) -func _reload_self(): - get_tree().reload_current_scene() +func _on_win(): + transition(GameState.WIN) diff --git a/world.tscn b/world.tscn new file mode 100644 index 0000000..c5a8a6f --- /dev/null +++ b/world.tscn @@ -0,0 +1,16 @@ +[gd_scene load_steps=3 format=3 uid="uid://bnb1i0y0fls7b"] + +[ext_resource type="PackedScene" uid="uid://q1x5v4q6uxsj" path="res://main_menu.tscn" id="1_f3sb7"] +[ext_resource type="Script" uid="uid://btq5lp33qphwg" path="res://world.gd" id="1_fj7yv"] + +[node name="World" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_fj7yv") + +[node name="MainMenu" parent="." instance=ExtResource("1_f3sb7")] +layout_mode = 1