diff --git a/main_menu.gd b/main_menu.gd new file mode 100644 index 0000000..0da7d60 --- /dev/null +++ b/main_menu.gd @@ -0,0 +1,43 @@ +extends Node + +@onready var menu_text = $Title +@onready var control_ui = $Vignette +@onready var root = self + +signal main_menu_interacted + +var input_received = false + +func _input(event): + if input_received: + return + + if event is InputEventKey or event is InputEventMouseButton: + input_received = true + control_ui.visible = false + replace_with_falling_body(menu_text) + emit_signal("main_menu_interacted") + +func replace_with_falling_body(node: Node2D): + var global_pos = node.global_position + + var body := RigidBody2D.new() + body.gravity_scale = 1 + body.position = global_pos + body.global_position = global_pos + + var shape := CollisionShape2D.new() + var rect_shape := RectangleShape2D.new() + rect_shape.extents = Vector2(20, 20) + shape.shape = rect_shape + body.add_child(shape) + + var parent = node.get_parent() + parent.remove_child(node) + body.add_child(node) + node.position = Vector2.ZERO + root.add_child(body) + + var x_force = randf_range(-300.0, 300.0) + var y_force = randf_range(400.0, -100.0) + body.apply_impulse(Vector2(x_force, y_force)) diff --git a/main_menu.gd.uid b/main_menu.gd.uid new file mode 100644 index 0000000..3d9b480 --- /dev/null +++ b/main_menu.gd.uid @@ -0,0 +1 @@ +uid://bhpge7t5uk4gv diff --git a/main_menu.tscn b/main_menu.tscn index 57a0ec5..85e42a0 100644 --- a/main_menu.tscn +++ b/main_menu.tscn @@ -1,16 +1,19 @@ -[gd_scene load_steps=4 format=3 uid="uid://q1x5v4q6uxsj"] +[gd_scene load_steps=6 format=3 uid="uid://q1x5v4q6uxsj"] [ext_resource type="Texture2D" uid="uid://dsfng5b065eyp" path="res://assets/background/full_bg_example.png" id="1_06t4h"] +[ext_resource type="Script" uid="uid://bhpge7t5uk4gv" path="res://main_menu.gd" id="1_glbon"] [ext_resource type="Theme" uid="uid://d2rlcffg7nguy" path="res://menus.tres" id="2_jix8l"] [ext_resource type="Texture2D" uid="uid://cyheahpjvgaec" path="res://assets/menus/main/main.png" id="3_glbon"] +[ext_resource type="AudioStream" uid="uid://dx1yvtemmpktm" path="res://mainmenu.ogg" id="4_jix8l"] -[node name="Main Menu" type="Control"] +[node name="MainMenu" 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_glbon") [node name="Background" type="Sprite2D" parent="."] position = Vector2(640, 360) @@ -41,17 +44,12 @@ grow_vertical = 2 theme = ExtResource("2_jix8l") text = "Press any key to start" -[node name="Title" type="TextureRect" parent="."] -layout_mode = 1 -anchors_preset = 8 -anchor_left = 0.5 -anchor_top = 0.5 -anchor_right = 0.5 -anchor_bottom = 0.5 -offset_left = -450.0 -offset_top = -145.0 -offset_right = 450.0 -offset_bottom = 145.0 -grow_horizontal = 2 -grow_vertical = 2 +[node name="Title" type="Sprite2D" parent="."] +position = Vector2(635, 400) texture = ExtResource("3_glbon") + +[node name="MenuMusic" type="AudioStreamPlayer" parent="."] +unique_name_in_owner = true +stream = ExtResource("4_jix8l") +volume_db = -14.0 +autoplay = true diff --git a/mainmenu.ogg b/mainmenu.ogg new file mode 100644 index 0000000..45d0c54 Binary files /dev/null and b/mainmenu.ogg differ diff --git a/mainmenu.ogg.import b/mainmenu.ogg.import new file mode 100644 index 0000000..2f1a3f1 --- /dev/null +++ b/mainmenu.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://dx1yvtemmpktm" +path="res://.godot/imported/mainmenu.ogg-aa713911500d6936271f6784f44af7da.oggvorbisstr" + +[deps] + +source_file="res://mainmenu.ogg" +dest_files=["res://.godot/imported/mainmenu.ogg-aa713911500d6936271f6784f44af7da.oggvorbisstr"] + +[params] + +loop=true +loop_offset=0.0 +bpm=0.0 +beat_count=0 +bar_beats=4 diff --git a/project.godot b/project.godot index 61d240b..cec1639 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="ld58" -run/main_scene="uid://dt4nq0nkmjiit" +run/main_scene="uid://q1x5v4q6uxsj" config/features=PackedStringArray("4.5", "Forward Plus") config/icon="res://icon.svg" @@ -19,6 +19,10 @@ config/icon="res://icon.svg" general/text_to_speech=true +[autoload] + +World="*res://world.gd" + [display] window/size/viewport_width=1280 diff --git a/world.gd b/world.gd new file mode 100644 index 0000000..7a8b3a5 --- /dev/null +++ b/world.gd @@ -0,0 +1,35 @@ +extends Node3D + +enum GameState { MAIN_MENU, GAME, LOSS, SUCCESS } +var current_game_state: GameState = GameState.MAIN_MENU +var manager + +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 _on_main_menu_interacted(): + transition() + add_child(manager) + manager.failed.connect(_on_loss) + +func _on_loss(): + transition() + +func _reload_self(): + get_tree().reload_current_scene() diff --git a/world.gd.uid b/world.gd.uid new file mode 100644 index 0000000..2a76f19 --- /dev/null +++ b/world.gd.uid @@ -0,0 +1 @@ +uid://btq5lp33qphwg