From 61b03c5801c9130c0457333722b1f2bd713b79ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Blomberg?= Date: Thu, 16 Oct 2025 10:50:04 +0200 Subject: [PATCH] Add initial project files and implement core game features - Created README.md with project description and setup instructions - Added project configuration files (TheGame.csproj, TheGame.sln, project.godot) - Implemented main game scenes (MainMenu.tscn, Game.tscn, LoadGameMenu.tscn) - Developed game logic in C# scripts (Game.cs, MainMenu.cs, LoadGameMenu.cs, PauseMenu.cs, SaveManager.cs) - Introduced save/load functionality and timer display - Included icon.svg for game branding --- README.md | 129 ++++++++++++++++++++++++++++++++++++++- TheGame.csproj | 9 +++ TheGame.sln | 24 ++++++++ icon.svg | 1 + project.godot | 30 +++++++++ scenes/Game.tscn | 120 ++++++++++++++++++++++++++++++++++++ scenes/LoadGameMenu.tscn | 54 ++++++++++++++++ scenes/MainMenu.tscn | 54 ++++++++++++++++ scripts/Game.cs | 76 +++++++++++++++++++++++ scripts/GameState.cs | 9 +++ scripts/LoadGameMenu.cs | 73 ++++++++++++++++++++++ scripts/MainMenu.cs | 38 ++++++++++++ scripts/PauseMenu.cs | 40 ++++++++++++ scripts/SaveManager.cs | 111 +++++++++++++++++++++++++++++++++ 14 files changed, 767 insertions(+), 1 deletion(-) create mode 100644 TheGame.csproj create mode 100644 TheGame.sln create mode 100644 icon.svg create mode 100644 project.godot create mode 100644 scenes/Game.tscn create mode 100644 scenes/LoadGameMenu.tscn create mode 100644 scenes/MainMenu.tscn create mode 100644 scripts/Game.cs create mode 100644 scripts/GameState.cs create mode 100644 scripts/LoadGameMenu.cs create mode 100644 scripts/MainMenu.cs create mode 100644 scripts/PauseMenu.cs create mode 100644 scripts/SaveManager.cs diff --git a/README.md b/README.md index 6bf7717..ad3301b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,130 @@ # TheGame -a game about hacking and is a gatcho game \ No newline at end of file +Ett 2D spel byggt i Godot med C# som innehåller en startmeny, timer och save/load funktionalitet. + +## Funktioner + +- **Startmeny** med knappar för Start Game, Load Game och Exit +- **Timer** som räknar speltid i övre högra hörnet +- **Pausmeny** med knapp i övre vänstra hörnet som innehåller: + - Pause/Resume funktionalitet + - Save Game + - Exit to Main Menu + - Exit to Desktop +- **Save/Load System** som sparar speltid i `saves/` mappen +- **Load Game Menu** som visar alla sparade spel med datum +- Load Game knappen är automatiskt utgråad om inga sparade spel finns + +## Krav och Dependencies + +### Systemkrav +- **Godot 4.2** eller senare med C# support +- **.NET 6.0** SDK eller senare +- **Windows** (testat på Windows, men bör fungera på andra plattformar) + +### Dependencies +Projektet använder följande .NET dependencies: +- `Godot.NET.Sdk` - Godot's .NET SDK +- `System.Text.Json` - För JSON serialisering av sparfiler + +## Installation och Setup + +### 1. Installera Godot med C# Support +1. Ladda ner Godot 4.2+ **Mono version** från [godotengine.org](https://godotengine.org/download) +2. Installera .NET 6.0 SDK från [Microsoft](https://dotnet.microsoft.com/download) + +### 2. Öppna Projektet +1. Starta Godot +2. Klicka på "Import" +3. Navigera till projektmappen och välj `project.godot` +4. Klicka "Import & Edit" + +### 3. Första Kompilering +1. I Godot editorn, gå till **Project → Tools → C# → Create C# solution** +2. Vänta tills kompileringen är klar +3. Om fel uppstår, kontrollera att .NET SDK är korrekt installerat + +## Kompilering och Körning + +### Utvecklingsläge (Godot Editor) +1. Öppna projektet i Godot +2. Tryck **F5** eller klicka på "Play"-knappen +3. Första gången kommer du behöva välja `scenes/MainMenu.tscn` som main scene + +### Bygga för Distribution +1. I Godot editorn, gå till **Project → Export** +2. Lägg till en export template för din målplattform (Windows, Linux, macOS) +3. Konfigurera export-inställningar +4. Klicka **Export Project** för att skapa en körbar fil + +### Alternativ Kompilering via Terminal +```bash +# Navigera till projektmappen +cd c:\Repo\TheGame + +# Bygg projektet +dotnet build + +# Kör Godot projekt från kommandoraden (kräver Godot i PATH) +godot --path . scenes/MainMenu.tscn +``` + +## Projektstruktur + +``` +TheGame/ +├── project.godot # Godot projektfil +├── TheGame.csproj # C# projektfil +├── scenes/ # Godot scener +│ ├── MainMenu.tscn # Huvudmeny +│ ├── Game.tscn # Spelscen +│ └── LoadGameMenu.tscn # Ladda spel meny +├── scripts/ # C# scripts +│ ├── MainMenu.cs # Huvudmeny logik +│ ├── Game.cs # Spel logik och timer +│ ├── PauseMenu.cs # Pausmeny logik +│ ├── SaveManager.cs # Save/Load hantering +│ ├── LoadGameMenu.cs # Ladda spel meny +│ └── GameState.cs # Spelstatus hantering +├── saves/ # Sparade spel (skapas automatiskt) +└── README.md # Denna fil +``` + +## Kontroller + +- **ESC** - Pausa/återuppta spelet +- **Musklick** - Navigera menyer och knappar +- **Pausknapp** (☰) - Pausa spelet (övre vänstra hörnet) + +## Felsökning + +### Vanliga Problem + +1. **"C# script compilation failed"** + - Kontrollera att .NET 6.0 SDK är installerat + - Kör `dotnet --version` i terminal för att verifiera + +2. **"Cannot find Godot.NET.Sdk"** + - Se till att du använder Godot Mono version + - Återskapa C# solution via Project → Tools → C# → Create C# solution + +3. **Save-filer sparas inte** + - Kontrollera att spelet har skrivrättigheter till projektmappen + - Saves sparas i `saves/` mappen bredvid den körbara filen + +4. **Load Game knapp fungerar inte** + - Detta är förväntat beteende om inga sparfiler finns + - Knappen blir automatiskt klickbar när du har sparat minst ett spel + +## Utveckling + +För att utveckla projektet vidare: + +1. Öppna projektet i Godot +2. C# scripts kan redigeras i valfri IDE (Visual Studio, VS Code, Rider) +3. Godot kommer automatiskt att kompilera om scripten när de ändras +4. Använd Godot's debugger för att felsöka runtime-problem + +## Licens + +Se `LICENSE` filen för licensinformation. \ No newline at end of file diff --git a/TheGame.csproj b/TheGame.csproj new file mode 100644 index 0000000..391a824 --- /dev/null +++ b/TheGame.csproj @@ -0,0 +1,9 @@ + + + net6.0 + net7.0 + net8.0 + true + TheGame + + \ No newline at end of file diff --git a/TheGame.sln b/TheGame.sln new file mode 100644 index 0000000..ddf40ae --- /dev/null +++ b/TheGame.sln @@ -0,0 +1,24 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.2.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TheGame", "TheGame.csproj", "{3104CB95-654D-4767-821F-5F55A5C625DE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3104CB95-654D-4767-821F-5F55A5C625DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3104CB95-654D-4767-821F-5F55A5C625DE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3104CB95-654D-4767-821F-5F55A5C625DE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3104CB95-654D-4767-821F-5F55A5C625DE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {90CEA6F9-D027-4227-BB50-85F9D2D80783} + EndGlobalSection +EndGlobal diff --git a/icon.svg b/icon.svg new file mode 100644 index 0000000..cc9bb65 --- /dev/null +++ b/icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..94fc3e1 --- /dev/null +++ b/project.godot @@ -0,0 +1,30 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=5 + +[application] + +config/name="TheGame" +run/main_scene="res://scenes/MainMenu.tscn" +config/features=PackedStringArray("4.2", "C#", "Forward Plus") +config/icon="res://icon.svg" + +[display] + +window/size/viewport_width=1280 +window/size/viewport_height=720 +window/size/resizable=true + +[dotnet] + +project/assembly_name="TheGame" + +[rendering] + +renderer/rendering_method="forward_plus" \ No newline at end of file diff --git a/scenes/Game.tscn b/scenes/Game.tscn new file mode 100644 index 0000000..d72042b --- /dev/null +++ b/scenes/Game.tscn @@ -0,0 +1,120 @@ +[gd_scene load_steps=3 format=3 uid="uid://bqkwdpfmu7tge"] + +[ext_resource type="Script" path="res://scripts/Game.cs" id="1_xncbp"] +[ext_resource type="Script" path="res://scripts/PauseMenu.cs" id="2_a5qiy"] + +[node name="Game" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource("1_xncbp") + +[node name="Background" type="ColorRect" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +color = Color(0.2, 0.3, 0.4, 1) + +[node name="UI" type="Control" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 + +[node name="PauseButton" type="Button" parent="UI"] +layout_mode = 0 +anchor_right = 0.1 +anchor_bottom = 0.08 +offset_left = 10.0 +offset_top = 10.0 +offset_right = -10.0 +offset_bottom = -10.0 +text = "☰" + +[node name="TimerLabel" type="Label" parent="UI"] +layout_mode = 0 +anchor_left = 0.85 +anchor_right = 1.0 +anchor_bottom = 0.08 +offset_left = 10.0 +offset_top = 10.0 +offset_right = -10.0 +offset_bottom = -10.0 +text = "00:00:00" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="GameContent" type="Label" 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 = -100.0 +offset_top = -20.0 +offset_right = 100.0 +offset_bottom = 20.0 +text = "GAME CONTENT HERE +Press ESC or click pause button to pause" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="PauseMenu" type="Control" parent="."] +visible = false +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource("2_a5qiy") + +[node name="Background" type="ColorRect" parent="PauseMenu"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +color = Color(0, 0, 0, 0.8) + +[node name="MenuContainer" type="VBoxContainer" parent="PauseMenu"] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -100.0 +offset_top = -120.0 +offset_right = 100.0 +offset_bottom = 120.0 + +[node name="TitleLabel" type="Label" parent="PauseMenu/MenuContainer"] +layout_mode = 2 +text = "PAUSED" +horizontal_alignment = 1 + +[node name="HSeparator" type="HSeparator" parent="PauseMenu/MenuContainer"] +layout_mode = 2 + +[node name="ResumeButton" type="Button" parent="PauseMenu/MenuContainer"] +layout_mode = 2 +text = "Resume" + +[node name="SaveButton" type="Button" parent="PauseMenu/MenuContainer"] +layout_mode = 2 +text = "Save Game" + +[node name="MainMenuButton" type="Button" parent="PauseMenu/MenuContainer"] +layout_mode = 2 +text = "Exit to Main Menu" + +[node name="DesktopButton" type="Button" parent="PauseMenu/MenuContainer"] +layout_mode = 2 +text = "Exit to Desktop" + +[connection signal="pressed" from="UI/PauseButton" to="." method="_on_pause_button_pressed"] +[connection signal="pressed" from="PauseMenu/MenuContainer/ResumeButton" to="PauseMenu" method="_on_resume_button_pressed"] +[connection signal="pressed" from="PauseMenu/MenuContainer/SaveButton" to="PauseMenu" method="_on_save_button_pressed"] +[connection signal="pressed" from="PauseMenu/MenuContainer/MainMenuButton" to="PauseMenu" method="_on_main_menu_button_pressed"] +[connection signal="pressed" from="PauseMenu/MenuContainer/DesktopButton" to="PauseMenu" method="_on_desktop_button_pressed"] \ No newline at end of file diff --git a/scenes/LoadGameMenu.tscn b/scenes/LoadGameMenu.tscn new file mode 100644 index 0000000..2a18b43 --- /dev/null +++ b/scenes/LoadGameMenu.tscn @@ -0,0 +1,54 @@ +[gd_scene load_steps=2 format=3 uid="uid://cdnyu0lqxhn80"] + +[ext_resource type="Script" path="res://scripts/LoadGameMenu.cs" id="1_l8m0c"] + +[node name="LoadGameMenu" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource("1_l8m0c") + +[node name="Background" type="ColorRect" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +color = Color(0.15, 0.15, 0.25, 1) + +[node name="VBoxContainer" type="VBoxContainer" 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 = -200.0 +offset_top = -200.0 +offset_right = 200.0 +offset_bottom = 200.0 + +[node name="TitleLabel" type="Label" parent="VBoxContainer"] +layout_mode = 2 +text = "LOAD GAME" +horizontal_alignment = 1 + +[node name="HSeparator" type="HSeparator" parent="VBoxContainer"] +layout_mode = 2 + +[node name="ScrollContainer" type="ScrollContainer" parent="VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 3 + +[node name="SaveList" type="VBoxContainer" parent="VBoxContainer/ScrollContainer"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="HSeparator2" type="HSeparator" parent="VBoxContainer"] +layout_mode = 2 + +[node name="BackButton" type="Button" parent="VBoxContainer"] +layout_mode = 2 +text = "Back to Main Menu" + +[connection signal="pressed" from="VBoxContainer/BackButton" to="." method="_on_back_button_pressed"] \ No newline at end of file diff --git a/scenes/MainMenu.tscn b/scenes/MainMenu.tscn new file mode 100644 index 0000000..7c60281 --- /dev/null +++ b/scenes/MainMenu.tscn @@ -0,0 +1,54 @@ +[gd_scene load_steps=2 format=3 uid="uid://dsrcpteclv0ar"] + +[ext_resource type="Script" path="res://scripts/MainMenu.cs" id="1_g4hxb"] + +[node name="MainMenu" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource("1_g4hxb") + +[node name="Background" type="ColorRect" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +color = Color(0.15, 0.15, 0.25, 1) + +[node name="VBoxContainer" type="VBoxContainer" 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 = -100.0 +offset_top = -100.0 +offset_right = 100.0 +offset_bottom = 100.0 + +[node name="TitleLabel" type="Label" parent="VBoxContainer"] +layout_mode = 2 +text = "THE GAME" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="HSeparator" type="HSeparator" parent="VBoxContainer"] +layout_mode = 2 + +[node name="StartButton" type="Button" parent="VBoxContainer"] +layout_mode = 2 +text = "Start Game" + +[node name="LoadButton" type="Button" parent="VBoxContainer"] +layout_mode = 2 +text = "Load Game" + +[node name="ExitButton" type="Button" parent="VBoxContainer"] +layout_mode = 2 +text = "Exit" + +[connection signal="pressed" from="VBoxContainer/StartButton" to="." method="_on_start_button_pressed"] +[connection signal="pressed" from="VBoxContainer/LoadButton" to="." method="_on_load_button_pressed"] +[connection signal="pressed" from="VBoxContainer/ExitButton" to="." method="_on_exit_button_pressed"] \ No newline at end of file diff --git a/scripts/Game.cs b/scripts/Game.cs new file mode 100644 index 0000000..83be572 --- /dev/null +++ b/scripts/Game.cs @@ -0,0 +1,76 @@ +using Godot; + +namespace TheGame +{ + public partial class Game : Control + { + private Label _timerLabel; + private Control _pauseMenu; + private float _gameTime = 0.0f; + private bool _isPaused = false; + + public override void _Ready() + { + _timerLabel = GetNode