From 04d50df23eb1e3062feb4eea08d8781c5c147e9f Mon Sep 17 00:00:00 2001 From: ToasterPanic Date: Sat, 6 Dec 2025 22:06:34 -0500 Subject: [PATCH] Saving & loading, --- scenes/game.tscn | 45 ++++++++++++- scenes/ground.tscn | 46 +++++++++++++- scenes/title.tscn | 65 ++++++++++++++++++- scripts/galactamart_worker.gd | 2 + scripts/game.gd | 23 +++++++ scripts/game_ground.gd | 20 ++++++ scripts/global.gd | 7 +-- scripts/story_handler_1.gd | 2 + scripts/title.gd | 97 ++++++++++++++++++++++++++++- textures/save_indicator.ase | Bin 0 -> 523 bytes textures/save_indicator.png | Bin 0 -> 224 bytes textures/save_indicator.png.import | 40 ++++++++++++ 12 files changed, 336 insertions(+), 11 deletions(-) create mode 100644 textures/save_indicator.ase create mode 100644 textures/save_indicator.png create mode 100644 textures/save_indicator.png.import diff --git a/scenes/game.tscn b/scenes/game.tscn index 9782439..3e76bd2 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=41 format=4 uid="uid://bauklhpieuivd"] +[gd_scene load_steps=45 format=4 uid="uid://bauklhpieuivd"] [ext_resource type="Script" uid="uid://d0qswyhwbhdua" path="res://scripts/game.gd" id="1_u5sy4"] [ext_resource type="Texture2D" uid="uid://dtwo7g0ipc4k" path="res://textures/ship_1.png" id="1_uwrxv"] @@ -22,6 +22,7 @@ [ext_resource type="Script" uid="uid://dqiaioigmj5wb" path="res://scripts/pause_menu.gd" id="15_rysoc"] [ext_resource type="FontFile" uid="uid://donsvh2l775rb" path="res://fonts/Doto.ttf" id="16_1kice"] [ext_resource type="PackedScene" uid="uid://cy4nbqbm222os" path="res://scenes/settings.tscn" id="17_ssvqc"] +[ext_resource type="Texture2D" uid="uid://cwa4uu7hrw2l0" path="res://textures/save_indicator.png" id="22_bt5mj"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_ir15t"] texture = ExtResource("12_trtic") @@ -86,6 +87,28 @@ corner_detail = 1 font_size = 48 outline_size = 2 +[sub_resource type="AtlasTexture" id="AtlasTexture_vuhkc"] +atlas = ExtResource("22_bt5mj") +region = Rect2(0, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_26mqe"] +atlas = ExtResource("22_bt5mj") +region = Rect2(16, 0, 16, 16) + +[sub_resource type="SpriteFrames" id="SpriteFrames_e1j6l"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_vuhkc") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_26mqe") +}], +"loop": true, +"name": &"default", +"speed": 2.0 +}] + [sub_resource type="ShaderMaterial" id="ShaderMaterial_trtic"] shader = ExtResource("12_kvuet") shader_parameter/shake = 0.002000000095 @@ -704,6 +727,26 @@ script = ExtResource("15_ca42v") action_name = "navpanel" metadata/_custom_type_script = "uid://b2maxk5g6yb0i" +[node name="SaveIndicator" type="Control" parent="UI/Control"] +visible = false +custom_minimum_size = Vector2(64, 64) +layout_mode = 1 +anchors_preset = 3 +anchor_left = 1.0 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = -64.0 +offset_top = -64.0 +grow_horizontal = 0 +grow_vertical = 0 + +[node name="SaveIcon" type="AnimatedSprite2D" parent="UI/Control/SaveIndicator"] +position = Vector2(32, 32) +scale = Vector2(4, 4) +sprite_frames = SubResource("SpriteFrames_e1j6l") +autoplay = "default" + [node name="FadeToBlack" type="ColorRect" parent="UI"] process_mode = 3 modulate = Color(1, 1, 1, 0) diff --git a/scenes/ground.tscn b/scenes/ground.tscn index c3f4d0f..b07a955 100644 --- a/scenes/ground.tscn +++ b/scenes/ground.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=27 format=3 uid="uid://by43ihcec8e8q"] +[gd_scene load_steps=31 format=3 uid="uid://by43ihcec8e8q"] [ext_resource type="Script" uid="uid://b2sw6ymaf4t0s" path="res://scripts/game_ground.gd" id="1_6ra5r"] [ext_resource type="Script" uid="uid://dowu512otgyyf" path="res://scripts/player_ground.gd" id="3_8gbjj"] @@ -10,6 +10,7 @@ [ext_resource type="Shader" uid="uid://d3hoh7ec2w8q7" path="res://scripts/outline.gdshader" id="7_vuhkc"] [ext_resource type="Shader" uid="uid://d2e0541hawkml" path="res://scripts/vignette.gdshader" id="9_5vwr8"] [ext_resource type="Shader" uid="uid://bk7q00br1ms30" path="res://scripts/retro.gdshader" id="9_257nh"] +[ext_resource type="Texture2D" uid="uid://cwa4uu7hrw2l0" path="res://textures/save_indicator.png" id="13_176r3"] [ext_resource type="Texture2D" uid="uid://dauoebs801ngm" path="res://addons/super_awesome_input_icons/textures/keyboard/question.png" id="16_e3s4u"] [ext_resource type="Script" uid="uid://b2maxk5g6yb0i" path="res://addons/super_awesome_input_icons/classes/input_icon_texture_rect.gd" id="16_hby33"] [ext_resource type="PackedScene" uid="uid://dhcfrsf726k68" path="res://scenes/dialogue_select_button.tscn" id="19_qqas2"] @@ -108,6 +109,28 @@ font_size = 48 outline_size = 4 outline_color = Color(0, 0, 0, 1) +[sub_resource type="AtlasTexture" id="AtlasTexture_vuhkc"] +atlas = ExtResource("13_176r3") +region = Rect2(0, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_26mqe"] +atlas = ExtResource("13_176r3") +region = Rect2(16, 0, 16, 16) + +[sub_resource type="SpriteFrames" id="SpriteFrames_257nh"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_vuhkc") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_26mqe") +}], +"loop": true, +"name": &"default", +"speed": 2.0 +}] + [sub_resource type="ShaderMaterial" id="ShaderMaterial_ypt7u"] shader = ExtResource("9_257nh") shader_parameter/shake = 0.002000000095 @@ -303,6 +326,27 @@ metadata/_custom_type_script = "uid://b2maxk5g6yb0i" [node name="Button" parent="UI/Control/DialogueOptions" instance=ExtResource("19_qqas2")] layout_mode = 2 +[node name="SaveIndicator" type="Control" parent="UI/Control"] +visible = false +custom_minimum_size = Vector2(64, 64) +layout_mode = 1 +anchors_preset = 3 +anchor_left = 1.0 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = -64.0 +offset_top = -64.0 +grow_horizontal = 0 +grow_vertical = 0 + +[node name="SaveIcon" type="AnimatedSprite2D" parent="UI/Control/SaveIndicator"] +position = Vector2(32, 32) +scale = Vector2(4, 4) +sprite_frames = SubResource("SpriteFrames_257nh") +autoplay = "default" +frame_progress = 0.42345548 + [node name="Shader" type="ColorRect" parent="UI"] material = SubResource("ShaderMaterial_ypt7u") anchors_preset = 15 diff --git a/scenes/title.tscn b/scenes/title.tscn index bbd48e7..ec4acbb 100644 --- a/scenes/title.tscn +++ b/scenes/title.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=12 format=3 uid="uid://b1x7evhkxm385"] +[gd_scene load_steps=13 format=3 uid="uid://b1x7evhkxm385"] [ext_resource type="Script" uid="uid://md1biuc6ygmv" path="res://scripts/title.gd" id="1_pyl7j"] [ext_resource type="FontFile" uid="uid://n1nd5m2kwexu" path="res://fonts/Michroma.ttf" id="1_wosw1"] @@ -8,6 +8,7 @@ [ext_resource type="Shader" uid="uid://bk7q00br1ms30" path="res://scripts/retro.gdshader" id="2_p6dhs"] [ext_resource type="Script" uid="uid://b2maxk5g6yb0i" path="res://addons/super_awesome_input_icons/classes/input_icon_texture_rect.gd" id="2_pyl7j"] [ext_resource type="FontFile" uid="uid://donsvh2l775rb" path="res://fonts/Doto.ttf" id="3_b3w7a"] +[ext_resource type="AudioStream" uid="uid://bff3l15ivkcyi" path="res://sounds/ui_back.mp3" id="3_w65of"] [ext_resource type="PackedScene" uid="uid://cy4nbqbm222os" path="res://scenes/settings.tscn" id="6_yql1r"] [sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_yql1r"] @@ -40,6 +41,9 @@ script = ExtResource("1_pyl7j") [node name="UiSelect" type="AudioStreamPlayer" parent="."] stream = ExtResource("2_hiwto") +[node name="UiBack" type="AudioStreamPlayer" parent="."] +stream = ExtResource("3_w65of") + [node name="Title" type="AudioStreamPlayer" parent="."] stream = ExtResource("2_ia1n6") volume_db = -4.0 @@ -306,7 +310,61 @@ theme_override_font_sizes/bold_italics_font_size = 32 theme_override_font_sizes/italics_font_size = 32 theme_override_font_sizes/mono_font_size = 32 bbcode_enabled = true -text = "[font size=20]soundtrack by delosound on pixabay[/font]" +text = "[font size=20]space ambient music: minecraft nether music (by C418)[/font]" +fit_content = true +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Label5" type="RichTextLabel" parent="UI/Control/Credits"] +custom_minimum_size = Vector2(640, 0) +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 +theme_override_fonts/normal_font = ExtResource("1_wosw1") +theme_override_fonts/bold_font = ExtResource("3_b3w7a") +theme_override_font_sizes/normal_font_size = 32 +theme_override_font_sizes/bold_font_size = 32 +theme_override_font_sizes/bold_italics_font_size = 32 +theme_override_font_sizes/italics_font_size = 32 +theme_override_font_sizes/mono_font_size = 32 +bbcode_enabled = true +text = "[font size=20]space station music: SCP-3008 soundtrack by uglyburger0[/font]" +fit_content = true +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Label6" type="RichTextLabel" parent="UI/Control/Credits"] +custom_minimum_size = Vector2(640, 0) +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 +theme_override_fonts/normal_font = ExtResource("1_wosw1") +theme_override_fonts/bold_font = ExtResource("3_b3w7a") +theme_override_font_sizes/normal_font_size = 32 +theme_override_font_sizes/bold_font_size = 32 +theme_override_font_sizes/bold_italics_font_size = 32 +theme_override_font_sizes/italics_font_size = 32 +theme_override_font_sizes/mono_font_size = 32 +bbcode_enabled = true +text = "[font size=20]title screen music: delosound on pixabay[/font]" +fit_content = true +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Label7" type="RichTextLabel" parent="UI/Control/Credits"] +custom_minimum_size = Vector2(640, 0) +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 +theme_override_fonts/normal_font = ExtResource("1_wosw1") +theme_override_fonts/bold_font = ExtResource("3_b3w7a") +theme_override_font_sizes/normal_font_size = 32 +theme_override_font_sizes/bold_font_size = 32 +theme_override_font_sizes/bold_italics_font_size = 32 +theme_override_font_sizes/italics_font_size = 32 +theme_override_font_sizes/mono_font_size = 32 +bbcode_enabled = true +text = "[font size=20]special thanks to hack club for getting me to finish projects for once[/font]" fit_content = true horizontal_alignment = 1 vertical_alignment = 1 @@ -446,7 +504,10 @@ color = Color(1, 1, 1, 0) [connection signal="pressed" from="UI/Control/ControllerInfo/Box/Flow/Continue" to="." method="_on_continue_pressed"] [connection signal="pressed" from="UI/Control/Title/Buttons/NewGame" to="." method="_on_new_game_pressed"] +[connection signal="pressed" from="UI/Control/Title/Buttons/LoadGame" to="." method="_on_load_game_pressed"] [connection signal="pressed" from="UI/Control/Title/Buttons/Settings" to="." method="_on_settings_pressed"] [connection signal="pressed" from="UI/Control/Title/Buttons/Credits" to="." method="_on_credits_pressed"] [connection signal="pressed" from="UI/Control/Title/Buttons/Quit" to="." method="_on_quit_pressed"] [connection signal="pressed" from="UI/Control/Credits/Buttons/ExitCredits" to="." method="_on_exit_credits_pressed"] +[connection signal="pressed" from="UI/Control/OverrideSave/Buttons/YesOverride" to="." method="_on_yes_override_pressed"] +[connection signal="pressed" from="UI/Control/OverrideSave/Buttons/NoOverride" to="." method="_on_no_override_pressed"] diff --git a/scripts/galactamart_worker.gd b/scripts/galactamart_worker.gd index eca3547..7bf43e9 100644 --- a/scripts/galactamart_worker.gd +++ b/scripts/galactamart_worker.gd @@ -62,6 +62,8 @@ func _interact(player: Node2D) -> void: await game.dialogue("Okay, your tank should be filled to 25%.") else: await game.dialogue("Sorry, but you don't have enough marks for that.") + + game.save_game() player.get_node("Camera").enabled = true $Camera.enabled = false diff --git a/scripts/game.gd b/scripts/game.gd index 2c0e627..c0ce8ac 100644 --- a/scripts/game.gd +++ b/scripts/game.gd @@ -41,6 +41,21 @@ func world_to_chunk(position: Vector2) -> Vector2: func chunk_to_world(position: Vector2) -> Vector2: return Vector2(floori(position.x * 1024), floori(position.y * 1024)) +## Saves the game. +func save_game() -> void: + $UI/Control/SaveIndicator.visible = true + + global.stats.position = { + "x": $Player.global_position.x, + "y": $Player.global_position.y + } + + global.save_game() + + await get_tree().create_timer(2).timeout + + $UI/Control/SaveIndicator.visible = false + func enter_physical(map): get_tree().paused = true @@ -109,6 +124,14 @@ func _ready() -> void: $Stars.add_child(star) i += 1 + + if global.stats.position: + $Player.global_position.x = global.stats.position.x + $Player.global_position.y = global.stats.position.y + + global.stats.position = null + else: + save_game() func _process(delta: float) -> void: if get_tree().paused: diff --git a/scripts/game_ground.gd b/scripts/game_ground.gd index 487643c..ca1a47e 100644 --- a/scripts/game_ground.gd +++ b/scripts/game_ground.gd @@ -18,6 +18,20 @@ var dialogue_speed = { "player_woozy": 0.2, } +func save_game() -> void: + $UI/Control/SaveIndicator.visible = true + + global.stats.position = { + "x": $PlayerGround.global_position.x, + "y": $PlayerGround.global_position.y + } + + global.save_game() + + await get_tree().create_timer(2).timeout + + $UI/Control/SaveIndicator.visible = false + func _ready() -> void: $UI/Control/Dialogue.visible = false @@ -40,6 +54,12 @@ func _ready() -> void: n._ground_ready() location_scene.free() + + if global.stats.position: + $PlayerGround.global_position.x = global.stats.position.x + $PlayerGround.global_position.y = global.stats.position.y + + global.stats.position = null func _process(delta: float) -> void: if current_interaction_area: diff --git a/scripts/global.gd b/scripts/global.gd index c0e3d2b..9a30e01 100644 --- a/scripts/global.gd +++ b/scripts/global.gd @@ -74,8 +74,7 @@ func load_game(): print("JSON Parse Error: ", json.get_error_message(), " in ", parse_result, " at line ", json.get_error_line()) return - if json.data.settings: settings = json.data.settings - if json.data.stats: settings = json.data.stats + if json.data.stats: stats = json.data.stats func load_settings(): if not FileAccess.file_exists("user://settings.json"): @@ -107,8 +106,8 @@ var default_stats = { "boost_tank_size": 1, "marks": 200, "location": "space", - "ship_position": Vector2(), - "ship_rotation": 0, + "position": Vector2(), + "rotation": 0, "story_progress": 1, "navigation_goal": null, "equipped_ground_gun": "pistol" diff --git a/scripts/story_handler_1.gd b/scripts/story_handler_1.gd index dbe8ac6..ebed68b 100644 --- a/scripts/story_handler_1.gd +++ b/scripts/story_handler_1.gd @@ -198,3 +198,5 @@ func _ground_ready() -> void: game.set_vignette_parameter("softness", i * 0.04) i += 2 + else: + game.save_game() diff --git a/scripts/title.gd b/scripts/title.gd index 0377ae4..ecf25e3 100644 --- a/scripts/title.gd +++ b/scripts/title.gd @@ -103,7 +103,7 @@ func _on_credits_pressed() -> void: func _on_exit_credits_pressed() -> void: if transitioning: return - $UiSelect.play() + $UiBack.play() transitioning = true @@ -174,7 +174,7 @@ func _on_settings_pressed() -> void: func _on_settings_back_pressed() -> void: if transitioning: return - $UiSelect.play() + $UiBack.play() transitioning = true @@ -227,7 +227,7 @@ func _on_new_game_pressed() -> void: $UI/Control/Title.visible = false - if global.stats.loaded: + if FileAccess.file_exists("user://savegame.save"): $UI/Control/OverrideSave.visible = true $UI/Control/OverrideSave.modulate.a = 0 @@ -242,10 +242,101 @@ func _on_new_game_pressed() -> void: i += 1 $UI/Control/OverrideSave/Buttons/NoOverride.grab_focus() + + transitioning = false + + return if global.stats.location == "space": get_tree().change_scene_to_file("res://scenes/game.tscn") else: get_tree().change_scene_to_file("res://scenes/ground.tscn") +func _on_load_game_pressed() -> void: + if transitioning: return + + $UiSelect.play() + + transitioning = true + + get_viewport().gui_release_focus() + var i = 0 + + while i < 6: + $UI/Control/Title.modulate.a -= 0.2 + + await get_tree().create_timer(0.2).timeout + + i += 1 + + $UI/Control/Title.visible = false + + await global.load_game() + + if global.stats.location == "space": + get_tree().change_scene_to_file("res://scenes/game.tscn") + else: + get_tree().change_scene_to_file("res://scenes/ground.tscn") + + +func _on_yes_override_pressed() -> void: + if transitioning: return + + $UiSelect.play() + + transitioning = true + + get_viewport().gui_release_focus() + var i = 0 + + while i < 6: + $UI/Control/OverrideSave.modulate.a -= 0.2 + + await get_tree().create_timer(0.2).timeout + + i += 1 + + $UI/Control/OverrideSave.visible = false + + global.stats = global.default_stats.duplicate_deep() + + if global.stats.location == "space": + get_tree().change_scene_to_file("res://scenes/game.tscn") + else: + get_tree().change_scene_to_file("res://scenes/ground.tscn") + + +func _on_no_override_pressed() -> void: + if transitioning: return + + $UiBack.play() + + transitioning = true + + get_viewport().gui_release_focus() + var i = 0 + + while i < 6: + $UI/Control/OverrideSave.modulate.a -= 0.2 + + await get_tree().create_timer(0.2).timeout + + i += 1 + + $UI/Control/OverrideSave.visible = false + $UI/Control/Title.visible = true + + $UI/Control/Title.modulate.a = 0 + + i = 0 + + while i < 6: + $UI/Control/Title.modulate.a += 0.2 + + await get_tree().create_timer(0.2).timeout + + i += 1 + + $UI/Control/Title/Buttons/NewGame.grab_focus() + transitioning = false diff --git a/textures/save_indicator.ase b/textures/save_indicator.ase new file mode 100644 index 0000000000000000000000000000000000000000..8caf786c5acf7ad775d6d3540d23966789cfc047 GIT binary patch literal 523 zcmd;PVqkc%l!-wA2o)F@85kH+fEWQ385lu=V0nZn^;i->(|>(r0o%#~G*%3V*%iQ6 zB3Y6PWV3)=rwC*yDVVrw*rZt+_J>*DFI2m^Ano1ZS-(G-&3qb=wa>tON}hM7evr3{ zk&UIjeThLrQ*_?LRtWQ zy}I%ZIyyS!L6#{nBU%3+$Yy8oNvupQQZP&da#$50vj2gh2LYh)tC*9VknrQYgOnTl z|3ro(?_RucIC$cdf$5YN$CKDj{CVv*!+s_yF{c*5=&)+2- Qf*$cME1^~{=ifFH0NhB43jhEB literal 0 HcmV?d00001 diff --git a/textures/save_indicator.png b/textures/save_indicator.png new file mode 100644 index 0000000000000000000000000000000000000000..a8c3bb0a16520f33ecac3f877245cf317b7ea044 GIT binary patch literal 224 zcmeAS@N?(olHy`uVBq!ia0vp^3P3Et!3HGD8EPYe6k~CayA#8@b22Z1oLQbOjv*eM zM?)O>8Wec4d;6bp{;86i!Xn5~YW%HbhuKsy&I1b?&u;GaXGkl{n&5Kor`g;fr^@&= zDM9gi;k)97Ust!++;rH&S=FMnA-pdorgGPh!yH`|yZer<=5tBv7hB`Mdf&Xa_tM#_ zYG;(DNI3ddMQ;+d;W@*#J;-h9e}jayyN;8*)fax+E&HNV!%*W-BIn+n>p#{17nR?5 XG>(7z`M6l1D;Ydp{an^LB{Ts5UA9z< literal 0 HcmV?d00001 diff --git a/textures/save_indicator.png.import b/textures/save_indicator.png.import new file mode 100644 index 0000000..f3d0364 --- /dev/null +++ b/textures/save_indicator.png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cwa4uu7hrw2l0" +path="res://.godot/imported/save_indicator.png-9ea36dce7f4f02849ef94f4ba75ec5ee.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://textures/save_indicator.png" +dest_files=["res://.godot/imported/save_indicator.png-9ea36dce7f4f02849ef94f4ba75ec5ee.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1