From b429afcb819fb4f71ad9cf43c75b30cca28b48d2 Mon Sep 17 00:00:00 2001 From: gdz Date: Fri, 8 Aug 2025 19:39:33 +0200 Subject: [PATCH] More World Generation, more Camera, other stuff. --- Ecosystem.sln.DotSettings.user | 5 +- project.godot | 2 +- 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 | 21 +- scenes/entities/bumblebee/Bumblebee.cs | 2 +- scenes/entities/fly/Fly.cs | 6 +- scenes/main.gd | 21 -- scenes/main.gd.uid | 1 - scenes/main.tscn | 121 --------- scenes/main/grid.gd | 33 +++ scenes/main/grid.gd.uid | 1 + scenes/menu_bar.gd | 20 -- scenes/menu_bar.gd.uid | 1 - scenes/options_menu.gd | 1 - scenes/options_menu.gd.uid | 1 - scenes/world/World.cs | 340 +++++++++++++++++++++++-- scenes/world/world.tscn | 3 + 22 files changed, 382 insertions(+), 334 deletions(-) delete mode 100644 scenes/Camera2d.cs delete mode 100644 scenes/Camera2d.cs.uid delete mode 100644 scenes/Main.cs delete mode 100644 scenes/Main.cs.uid delete mode 100644 scenes/camera_2d.gd delete mode 100644 scenes/camera_2d.gd.uid delete mode 100644 scenes/main.gd delete mode 100644 scenes/main.gd.uid delete mode 100644 scenes/main.tscn create mode 100644 scenes/main/grid.gd create mode 100644 scenes/main/grid.gd.uid delete mode 100644 scenes/menu_bar.gd delete mode 100644 scenes/menu_bar.gd.uid delete mode 100644 scenes/options_menu.gd delete mode 100644 scenes/options_menu.gd.uid diff --git a/Ecosystem.sln.DotSettings.user b/Ecosystem.sln.DotSettings.user index d970172..11d669d 100644 --- a/Ecosystem.sln.DotSettings.user +++ b/Ecosystem.sln.DotSettings.user @@ -1,3 +1,6 @@  ForceIncluded - ForceIncluded \ No newline at end of file + ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded \ No newline at end of file diff --git a/project.godot b/project.godot index 8174ad9..6d87984 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="Ecosystem" config/version="0.3.2" -run/main_scene="res://scenes/main.tscn" +run/main_scene="res://scenes/main/main.tscn" config/features=PackedStringArray("4.4", "C#", "Forward Plus") config/icon="res://art/icon.svg" diff --git a/scenes/Camera2d.cs b/scenes/Camera2d.cs deleted file mode 100644 index 60c9cc8..0000000 --- a/scenes/Camera2d.cs +++ /dev/null @@ -1,76 +0,0 @@ -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 deleted file mode 100644 index 5d62802..0000000 --- a/scenes/Camera2d.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://b3obsoy04p8gl diff --git a/scenes/Main.cs b/scenes/Main.cs deleted file mode 100644 index e246e3b..0000000 --- a/scenes/Main.cs +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 29f3688..0000000 --- a/scenes/Main.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://dte8xibis5wf7 diff --git a/scenes/camera_2d.gd b/scenes/camera_2d.gd deleted file mode 100644 index 0d59247..0000000 --- a/scenes/camera_2d.gd +++ /dev/null @@ -1,41 +0,0 @@ -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 deleted file mode 100644 index 75523d2..0000000 --- a/scenes/camera_2d.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://deol78luglq0w diff --git a/scenes/entities/BaseEntity.cs b/scenes/entities/BaseEntity.cs index 5ccc536..1ca943e 100644 --- a/scenes/entities/BaseEntity.cs +++ b/scenes/entities/BaseEntity.cs @@ -1,5 +1,7 @@ using Godot; -using System; + +using Ecosystem.utility; +namespace Ecosystem.scenes.entities; public partial class BaseEntity : Area2D { @@ -8,6 +10,8 @@ public partial class BaseEntity : Area2D [Signal] public delegate BaseEntity EntityDeselectedEventHandler(); + + public Data.EntityData _data; protected Vector2 ScreenSize; protected AnimationPlayer animationPlayer; @@ -16,7 +20,8 @@ public partial class BaseEntity : Area2D protected bool selected; - + protected Label positionLabel; + public override void _Ready() { ScreenSize = GetViewportRect().Size; @@ -24,6 +29,8 @@ public partial class BaseEntity : Area2D sprite = GetNode("Sprite2D"); collisionShape = GetNode("CollisionShape2D"); animationPlayer = sprite.GetNode("AnimationPlayer"); + + positionLabel = GetNode