MORE Camera
This commit is contained in:
21
scenes/HUD/menu_bar.gd
Normal file
21
scenes/HUD/menu_bar.gd
Normal file
@@ -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()
|
||||
|
||||
1
scenes/HUD/menu_bar.gd.uid
Normal file
1
scenes/HUD/menu_bar.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://8vkyddmxqfaf
|
||||
1
scenes/HUD/options_menu.gd
Normal file
1
scenes/HUD/options_menu.gd
Normal file
@@ -0,0 +1 @@
|
||||
extends PopupMenu
|
||||
1
scenes/HUD/options_menu.gd.uid
Normal file
1
scenes/HUD/options_menu.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cmoqidhmxlccq
|
||||
18
scenes/main/Camera2d.cs
Normal file
18
scenes/main/Camera2d.cs
Normal file
@@ -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;
|
||||
}
|
||||
1
scenes/main/Camera2d.cs.uid
Normal file
1
scenes/main/Camera2d.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b3obsoy04p8gl
|
||||
27
scenes/main/EntityManager.cs
Normal file
27
scenes/main/EntityManager.cs
Normal file
@@ -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<int, entities.BaseEntity> _entities = new Dictionary<int, entities.BaseEntity>();
|
||||
public Dictionary<int, entities.BaseEntity> Entities => _entities;
|
||||
public void AddEntity(entities.BaseEntity entity) => _entities.Add(0, entity);
|
||||
}
|
||||
1
scenes/main/EntityManager.cs.uid
Normal file
1
scenes/main/EntityManager.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dskaddldr1q0x
|
||||
40
scenes/main/GobalCamera.cs
Normal file
40
scenes/main/GobalCamera.cs
Normal file
@@ -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;
|
||||
}
|
||||
1
scenes/main/GobalCamera.cs.uid
Normal file
1
scenes/main/GobalCamera.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://csmrhb44u00j
|
||||
55
scenes/main/Main.cs
Normal file
55
scenes/main/Main.cs
Normal file
@@ -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<Camera2D>("GlobalCamera");
|
||||
spawner = GetNode("World/Spawner");
|
||||
|
||||
GetNode<Node2D>("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
|
||||
*/
|
||||
1
scenes/main/Main.cs.uid
Normal file
1
scenes/main/Main.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dte8xibis5wf7
|
||||
84
scenes/main/camera_2d.gd
Normal file
84
scenes/main/camera_2d.gd
Normal file
@@ -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
|
||||
1
scenes/main/camera_2d.gd.uid
Normal file
1
scenes/main/camera_2d.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://deol78luglq0w
|
||||
22
scenes/main/main.gd
Normal file
22
scenes/main/main.gd
Normal file
@@ -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)
|
||||
|
||||
1
scenes/main/main.gd.uid
Normal file
1
scenes/main/main.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bb6w1hp1i6k6t
|
||||
143
scenes/main/main.tscn
Normal file
143
scenes/main/main.tscn
Normal file
@@ -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"]
|
||||
13
scripts/Data.cs
Normal file
13
scripts/Data.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
1
scripts/Data.cs.uid
Normal file
1
scripts/Data.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://ucbh1i3pk1qy
|
||||
5
utility/CellData.gd
Normal file
5
utility/CellData.gd
Normal file
@@ -0,0 +1,5 @@
|
||||
class_name CellData
|
||||
extends Resource
|
||||
|
||||
@export var name: String
|
||||
@export var texture: Texture
|
||||
1
utility/CellData.gd.uid
Normal file
1
utility/CellData.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://s2rldju52u45
|
||||
6
utility/EntityData.gd
Normal file
6
utility/EntityData.gd
Normal file
@@ -0,0 +1,6 @@
|
||||
class_name EntityData
|
||||
extends Resource
|
||||
|
||||
@export var name: String
|
||||
@export var canFly: bool
|
||||
@export var canSpawnThings: bool
|
||||
1
utility/EntityData.gd.uid
Normal file
1
utility/EntityData.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://v6ittu7sc334
|
||||
Reference in New Issue
Block a user