From 802918e5b81cc0a0c4a3f9d5a51ff92704e52d30 Mon Sep 17 00:00:00 2001 From: gdz Date: Tue, 29 Jul 2025 23:21:53 +0200 Subject: [PATCH] Version 0.1 - 0.3.1 Added the World Added Mobs, and spawning those mobs at runtime Added simple camera movement Added simple UI/HUD --- .idea/.idea.Ecosystem/.idea/.gitignore | 13 ++ .idea/.idea.Ecosystem/.idea/.name | 1 + .idea/.idea.Ecosystem/.idea/encodings.xml | 4 + .idea/.idea.Ecosystem/.idea/indexLayout.xml | 8 ++ .../.idea/libraries/GdSdk_Master.xml | 10 ++ .idea/.idea.Ecosystem/.idea/vcs.xml | 6 + Ecosystem.csproj | 6 + Ecosystem.sln | 19 +++ Ecosystem.sln.DotSettings.user | 3 + art/mobs/fly/bumblebee.png | Bin 0 -> 214 bytes art/mobs/fly/bumblebee.png.import | 34 +++++ art/spawner_fallback.png | Bin 0 -> 161 bytes art/spawner_fallback.png.import | 34 +++++ project.godot | 48 ++++++- scenes/Camera2d.cs | 76 +++++++++++ scenes/Camera2d.cs.uid | 1 + scenes/Main.cs | 17 +++ scenes/Main.cs.uid | 1 + scenes/camera_2d.gd | 41 ++++++ scenes/camera_2d.gd.uid | 1 + scenes/entities/BaseEntity.cs | 103 +++++++++++++++ scenes/entities/BaseEntity.cs.uid | 1 + scenes/entities/BaseEntity.tscn | 51 ++++++++ scenes/entities/bumblebee/Bumblebee.cs | 16 +++ scenes/entities/bumblebee/Bumblebee.cs.uid | 1 + scenes/entities/bumblebee/bumblebee.tscn | 61 +++++++++ scenes/entities/fly/Fly.cs | 64 +++++++++ scenes/entities/fly/Fly.cs.uid | 1 + scenes/entities/fly/fly.tscn | 67 ++++++++++ scenes/main.gd | 21 +++ scenes/main.gd.uid | 1 + scenes/main.tscn | 121 ++++++++++++++++++ scenes/menu_bar.gd | 20 +++ scenes/menu_bar.gd.uid | 1 + scenes/options_menu.gd | 1 + scenes/options_menu.gd.uid | 1 + scenes/spawner/advanced_spwaner.gd | 23 ++++ scenes/spawner/advanced_spwaner.gd.uid | 1 + scenes/spawner/spawner.gd | 17 +++ scenes/spawner/spawner.gd.uid | 1 + scenes/spawner/spawner.tscn | 17 +++ scenes/world/World.cs | 91 +++++++++++++ scenes/world/World.cs.uid | 1 + scenes/world/world.tscn | 28 ++++ utility/Math.cs | 54 ++++++++ utility/Math.cs.uid | 1 + 46 files changed, 1087 insertions(+), 1 deletion(-) create mode 100644 .idea/.idea.Ecosystem/.idea/.gitignore create mode 100644 .idea/.idea.Ecosystem/.idea/.name create mode 100644 .idea/.idea.Ecosystem/.idea/encodings.xml create mode 100644 .idea/.idea.Ecosystem/.idea/indexLayout.xml create mode 100644 .idea/.idea.Ecosystem/.idea/libraries/GdSdk_Master.xml create mode 100644 .idea/.idea.Ecosystem/.idea/vcs.xml create mode 100644 Ecosystem.csproj create mode 100644 Ecosystem.sln create mode 100644 Ecosystem.sln.DotSettings.user create mode 100644 art/mobs/fly/bumblebee.png create mode 100644 art/mobs/fly/bumblebee.png.import create mode 100644 art/spawner_fallback.png create mode 100644 art/spawner_fallback.png.import create mode 100644 scenes/Camera2d.cs create mode 100644 scenes/Camera2d.cs.uid create mode 100644 scenes/Main.cs create mode 100644 scenes/Main.cs.uid create mode 100644 scenes/camera_2d.gd create mode 100644 scenes/camera_2d.gd.uid create mode 100644 scenes/entities/BaseEntity.cs create mode 100644 scenes/entities/BaseEntity.cs.uid create mode 100644 scenes/entities/BaseEntity.tscn create mode 100644 scenes/entities/bumblebee/Bumblebee.cs create mode 100644 scenes/entities/bumblebee/Bumblebee.cs.uid create mode 100644 scenes/entities/bumblebee/bumblebee.tscn create mode 100644 scenes/entities/fly/Fly.cs create mode 100644 scenes/entities/fly/Fly.cs.uid create mode 100644 scenes/entities/fly/fly.tscn create mode 100644 scenes/main.gd create mode 100644 scenes/main.gd.uid create mode 100644 scenes/main.tscn create mode 100644 scenes/menu_bar.gd create mode 100644 scenes/menu_bar.gd.uid create mode 100644 scenes/options_menu.gd create mode 100644 scenes/options_menu.gd.uid create mode 100644 scenes/spawner/advanced_spwaner.gd create mode 100644 scenes/spawner/advanced_spwaner.gd.uid create mode 100644 scenes/spawner/spawner.gd create mode 100644 scenes/spawner/spawner.gd.uid create mode 100644 scenes/spawner/spawner.tscn create mode 100644 scenes/world/World.cs create mode 100644 scenes/world/World.cs.uid create mode 100644 scenes/world/world.tscn create mode 100644 utility/Math.cs create mode 100644 utility/Math.cs.uid diff --git a/.idea/.idea.Ecosystem/.idea/.gitignore b/.idea/.idea.Ecosystem/.idea/.gitignore new file mode 100644 index 0000000..47474ad --- /dev/null +++ b/.idea/.idea.Ecosystem/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/contentModel.xml +/.idea.Ecosystem.iml +/projectSettingsUpdater.xml +/modules.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.idea.Ecosystem/.idea/.name b/.idea/.idea.Ecosystem/.idea/.name new file mode 100644 index 0000000..ba08cab --- /dev/null +++ b/.idea/.idea.Ecosystem/.idea/.name @@ -0,0 +1 @@ +Ecosystem \ No newline at end of file diff --git a/.idea/.idea.Ecosystem/.idea/encodings.xml b/.idea/.idea.Ecosystem/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/.idea.Ecosystem/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.Ecosystem/.idea/indexLayout.xml b/.idea/.idea.Ecosystem/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/.idea.Ecosystem/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Ecosystem/.idea/libraries/GdSdk_Master.xml b/.idea/.idea.Ecosystem/.idea/libraries/GdSdk_Master.xml new file mode 100644 index 0000000..30535c3 --- /dev/null +++ b/.idea/.idea.Ecosystem/.idea/libraries/GdSdk_Master.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Ecosystem/.idea/vcs.xml b/.idea/.idea.Ecosystem/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/.idea.Ecosystem/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Ecosystem.csproj b/Ecosystem.csproj new file mode 100644 index 0000000..8eebc1d --- /dev/null +++ b/Ecosystem.csproj @@ -0,0 +1,6 @@ + + + net8.0 + true + + \ No newline at end of file diff --git a/Ecosystem.sln b/Ecosystem.sln new file mode 100644 index 0000000..664f67f --- /dev/null +++ b/Ecosystem.sln @@ -0,0 +1,19 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ecosystem", "Ecosystem.csproj", "{055B99F5-4C00-494B-AF80-5AE1A86BE6C3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + ExportDebug|Any CPU = ExportDebug|Any CPU + ExportRelease|Any CPU = ExportRelease|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {055B99F5-4C00-494B-AF80-5AE1A86BE6C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {055B99F5-4C00-494B-AF80-5AE1A86BE6C3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {055B99F5-4C00-494B-AF80-5AE1A86BE6C3}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU + {055B99F5-4C00-494B-AF80-5AE1A86BE6C3}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU + {055B99F5-4C00-494B-AF80-5AE1A86BE6C3}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU + {055B99F5-4C00-494B-AF80-5AE1A86BE6C3}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU + EndGlobalSection +EndGlobal diff --git a/Ecosystem.sln.DotSettings.user b/Ecosystem.sln.DotSettings.user new file mode 100644 index 0000000..d970172 --- /dev/null +++ b/Ecosystem.sln.DotSettings.user @@ -0,0 +1,3 @@ + + ForceIncluded + ForceIncluded \ No newline at end of file diff --git a/art/mobs/fly/bumblebee.png b/art/mobs/fly/bumblebee.png new file mode 100644 index 0000000000000000000000000000000000000000..fd7ecd8339800ea7317d9d7841dc6e3909f2949c GIT binary patch literal 214 zcmeAS@N?(olHy`uVBq!ia0vp^3P3Et!3HGD8EPYe6k~CayA#8@b22Z1oC%&Tjv*eM z$q5py%sdhofBY{z@mR>6eafrjSqi(-f*2hC{)lnfw%YSzzp+Mry^*tE!c%M4F6EAE z=bH|1<#|>0e}h!dvGgOV?k#mY?)`u9;JfoOe)MaHQeC&y-u|n)EgtJHhd8(S+jX5*L3)%x&~FHZ#=uv?8wIX2)5D8iv(L zGZYP&3nhNZEAwn%jHyd^;CD%4;*plPQDTtAz|5??^rj?3Y_Cp@^yvrOKx-I0UHx3v IIVCg!0N!Rbv;Y7A literal 0 HcmV?d00001 diff --git a/art/spawner_fallback.png.import b/art/spawner_fallback.png.import new file mode 100644 index 0000000..defa6b4 --- /dev/null +++ b/art/spawner_fallback.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b6wg3uyaeju7u" +path="res://.godot/imported/spawner_fallback.png-105b6f8dbe93a33a7282612a301b76ab.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://art/spawner_fallback.png" +dest_files=["res://.godot/imported/spawner_fallback.png-105b6f8dbe93a33a7282612a301b76ab.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +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/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 diff --git a/project.godot b/project.godot index 9fa15fe..8174ad9 100644 --- a/project.godot +++ b/project.godot @@ -11,9 +11,55 @@ config_version=5 [application] config/name="Ecosystem" -config/features=PackedStringArray("4.4", "Forward Plus") +config/version="0.3.2" +run/main_scene="res://scenes/main.tscn" +config/features=PackedStringArray("4.4", "C#", "Forward Plus") config/icon="res://art/icon.svg" +[display] + +window/size/viewport_width=800 +window/size/viewport_height=600 + [dotnet] project/assembly_name="Ecosystem" + +[input] + +zoom_in={ +"deadzone": 0.2, +"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":5,"canceled":false,"pressed":false,"double_click":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":43,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +] +} +zoom_out={ +"deadzone": 0.2, +"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":4,"canceled":false,"pressed":false,"double_click":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":45,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +] +} +camera_up={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null) +] +} +camera_down={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null) +] +} +camera_right={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null) +] +} +camera_left={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null) +] +} + +[rendering] + +textures/canvas_textures/default_texture_filter=0 diff --git a/scenes/Camera2d.cs b/scenes/Camera2d.cs new file mode 100644 index 0000000..60c9cc8 --- /dev/null +++ b/scenes/Camera2d.cs @@ -0,0 +1,76 @@ +using Godot; +using System; + +public partial class Camera2d : Camera2D +{ + private float targetZoom = 1.0f; + private float minZoom = .1f; + private float maxZoom = 1.0f; + private float zoomIncrement = .1f; + private float zoomRate = 8.0f; + + public override void _Ready() + { + // Print the size of the viewport. + GD.Print("Viewport Resolution is: ", GetViewport().GetVisibleRect().Size); + } + + public override void _Input(InputEvent @event) + { + // Mouse in viewport coordinates. + if (@event is InputEventMouseButton eventMouseButton) + { + GD.Print("Mouse Click/Unclick at: ", eventMouseButton.Position); + + switch (eventMouseButton.ButtonIndex) + { + case MouseButton.Left: + Position = eventMouseButton.Position; + break; + case MouseButton.WheelDown: + zoomIn(); + break; + case MouseButton.WheelUp: + zoomOut(); + break; + default: + break; + } + } + else if (@event is InputEventMouseMotion eventMouseMotion) + { + Vector2 zoomThreshold = new Vector2(.2f, .2f); // When should the zoom doesnt be accounted + Vector2 zoomThresholdSpeed = new Vector2(1.0f, 1.0f); // What value to use when the Threshold is reached + + GD.Print("Mouse Motion at: ", eventMouseMotion.Position); + + if (eventMouseMotion.ButtonMask == MouseButtonMask.Middle) + Position -= eventMouseMotion.Relative * (Zoom < zoomThreshold ? zoomThresholdSpeed : Zoom); + } + + GD.Print("Camera Position: ", Position); + } + + public override void _PhysicsProcess(double delta) + { + Zoom = Lerp(Zoom, targetZoom * Vector2.One, zoomRate * (float)delta); + if (Zoom.X == targetZoom) + SetPhysicsProcess(false); + + GD.Print("Camera Zoom: ", Zoom); + } + + private void zoomIn() + { + targetZoom = Single.Max(targetZoom - zoomIncrement, minZoom); + SetPhysicsProcess(true); + } + + private void zoomOut() + { + targetZoom = Single.Min(targetZoom + zoomIncrement, maxZoom); + SetPhysicsProcess(true); + } + + public static Vector2 Lerp(Vector2 from, Vector2 to, float weight) => from + (to - from) * weight; +} diff --git a/scenes/Camera2d.cs.uid b/scenes/Camera2d.cs.uid new file mode 100644 index 0000000..5d62802 --- /dev/null +++ b/scenes/Camera2d.cs.uid @@ -0,0 +1 @@ +uid://b3obsoy04p8gl diff --git a/scenes/Main.cs b/scenes/Main.cs new file mode 100644 index 0000000..e246e3b --- /dev/null +++ b/scenes/Main.cs @@ -0,0 +1,17 @@ +using Godot; +using System; + +public partial class Main : Node +{ + public override void _Ready() + { + var screenSize = GetViewport().GetVisibleRect().Size; + var camera = GetNode("Camera2D"); + camera.Position = new Vector2(screenSize.X / 2, screenSize.Y / 2); + + var spawner = GetNode("World/Spawner"); + + var flyPosition = camera.Position; + // spawner.spawn_fly(flyPosition); + } +} diff --git a/scenes/Main.cs.uid b/scenes/Main.cs.uid new file mode 100644 index 0000000..29f3688 --- /dev/null +++ b/scenes/Main.cs.uid @@ -0,0 +1 @@ +uid://dte8xibis5wf7 diff --git a/scenes/camera_2d.gd b/scenes/camera_2d.gd new file mode 100644 index 0000000..0d59247 --- /dev/null +++ b/scenes/camera_2d.gd @@ -0,0 +1,41 @@ +extends Camera2D + +@export_group("Zoom") +@export var _target_zoom: float = 1.0 + +func _ready() -> void: + position = Vector2(500, 500) + +func _unhandled_input(event: InputEvent) -> void: + if event is InputEventMouseMotion: + if event.button_mask == MOUSE_BUTTON_MASK_MIDDLE: + position -= event.relative * zoom + if event is InputEventMouseButton: + if event.is_pressed(): + if event.button_index == MOUSE_BUTTON_WHEEL_DOWN: + zoom_in() + if event.button_index == MOUSE_BUTTON_WHEEL_UP: + zoom_out() + +@export_group("Zoom") +@export var MIN_ZOOM: float = 0.1 +@export var MAX_ZOOM: float = 1.0 +@export var ZOOM_INCREMENT: float = 0.1 + +func zoom_in(): + _target_zoom = max(_target_zoom - ZOOM_INCREMENT, MIN_ZOOM) + set_physics_process(true) + +func zoom_out(): + _target_zoom = min(_target_zoom + ZOOM_INCREMENT, MAX_ZOOM) + set_physics_process(true) + +const ZOOM_RATE: float = 8.0 + +func _physics_process(delta: float) -> void: + zoom = lerp( + zoom, + _target_zoom * Vector2.ONE, + ZOOM_RATE * delta + ) + set_physics_process(not is_equal_approx(zoom.x, _target_zoom)) diff --git a/scenes/camera_2d.gd.uid b/scenes/camera_2d.gd.uid new file mode 100644 index 0000000..75523d2 --- /dev/null +++ b/scenes/camera_2d.gd.uid @@ -0,0 +1 @@ +uid://deol78luglq0w diff --git a/scenes/entities/BaseEntity.cs b/scenes/entities/BaseEntity.cs new file mode 100644 index 0000000..5ccc536 --- /dev/null +++ b/scenes/entities/BaseEntity.cs @@ -0,0 +1,103 @@ +using Godot; +using System; + +public partial class BaseEntity : Area2D +{ + [Signal] + public delegate BaseEntity EntitySelectedEventHandler(); + + [Signal] + public delegate BaseEntity EntityDeselectedEventHandler(); + + protected Vector2 ScreenSize; + protected AnimationPlayer animationPlayer; + protected Sprite2D sprite; + protected CollisionShape2D collisionShape; + + protected bool selected; + + + public override void _Ready() + { + ScreenSize = GetViewportRect().Size; + + sprite = GetNode("Sprite2D"); + collisionShape = GetNode("CollisionShape2D"); + animationPlayer = sprite.GetNode("AnimationPlayer"); + } + + public override void _UnhandledInput(InputEvent @event) + { + if (@event is InputEventMouseButton mouseEvent) + { + if (mouseEvent.IsPressed() && !mouseEvent.IsEcho()) + { + switch (mouseEvent.ButtonIndex) + { + case MouseButton.Left: + if (collisionShape.Shape.GetRect().HasPoint(GetLocalMousePosition())) entitySelected(); + else if (selected) entityDeselected(); + break; + default: + break; + } + } + } + } + + protected void entitySelected() + { + selected = true; + GD.Print("Selected"); + GetNode("SelectedSprite2D").Visible = true; + EmitSignalEntitySelected(); + + ShowInfo(); + } + + protected void entityDeselected() + { + selected = false; + GD.Print("Unselected"); + GetNode("SelectedSprite2D").Visible = false; + + EmitSignalEntityDeselected(); + + HideInfo(); + + } + + protected void ShowInfo() + { + MarginContainer marginContainer = GetNode("MarginContainer"); + Label nameLabel = GetNode