diff --git a/scenes/HUD/menu_bar.gd b/scenes/HUD/menu_bar.gd new file mode 100644 index 0000000..3b5f574 --- /dev/null +++ b/scenes/HUD/menu_bar.gd @@ -0,0 +1,21 @@ +extends MenuBar + +func options_index_pressed(index): + var curr_position = get_global_mouse_position() + + if index == 0: + options_camera_pressed(curr_position) + elif index == 1: + options_world_pressed(curr_position) + + +func options_camera_pressed(target_position): + var camera_menu = $Options/Camera + camera_menu.position = target_position + camera_menu.show() + +func options_world_pressed(target_position): + var world_menu = $Options/World + world_menu.position = target_position + world_menu.show() + \ No newline at end of file diff --git a/scenes/HUD/menu_bar.gd.uid b/scenes/HUD/menu_bar.gd.uid new file mode 100644 index 0000000..87cd31a --- /dev/null +++ b/scenes/HUD/menu_bar.gd.uid @@ -0,0 +1 @@ +uid://8vkyddmxqfaf diff --git a/scenes/HUD/options_menu.gd b/scenes/HUD/options_menu.gd new file mode 100644 index 0000000..f6fd839 --- /dev/null +++ b/scenes/HUD/options_menu.gd @@ -0,0 +1 @@ +extends PopupMenu diff --git a/scenes/HUD/options_menu.gd.uid b/scenes/HUD/options_menu.gd.uid new file mode 100644 index 0000000..a371d3e --- /dev/null +++ b/scenes/HUD/options_menu.gd.uid @@ -0,0 +1 @@ +uid://cmoqidhmxlccq diff --git a/scenes/main/Camera2d.cs b/scenes/main/Camera2d.cs new file mode 100644 index 0000000..2438d0a --- /dev/null +++ b/scenes/main/Camera2d.cs @@ -0,0 +1,18 @@ +using Godot; +using System; + +public partial class Camera2d : Camera2D +{ + public float zoomSpeed = 0.05f; + public float zoomMin = 0.001f; + public float zoomMax = 2.0f; + public float dragSensitivity = 0.05f; + + + public override void _Input(InputEvent @event) + { + base._Input(@event); + } + + public static Vector2 Lerp(Vector2 from, Vector2 to, float weight) => from + (to - from) * weight; +} diff --git a/scenes/main/Camera2d.cs.uid b/scenes/main/Camera2d.cs.uid new file mode 100644 index 0000000..5d62802 --- /dev/null +++ b/scenes/main/Camera2d.cs.uid @@ -0,0 +1 @@ +uid://b3obsoy04p8gl diff --git a/scenes/main/EntityManager.cs b/scenes/main/EntityManager.cs new file mode 100644 index 0000000..f40e08e --- /dev/null +++ b/scenes/main/EntityManager.cs @@ -0,0 +1,27 @@ +using Ecosystem.scenes.entities; +using Godot; +using Godot.Collections; + +namespace Ecosystem.scenes.main; + +public partial class EntityManager : Node +{ + private static readonly object _lock = new object(); + private static EntityManager _instance; + public static EntityManager Instance + { + get + { + lock (_lock) + { + if (_instance == null) + _instance = new EntityManager(); + return _instance; + } + } + } + + private Dictionary _entities = new Dictionary(); + public Dictionary Entities => _entities; + public void AddEntity(entities.BaseEntity entity) => _entities.Add(0, entity); +} \ No newline at end of file diff --git a/scenes/main/EntityManager.cs.uid b/scenes/main/EntityManager.cs.uid new file mode 100644 index 0000000..8fdd11b --- /dev/null +++ b/scenes/main/EntityManager.cs.uid @@ -0,0 +1 @@ +uid://dskaddldr1q0x diff --git a/scenes/main/GobalCamera.cs b/scenes/main/GobalCamera.cs new file mode 100644 index 0000000..5f5e38c --- /dev/null +++ b/scenes/main/GobalCamera.cs @@ -0,0 +1,40 @@ +using Godot; +using System; + +public partial class GobalCamera : Camera2D +{ + public Vector2 zoomSpeed = new Vector2(0.05f, 0.05f); + public float zoomMin = 0.001f; + public float zoomMax = 2.0f; + [Export] public float dragSensitivity = 0.35f; + + + public override void _Input(InputEvent @event) + { + base._Input(@event); + + if (@event is InputEventMouseMotion mouseMotion && Input.IsMouseButtonPressed(MouseButton.Middle)) + { + Position -= mouseMotion.Relative * dragSensitivity / Zoom; + } + + if (@event is InputEventMouseButton mouseButton) + { + switch (mouseButton.ButtonIndex) + { + case MouseButton.WheelUp: + Zoom += zoomSpeed; + Zoom.Clamp(zoomMin, zoomMax); + break; + case MouseButton.WheelDown: + Zoom -= zoomSpeed; + Zoom.Clamp(zoomMin, zoomMax); + break; + } + + Zoom.Clamp(zoomMin, zoomMax); + } + } + + public static Vector2 Lerp(Vector2 from, Vector2 to, float weight) => from + (to - from) * weight; +} diff --git a/scenes/main/GobalCamera.cs.uid b/scenes/main/GobalCamera.cs.uid new file mode 100644 index 0000000..29bd2fb --- /dev/null +++ b/scenes/main/GobalCamera.cs.uid @@ -0,0 +1 @@ +uid://csmrhb44u00j diff --git a/scenes/main/Main.cs b/scenes/main/Main.cs new file mode 100644 index 0000000..3c25f3a --- /dev/null +++ b/scenes/main/Main.cs @@ -0,0 +1,55 @@ +using Godot; + +namespace Ecosystem.scenes.main; + +public partial class Main : Node +{ + public Vector2 screenSize; + public Node spawner; + public Camera2D camera; + + public override void _Ready() + { + screenSize = GetViewport().GetVisibleRect().Size; + camera = GetNode("GlobalCamera"); + spawner = GetNode("World/Spawner"); + + GetNode("Grid").Call("generateGrid"); + + camera.Position = new Vector2(screenSize.X / 2, screenSize.Y / 2); + + var flyPosition = camera.Position; + spawner.Call("spawn_fly", flyPosition); + + + } +} + + +/* main.gd +extends Node + +var screenSize: Vector2 +var spawner +var camera + +func _ready() -> void: +screenSize = get_viewport().get_visible_rect().size +spawner = $World/Spawner +camera = $Camera2D + +camera.position = Vector2(screenSize.x / 2, screenSize.x / 2) + +var flyPosition = camera.position +spawner.spawn_fly(flyPosition) +spawner.spawn_bee(flyPosition) + + + +func spawn_fly(): +spawner.spawn_fly(camera.position) + + +func open_entity_panel(entity): +const information_container: MarginContainer = $HUD/InformationMarginContainer +*/ \ No newline at end of file diff --git a/scenes/main/Main.cs.uid b/scenes/main/Main.cs.uid new file mode 100644 index 0000000..29f3688 --- /dev/null +++ b/scenes/main/Main.cs.uid @@ -0,0 +1 @@ +uid://dte8xibis5wf7 diff --git a/scenes/main/camera_2d.gd b/scenes/main/camera_2d.gd new file mode 100644 index 0000000..ac387b5 --- /dev/null +++ b/scenes/main/camera_2d.gd @@ -0,0 +1,84 @@ +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() + + if event is InputEventAction: + print("Action pressed", event.action) + if event.is_action_pressed("camera_up"): + move_up() + elif event.is_action_pressed("camera_down"): + move_down() + elif event.is_action_pressed("camera_left"): + move_left() + elif event.is_action_pressed("camera_right"): + move_right() + + +@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 + +@export var camera_speed: float = 10 +var target_position: Vector2 + + +func _physics_process(delta: float) -> void: + zoom = lerp( + zoom, + _target_zoom * Vector2.ONE, + ZOOM_RATE * delta + ) + + position = lerp( + position, + target_position, + camera_speed * delta + ) + +# set_physics_process(not is_equal_approx(zoom.x, _target_zoom)) + + +func move_up(): + target_position.y -= camera_speed + + +func move_down(): + target_position.y += camera_speed + + +func move_right(): + target_position.x += camera_speed + + +func move_left(): + target_position.x -= camera_speed \ No newline at end of file diff --git a/scenes/main/camera_2d.gd.uid b/scenes/main/camera_2d.gd.uid new file mode 100644 index 0000000..75523d2 --- /dev/null +++ b/scenes/main/camera_2d.gd.uid @@ -0,0 +1 @@ +uid://deol78luglq0w diff --git a/scenes/main/main.gd b/scenes/main/main.gd new file mode 100644 index 0000000..7cae5ea --- /dev/null +++ b/scenes/main/main.gd @@ -0,0 +1,22 @@ +extends Node + +var screenSize: Vector2 +var spawner +var camera + +func _ready() -> void: + screenSize = get_viewport().get_visible_rect().size + spawner = $World/Spawner + camera = $Camera2D + + camera.position = Vector2(screenSize.x / 2, screenSize.x / 2) + + var flyPosition = camera.position + spawner.spawn_fly(flyPosition) + spawner.spawn_bee(flyPosition) + + + +func spawn_fly(): + spawner.spawn_fly(camera.position) + \ No newline at end of file diff --git a/scenes/main/main.gd.uid b/scenes/main/main.gd.uid new file mode 100644 index 0000000..5e0cd05 --- /dev/null +++ b/scenes/main/main.gd.uid @@ -0,0 +1 @@ +uid://bb6w1hp1i6k6t diff --git a/scenes/main/main.tscn b/scenes/main/main.tscn new file mode 100644 index 0000000..42f6286 --- /dev/null +++ b/scenes/main/main.tscn @@ -0,0 +1,143 @@ +[gd_scene load_steps=8 format=3 uid="uid://bkw0abirq18mt"] + +[ext_resource type="Script" uid="uid://dte8xibis5wf7" path="res://scenes/main/Main.cs" id="1_6q06x"] +[ext_resource type="PackedScene" uid="uid://brbhyuelsuxyx" path="res://scenes/world/world.tscn" id="1_o5qli"] +[ext_resource type="Script" uid="uid://cqrt5x30j5vm6" path="res://scenes/main/grid.gd" id="3_hujxm"] +[ext_resource type="Script" uid="uid://csmrhb44u00j" path="res://scenes/main/GobalCamera.cs" id="3_ow5a4"] +[ext_resource type="Script" uid="uid://8vkyddmxqfaf" path="res://scenes/HUD/menu_bar.gd" id="4_tbgi4"] +[ext_resource type="Script" uid="uid://cmoqidhmxlccq" path="res://scenes/HUD/options_menu.gd" id="5_tefeu"] +[ext_resource type="Script" uid="uid://dskaddldr1q0x" path="res://scenes/main/EntityManager.cs" id="6_ow5a4"] + +[node name="Main" type="Node"] +script = ExtResource("1_6q06x") + +[node name="World" parent="." instance=ExtResource("1_o5qli")] +NoiseSeed = 5 +NoiseFrequency = 0.32 +NoiseOffset = Vector3(0.04, 0, 0) +NoiseFractalType = 2 +NoiseFractalOctaves = 10 +NoiseFractalLacunarity = 0.395 +NoiseFractalGain = 0.26 +NoiseFractalWeightedStrength = 0.355 + +[node name="Spawner" parent="World" index="1"] +position = Vector2(482.81, 501.18) + +[node name="Grid" type="Node2D" parent="."] +script = ExtResource("3_hujxm") +show_debug = true + +[node name="Debug" type="Node2D" parent="Grid"] + +[node name="GlobalCamera" type="Camera2D" parent="."] +drag_left_margin = 0.5 +drag_top_margin = 0.5 +drag_right_margin = 0.5 +drag_bottom_margin = 0.5 +script = ExtResource("3_ow5a4") + +[node name="HUD" type="CanvasLayer" parent="."] + +[node name="MenuBar" type="MenuBar" parent="HUD"] +anchors_preset = 10 +anchor_right = 1.0 +grow_horizontal = 2 +script = ExtResource("4_tbgi4") + +[node name="Entity" type="PopupMenu" parent="HUD/MenuBar"] +auto_translate_mode = 1 +size = Vector2i(109, 100) + +[node name="Spawn" type="PopupMenu" parent="HUD/MenuBar"] +size = Vector2i(109, 100) +item_count = 2 +item_0/text = "Fly" +item_0/id = 0 +item_1/text = "Bumblebee" +item_1/id = 1 + +[node name="Options" type="PopupMenu" parent="HUD/MenuBar"] +item_count = 2 +item_0/text = "Camera" +item_0/id = 0 +item_1/text = "World" +item_1/id = 1 +script = ExtResource("5_tefeu") + +[node name="Camera" type="PopupMenu" parent="HUD/MenuBar/Options"] +item_count = 2 +item_0/text = "Speed" +item_0/id = 0 +item_1/text = "Position" +item_1/id = 1 + +[node name="World" type="PopupMenu" parent="HUD/MenuBar/Options"] +auto_translate_mode = 1 +item_count = 1 +item_0/text = "Generate" +item_0/id = 0 + +[node name="SpawnMenuButton" type="MenuButton" parent="HUD"] +visible = false +anchors_preset = 2 +anchor_top = 1.0 +anchor_bottom = 1.0 +offset_top = -31.0 +offset_right = 60.0 +grow_vertical = 0 +text = "Spawn" +item_count = 2 +popup/item_0/text = "Fly" +popup/item_0/id = 0 +popup/item_1/text = "Bumblebee" +popup/item_1/id = 1 + +[node name="Button" type="Button" parent="HUD"] +visible = false +anchors_preset = 7 +anchor_left = 0.5 +anchor_top = 1.0 +anchor_right = 0.5 +anchor_bottom = 1.0 +offset_left = -42.5 +offset_top = -31.0 +offset_right = 42.5 +grow_horizontal = 2 +grow_vertical = 0 +text = "Spawn Fly" + +[node name="GenerateWorldButton" type="Button" parent="HUD"] +anchors_preset = 3 +anchor_left = 1.0 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = -131.0 +offset_top = -31.0 +grow_horizontal = 0 +grow_vertical = 0 +text = "Regenerate World" + +[node name="InformationMarginContainer" type="MarginContainer" parent="HUD"] +anchors_preset = 12 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 0 + +[node name="HBoxContainer" type="HBoxContainer" parent="HUD/InformationMarginContainer"] +layout_mode = 2 + +[node name="EntityInformationContainer" type="VBoxContainer" parent="HUD/InformationMarginContainer/HBoxContainer"] +layout_mode = 2 + +[node name="EntityManager" type="Node" parent="."] +script = ExtResource("6_ow5a4") + +[connection signal="index_pressed" from="HUD/MenuBar/Options" to="HUD/MenuBar" method="options_index_pressed"] +[connection signal="pressed" from="HUD/Button" to="." method="spawn_fly"] +[connection signal="pressed" from="HUD/GenerateWorldButton" to="World" method="GenerateWorld"] + +[editable path="World"] diff --git a/scripts/Data.cs b/scripts/Data.cs new file mode 100644 index 0000000..03791c1 --- /dev/null +++ b/scripts/Data.cs @@ -0,0 +1,13 @@ +using Godot; +using System; + +[GlobalClass] +public partial class Data : GodotObject +{ + public struct EntityData + { + [Export] public String Name; + [Export] public bool CanFly; + [Export] public bool CanSpawnThings; + } +} diff --git a/scripts/Data.cs.uid b/scripts/Data.cs.uid new file mode 100644 index 0000000..8cd7bdc --- /dev/null +++ b/scripts/Data.cs.uid @@ -0,0 +1 @@ +uid://ucbh1i3pk1qy diff --git a/utility/CellData.gd b/utility/CellData.gd new file mode 100644 index 0000000..c69f6e6 --- /dev/null +++ b/utility/CellData.gd @@ -0,0 +1,5 @@ +class_name CellData +extends Resource + +@export var name: String +@export var texture: Texture diff --git a/utility/CellData.gd.uid b/utility/CellData.gd.uid new file mode 100644 index 0000000..ac215d1 --- /dev/null +++ b/utility/CellData.gd.uid @@ -0,0 +1 @@ +uid://s2rldju52u45 diff --git a/utility/EntityData.gd b/utility/EntityData.gd new file mode 100644 index 0000000..17f6e1b --- /dev/null +++ b/utility/EntityData.gd @@ -0,0 +1,6 @@ +class_name EntityData +extends Resource + +@export var name: String +@export var canFly: bool +@export var canSpawnThings: bool \ No newline at end of file diff --git a/utility/EntityData.gd.uid b/utility/EntityData.gd.uid new file mode 100644 index 0000000..e5c5071 --- /dev/null +++ b/utility/EntityData.gd.uid @@ -0,0 +1 @@ +uid://v6ittu7sc334