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
This commit is contained in:
13
.idea/.idea.Ecosystem/.idea/.gitignore
generated
vendored
Normal file
13
.idea/.idea.Ecosystem/.idea/.gitignore
generated
vendored
Normal file
@@ -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
|
||||||
1
.idea/.idea.Ecosystem/.idea/.name
generated
Normal file
1
.idea/.idea.Ecosystem/.idea/.name
generated
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Ecosystem
|
||||||
4
.idea/.idea.Ecosystem/.idea/encodings.xml
generated
Normal file
4
.idea/.idea.Ecosystem/.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||||
|
</project>
|
||||||
8
.idea/.idea.Ecosystem/.idea/indexLayout.xml
generated
Normal file
8
.idea/.idea.Ecosystem/.idea/indexLayout.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="UserContentModel">
|
||||||
|
<attachedFolders />
|
||||||
|
<explicitIncludes />
|
||||||
|
<explicitExcludes />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
10
.idea/.idea.Ecosystem/.idea/libraries/GdSdk_Master.xml
generated
Normal file
10
.idea/.idea.Ecosystem/.idea/libraries/GdSdk_Master.xml
generated
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<component name="libraryTable">
|
||||||
|
<library name="GdSdk Master" type="GdScript">
|
||||||
|
<properties path="$USER_HOME$/.cache/JetBrains/Rider2025.1/projects/.idea.ecosystem.daf914ba/sdk/GdSdk Master" version="Master" date="2024-06-01T15:14:16.000+02:00" />
|
||||||
|
<CLASSES />
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES>
|
||||||
|
<root url="file://$USER_HOME$/.cache/JetBrains/Rider2025.1/projects/.idea.ecosystem.daf914ba/sdk/GdSdk Master" />
|
||||||
|
</SOURCES>
|
||||||
|
</library>
|
||||||
|
</component>
|
||||||
6
.idea/.idea.Ecosystem/.idea/vcs.xml
generated
Normal file
6
.idea/.idea.Ecosystem/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
Ecosystem.csproj
Normal file
6
Ecosystem.csproj
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<Project Sdk="Godot.NET.Sdk/4.4.1">
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
19
Ecosystem.sln
Normal file
19
Ecosystem.sln
Normal file
@@ -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
|
||||||
3
Ecosystem.sln.DotSettings.user
Normal file
3
Ecosystem.sln.DotSettings.user
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFastNoiseLite_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F20664ebdff579f3f2fbcaff2ccfdb1e5e6a15c79cb5d66fda913ce0ca12_003FFastNoiseLite_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMathf_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F69e3acf0074a4ef8afaea275d4055b96522800_003F52_003F4ffdd606_003FMathf_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
||||||
BIN
art/mobs/fly/bumblebee.png
Normal file
BIN
art/mobs/fly/bumblebee.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 214 B |
34
art/mobs/fly/bumblebee.png.import
Normal file
34
art/mobs/fly/bumblebee.png.import
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://cj5do47pclcnj"
|
||||||
|
path="res://.godot/imported/bumblebee.png-7ceadf65f22abcda51d8a6b48eac50dd.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://art/mobs/fly/bumblebee.png"
|
||||||
|
dest_files=["res://.godot/imported/bumblebee.png-7ceadf65f22abcda51d8a6b48eac50dd.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
|
||||||
BIN
art/spawner_fallback.png
Normal file
BIN
art/spawner_fallback.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 161 B |
34
art/spawner_fallback.png.import
Normal file
34
art/spawner_fallback.png.import
Normal file
@@ -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
|
||||||
@@ -11,9 +11,55 @@ config_version=5
|
|||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="Ecosystem"
|
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"
|
config/icon="res://art/icon.svg"
|
||||||
|
|
||||||
|
[display]
|
||||||
|
|
||||||
|
window/size/viewport_width=800
|
||||||
|
window/size/viewport_height=600
|
||||||
|
|
||||||
[dotnet]
|
[dotnet]
|
||||||
|
|
||||||
project/assembly_name="Ecosystem"
|
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
|
||||||
|
|||||||
76
scenes/Camera2d.cs
Normal file
76
scenes/Camera2d.cs
Normal file
@@ -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;
|
||||||
|
}
|
||||||
1
scenes/Camera2d.cs.uid
Normal file
1
scenes/Camera2d.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://b3obsoy04p8gl
|
||||||
17
scenes/Main.cs
Normal file
17
scenes/Main.cs
Normal file
@@ -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>("Camera2D");
|
||||||
|
camera.Position = new Vector2(screenSize.X / 2, screenSize.Y / 2);
|
||||||
|
|
||||||
|
var spawner = GetNode("World/Spawner");
|
||||||
|
|
||||||
|
var flyPosition = camera.Position;
|
||||||
|
// spawner.spawn_fly(flyPosition);
|
||||||
|
}
|
||||||
|
}
|
||||||
1
scenes/Main.cs.uid
Normal file
1
scenes/Main.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://dte8xibis5wf7
|
||||||
41
scenes/camera_2d.gd
Normal file
41
scenes/camera_2d.gd
Normal file
@@ -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))
|
||||||
1
scenes/camera_2d.gd.uid
Normal file
1
scenes/camera_2d.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://deol78luglq0w
|
||||||
103
scenes/entities/BaseEntity.cs
Normal file
103
scenes/entities/BaseEntity.cs
Normal file
@@ -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>("Sprite2D");
|
||||||
|
collisionShape = GetNode<CollisionShape2D>("CollisionShape2D");
|
||||||
|
animationPlayer = sprite.GetNode<AnimationPlayer>("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<Sprite2D>("SelectedSprite2D").Visible = true;
|
||||||
|
EmitSignalEntitySelected();
|
||||||
|
|
||||||
|
ShowInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void entityDeselected()
|
||||||
|
{
|
||||||
|
selected = false;
|
||||||
|
GD.Print("Unselected");
|
||||||
|
GetNode<Sprite2D>("SelectedSprite2D").Visible = false;
|
||||||
|
|
||||||
|
EmitSignalEntityDeselected();
|
||||||
|
|
||||||
|
HideInfo();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void ShowInfo()
|
||||||
|
{
|
||||||
|
MarginContainer marginContainer = GetNode<MarginContainer>("MarginContainer");
|
||||||
|
Label nameLabel = GetNode<Label>("MarginContainer/VBoxContainer/Label");
|
||||||
|
Label positionLabel = GetNode<Label>("MarginContainer/VBoxContainer/Label2");
|
||||||
|
|
||||||
|
nameLabel.Text = $"Name: {Name}";
|
||||||
|
positionLabel.Text = $"Position: {Position}";
|
||||||
|
|
||||||
|
marginContainer.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void HideInfo()
|
||||||
|
{
|
||||||
|
MarginContainer marginContainer = GetNode<MarginContainer>("MarginContainer");
|
||||||
|
marginContainer.Hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
// public override void _MouseEnter()
|
||||||
|
// {
|
||||||
|
// GD.Print("MouseEnter");
|
||||||
|
//
|
||||||
|
// if (Input.IsMouseButtonPressed(MouseButton.Left))
|
||||||
|
// {
|
||||||
|
// GD.Print("Selected");
|
||||||
|
// selected = true;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
public virtual void Create()
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
1
scenes/entities/BaseEntity.cs.uid
Normal file
1
scenes/entities/BaseEntity.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://b3o37f05w3fva
|
||||||
51
scenes/entities/BaseEntity.tscn
Normal file
51
scenes/entities/BaseEntity.tscn
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
[gd_scene load_steps=6 format=3 uid="uid://b0q03xfp1iy6t"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://b3o37f05w3fva" path="res://scenes/entities/BaseEntity.cs" id="1_jutb3"]
|
||||||
|
|
||||||
|
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_jutb3"]
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_scwlb"]
|
||||||
|
size = Vector2(2, 2)
|
||||||
|
|
||||||
|
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_o625d"]
|
||||||
|
|
||||||
|
[sub_resource type="Theme" id="Theme_jutb3"]
|
||||||
|
|
||||||
|
[node name="BaseEntity" type="Area2D"]
|
||||||
|
script = ExtResource("1_jutb3")
|
||||||
|
|
||||||
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
|
texture = SubResource("PlaceholderTexture2D_jutb3")
|
||||||
|
|
||||||
|
[node name="AnimationPlayer" type="AnimationPlayer" parent="Sprite2D"]
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
shape = SubResource("RectangleShape2D_scwlb")
|
||||||
|
|
||||||
|
[node name="SelectedSprite2D" type="Sprite2D" parent="."]
|
||||||
|
visible = false
|
||||||
|
scale = Vector2(5, 5)
|
||||||
|
texture = SubResource("PlaceholderTexture2D_o625d")
|
||||||
|
|
||||||
|
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||||
|
visible = false
|
||||||
|
anchors_preset = 12
|
||||||
|
anchor_top = 1.0
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
offset_top = -23.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 0
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
theme = SubResource("Theme_jutb3")
|
||||||
|
|
||||||
|
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Name"
|
||||||
|
|
||||||
|
[node name="Label2" type="Label" parent="MarginContainer/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Type"
|
||||||
16
scenes/entities/bumblebee/Bumblebee.cs
Normal file
16
scenes/entities/bumblebee/Bumblebee.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using Godot;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
public partial class Bumblebee : BaseEntity
|
||||||
|
{
|
||||||
|
private FastNoiseLite fastNoise = new FastNoiseLite();
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
base._Ready();
|
||||||
|
|
||||||
|
fastNoise.SetSeed(GD.RandRange(int.MinValue, int.MaxValue));
|
||||||
|
|
||||||
|
animationPlayer.Play("move");
|
||||||
|
}
|
||||||
|
}
|
||||||
1
scenes/entities/bumblebee/Bumblebee.cs.uid
Normal file
1
scenes/entities/bumblebee/Bumblebee.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://svy5ypjbf0gl
|
||||||
61
scenes/entities/bumblebee/bumblebee.tscn
Normal file
61
scenes/entities/bumblebee/bumblebee.tscn
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
[gd_scene load_steps=8 format=3 uid="uid://b43wgesnaq4eg"]
|
||||||
|
|
||||||
|
[ext_resource type="PackedScene" uid="uid://b0q03xfp1iy6t" path="res://scenes/entities/BaseEntity.tscn" id="1_jg071"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://cj5do47pclcnj" path="res://art/mobs/fly/bumblebee.png" id="2_opprm"]
|
||||||
|
[ext_resource type="Script" uid="uid://svy5ypjbf0gl" path="res://scenes/entities/bumblebee/Bumblebee.cs" id="2_wfrvd"]
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id="Animation_y1hpr"]
|
||||||
|
length = 0.001
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/path = NodePath(".:frame")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PackedFloat32Array(0),
|
||||||
|
"transitions": PackedFloat32Array(1),
|
||||||
|
"update": 1,
|
||||||
|
"values": [0]
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id="Animation_wfrvd"]
|
||||||
|
resource_name = "move"
|
||||||
|
length = 0.15
|
||||||
|
loop_mode = 1
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/path = NodePath(".:frame")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PackedFloat32Array(0, 0.0692609),
|
||||||
|
"transitions": PackedFloat32Array(1, 1),
|
||||||
|
"update": 1,
|
||||||
|
"values": [0, 1]
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="AnimationLibrary" id="AnimationLibrary_1wlul"]
|
||||||
|
_data = {
|
||||||
|
&"RESET": SubResource("Animation_y1hpr"),
|
||||||
|
&"move": SubResource("Animation_wfrvd")
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_wfrvd"]
|
||||||
|
radius = 4.0
|
||||||
|
|
||||||
|
[node name="Bumblebee" instance=ExtResource("1_jg071")]
|
||||||
|
script = ExtResource("2_wfrvd")
|
||||||
|
|
||||||
|
[node name="Sprite2D" parent="." index="0"]
|
||||||
|
texture = ExtResource("2_opprm")
|
||||||
|
hframes = 2
|
||||||
|
|
||||||
|
[node name="AnimationPlayer" parent="Sprite2D" index="0"]
|
||||||
|
libraries = {
|
||||||
|
&"": SubResource("AnimationLibrary_1wlul")
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" parent="." index="1"]
|
||||||
|
shape = SubResource("CircleShape2D_wfrvd")
|
||||||
64
scenes/entities/fly/Fly.cs
Normal file
64
scenes/entities/fly/Fly.cs
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
using Godot;
|
||||||
|
using System;
|
||||||
|
using Math = Ecosystem.utility.Math;
|
||||||
|
|
||||||
|
public partial class Fly : BaseEntity
|
||||||
|
{
|
||||||
|
[Export] public float _tx = 0;
|
||||||
|
[Export] public float _ty = 10000f;
|
||||||
|
[Export] public float StepSizeX = .01f;
|
||||||
|
[Export] public float StepSizeY = .1f;
|
||||||
|
|
||||||
|
// private Perlin perlin = new Perlin();
|
||||||
|
|
||||||
|
private FastNoiseLite noise = new FastNoiseLite();
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
base._Ready();
|
||||||
|
|
||||||
|
noise.SetSeed(GD.RandRange(int.MinValue, int.MaxValue));
|
||||||
|
|
||||||
|
// Position = ScreenSize / 2;
|
||||||
|
animationPlayer.Play("fly");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateRandom()
|
||||||
|
{
|
||||||
|
float randomTX = GD.Randf() % 10000;
|
||||||
|
float randomTY = GD.Randf() % 10000;
|
||||||
|
float randomStepSizeX = GD.Randf() % .1f;
|
||||||
|
float randomStepSizeY = GD.Randf() % .1f;
|
||||||
|
|
||||||
|
_tx = randomTX;
|
||||||
|
_ty = randomTY;
|
||||||
|
StepSizeX = randomStepSizeX;
|
||||||
|
StepSizeY = randomStepSizeY;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void step()
|
||||||
|
{
|
||||||
|
// double xNoise = perlin.Noise(_tx);
|
||||||
|
// double yNoise = perlin.Noise(_ty);
|
||||||
|
//
|
||||||
|
|
||||||
|
var xNoise = noise.GetNoise1D(_tx);
|
||||||
|
var yNoise = noise.GetNoise1D(_ty);
|
||||||
|
// var noiseVal = noise.GetNoise2D(_tx, _ty);
|
||||||
|
|
||||||
|
float x = Math.Map(xNoise, 0, 1, 0, ScreenSize.X);
|
||||||
|
float y = Math.Map(yNoise, 0, 1, 0, ScreenSize.Y);
|
||||||
|
|
||||||
|
Position = new Vector2(
|
||||||
|
x: Mathf.Clamp(x, 0, ScreenSize.X),
|
||||||
|
y: Mathf.Clamp(y, 0, ScreenSize.Y));
|
||||||
|
|
||||||
|
_tx += StepSizeX;
|
||||||
|
_ty += StepSizeY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _Process(double delta)
|
||||||
|
{
|
||||||
|
step();
|
||||||
|
}
|
||||||
|
}
|
||||||
1
scenes/entities/fly/Fly.cs.uid
Normal file
1
scenes/entities/fly/Fly.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://cjf04oa55b5sb
|
||||||
67
scenes/entities/fly/fly.tscn
Normal file
67
scenes/entities/fly/fly.tscn
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
[gd_scene load_steps=8 format=3 uid="uid://imihi2lpdd0r"]
|
||||||
|
|
||||||
|
[ext_resource type="PackedScene" uid="uid://b0q03xfp1iy6t" path="res://scenes/entities/BaseEntity.tscn" id="1_dir30"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://bcb027pj21is2" path="res://art/mobs/fly/fly_spritesheet.png" id="2_vd504"]
|
||||||
|
[ext_resource type="Script" uid="uid://cjf04oa55b5sb" path="res://scenes/entities/fly/Fly.cs" id="2_wo7w7"]
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id="Animation_k060o"]
|
||||||
|
length = 0.001
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/path = NodePath(".:frame")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PackedFloat32Array(0),
|
||||||
|
"transitions": PackedFloat32Array(1),
|
||||||
|
"update": 1,
|
||||||
|
"values": [0]
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id="Animation_wo7w7"]
|
||||||
|
resource_name = "fly"
|
||||||
|
length = 0.0593
|
||||||
|
loop_mode = 1
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/path = NodePath(".:frame")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PackedFloat32Array(0, 0.0333333),
|
||||||
|
"transitions": PackedFloat32Array(1, 1),
|
||||||
|
"update": 1,
|
||||||
|
"values": [0, 1]
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="AnimationLibrary" id="AnimationLibrary_88wi0"]
|
||||||
|
_data = {
|
||||||
|
&"RESET": SubResource("Animation_k060o"),
|
||||||
|
&"fly": SubResource("Animation_wo7w7")
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_8dfjp"]
|
||||||
|
radius = 5.0
|
||||||
|
height = 10.0
|
||||||
|
|
||||||
|
[node name="Fly" instance=ExtResource("1_dir30")]
|
||||||
|
script = ExtResource("2_wo7w7")
|
||||||
|
_tx = 0.0
|
||||||
|
_ty = 10000.0
|
||||||
|
StepSizeX = 0.01
|
||||||
|
StepSizeY = 0.1
|
||||||
|
|
||||||
|
[node name="Sprite2D" parent="." index="0"]
|
||||||
|
texture_filter = 1
|
||||||
|
texture = ExtResource("2_vd504")
|
||||||
|
hframes = 2
|
||||||
|
|
||||||
|
[node name="AnimationPlayer" parent="Sprite2D" index="0"]
|
||||||
|
libraries = {
|
||||||
|
&"": SubResource("AnimationLibrary_88wi0")
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" parent="." index="1"]
|
||||||
|
shape = SubResource("CapsuleShape2D_8dfjp")
|
||||||
21
scenes/main.gd
Normal file
21
scenes/main.gd
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
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.gd.uid
Normal file
1
scenes/main.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://bb6w1hp1i6k6t
|
||||||
121
scenes/main.tscn
Normal file
121
scenes/main.tscn
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
[gd_scene load_steps=6 format=3 uid="uid://bkw0abirq18mt"]
|
||||||
|
|
||||||
|
[ext_resource type="PackedScene" uid="uid://brbhyuelsuxyx" path="res://scenes/world/world.tscn" id="1_o5qli"]
|
||||||
|
[ext_resource type="Script" uid="uid://bb6w1hp1i6k6t" path="res://scenes/main.gd" id="1_sugp2"]
|
||||||
|
[ext_resource type="Script" uid="uid://deol78luglq0w" path="res://scenes/camera_2d.gd" id="2_0wfyh"]
|
||||||
|
[ext_resource type="Script" uid="uid://8vkyddmxqfaf" path="res://scenes/menu_bar.gd" id="4_tbgi4"]
|
||||||
|
[ext_resource type="Script" uid="uid://cmoqidhmxlccq" path="res://scenes/options_menu.gd" id="5_tefeu"]
|
||||||
|
|
||||||
|
[node name="Main" type="Node"]
|
||||||
|
script = ExtResource("1_sugp2")
|
||||||
|
|
||||||
|
[node name="World" parent="." instance=ExtResource("1_o5qli")]
|
||||||
|
|
||||||
|
[node name="Spawner" parent="World" index="1"]
|
||||||
|
position = Vector2(500, 500)
|
||||||
|
|
||||||
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
|
drag_left_margin = 0.5
|
||||||
|
drag_top_margin = 0.5
|
||||||
|
drag_right_margin = 0.5
|
||||||
|
drag_bottom_margin = 0.5
|
||||||
|
editor_draw_limits = true
|
||||||
|
editor_draw_drag_margin = true
|
||||||
|
script = ExtResource("2_0wfyh")
|
||||||
|
|
||||||
|
[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)
|
||||||
|
item_count = 2
|
||||||
|
item_0/text = "Fly"
|
||||||
|
item_0/id = 0
|
||||||
|
item_1/text = "Bumblebee"
|
||||||
|
item_1/id = 1
|
||||||
|
|
||||||
|
[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="MarginContainer" type="MarginContainer" parent="HUD"]
|
||||||
|
visible = false
|
||||||
|
anchors_preset = 12
|
||||||
|
anchor_top = 1.0
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 0
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="HUD/MarginContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Name:"
|
||||||
|
|
||||||
|
[node name="Label2" type="Label" parent="HUD/MarginContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Type"
|
||||||
|
|
||||||
|
[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"]
|
||||||
|
|
||||||
|
[editable path="World"]
|
||||||
20
scenes/menu_bar.gd
Normal file
20
scenes/menu_bar.gd
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
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(position):
|
||||||
|
var camera_menu = $Options/Camera
|
||||||
|
camera_menu.position = position
|
||||||
|
camera_menu.show()
|
||||||
|
|
||||||
|
func options_world_pressed(position):
|
||||||
|
var world_menu = $Options/World
|
||||||
|
world_menu.position = position
|
||||||
|
world_menu.show()
|
||||||
1
scenes/menu_bar.gd.uid
Normal file
1
scenes/menu_bar.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://8vkyddmxqfaf
|
||||||
1
scenes/options_menu.gd
Normal file
1
scenes/options_menu.gd
Normal file
@@ -0,0 +1 @@
|
|||||||
|
extends PopupMenu
|
||||||
1
scenes/options_menu.gd.uid
Normal file
1
scenes/options_menu.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://cmoqidhmxlccq
|
||||||
23
scenes/spawner/advanced_spwaner.gd
Normal file
23
scenes/spawner/advanced_spwaner.gd
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
@export var scenes: Array[PackedScene]
|
||||||
|
|
||||||
|
# Spawn the corresponding Entity at position
|
||||||
|
func spawn_entity(index, position):
|
||||||
|
var entity = scenes[index].instantiate()
|
||||||
|
|
||||||
|
if entity is Node2D:
|
||||||
|
entity.position = position
|
||||||
|
|
||||||
|
add_child(entity)
|
||||||
|
|
||||||
|
return entity
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func spawn_fly(position):
|
||||||
|
return spawn_entity(0, position)
|
||||||
|
|
||||||
|
func spawn_bee(position):
|
||||||
|
return spawn_entity(1, position)
|
||||||
1
scenes/spawner/advanced_spwaner.gd.uid
Normal file
1
scenes/spawner/advanced_spwaner.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://dkc807nt6d5jb
|
||||||
17
scenes/spawner/spawner.gd
Normal file
17
scenes/spawner/spawner.gd
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
const FlyScene = preload("res://scenes/entities/fly/fly.tscn")
|
||||||
|
|
||||||
|
func spawn_entity(entity_scene, position):
|
||||||
|
# Instance the scene
|
||||||
|
var entity = entity_scene.instantiate()
|
||||||
|
|
||||||
|
if entity is Node2D:
|
||||||
|
entity.position = position
|
||||||
|
|
||||||
|
add_child(entity)
|
||||||
|
|
||||||
|
return entity
|
||||||
|
|
||||||
|
func spawn_fly(position):
|
||||||
|
return spawn_entity(FlyScene, position)
|
||||||
1
scenes/spawner/spawner.gd.uid
Normal file
1
scenes/spawner/spawner.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://dxflnn04s7out
|
||||||
17
scenes/spawner/spawner.tscn
Normal file
17
scenes/spawner/spawner.tscn
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
[gd_scene load_steps=5 format=3 uid="uid://drwdehf7caidt"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://dkc807nt6d5jb" path="res://scenes/spawner/advanced_spwaner.gd" id="1_eoeca"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://imihi2lpdd0r" path="res://scenes/entities/fly/fly.tscn" id="2_wtxcb"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://b43wgesnaq4eg" path="res://scenes/entities/bumblebee/bumblebee.tscn" id="3_uhn3r"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://b6wg3uyaeju7u" path="res://art/spawner_fallback.png" id="4_byvvi"]
|
||||||
|
|
||||||
|
[node name="Spawner" type="Node2D"]
|
||||||
|
script = ExtResource("1_eoeca")
|
||||||
|
scenes = Array[PackedScene]([ExtResource("2_wtxcb"), ExtResource("3_uhn3r")])
|
||||||
|
|
||||||
|
[node name="Marker2D" type="Marker2D" parent="."]
|
||||||
|
top_level = true
|
||||||
|
gizmo_extents = 324.1
|
||||||
|
|
||||||
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
|
texture = ExtResource("4_byvvi")
|
||||||
91
scenes/world/World.cs
Normal file
91
scenes/world/World.cs
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
using Godot;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
public partial class World : Node2D
|
||||||
|
{
|
||||||
|
public enum GeneratorAlgorithm
|
||||||
|
{
|
||||||
|
RANDOM,
|
||||||
|
FAST_NOISE_LITE
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Vector2I darkGras = new Vector2I(0, 0);
|
||||||
|
Vector2I brightGras = new Vector2I(1, 0);
|
||||||
|
Vector2I flower = new Vector2I(2, 0);
|
||||||
|
TileMapLayer tileMapLayer;
|
||||||
|
|
||||||
|
Vector2 screenSize;
|
||||||
|
float worldWidth;
|
||||||
|
float worldHeight;
|
||||||
|
|
||||||
|
[Export] GeneratorAlgorithm algorithm = GeneratorAlgorithm.RANDOM;
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
screenSize = GetViewportRect().Size;
|
||||||
|
worldWidth = screenSize.X;
|
||||||
|
worldHeight = screenSize.Y;
|
||||||
|
|
||||||
|
tileMapLayer = GetNode<TileMapLayer>("TileMapLayer");
|
||||||
|
|
||||||
|
GD.Randomize();
|
||||||
|
GenerateWorld();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GenerateWorld()
|
||||||
|
{
|
||||||
|
switch (algorithm)
|
||||||
|
{
|
||||||
|
case GeneratorAlgorithm.RANDOM:
|
||||||
|
GenerateWorldRandom();
|
||||||
|
break;
|
||||||
|
case GeneratorAlgorithm.FAST_NOISE_LITE:
|
||||||
|
GenerateWorldSimplexNoise();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GenerateWorldRandom()
|
||||||
|
{
|
||||||
|
for (int y = 0; y < worldHeight; y++)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < worldWidth; x++)
|
||||||
|
{
|
||||||
|
float rnd = GD.Randf();
|
||||||
|
|
||||||
|
if (rnd < .7f)
|
||||||
|
tileMapLayer.SetCell(new Vector2I(x, y), 0, darkGras);
|
||||||
|
else if (rnd < .9f)
|
||||||
|
tileMapLayer.SetCell(new Vector2I(x, y), 0, brightGras);
|
||||||
|
else
|
||||||
|
tileMapLayer.SetCell(new Vector2I(x, y), 0, flower);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GenerateWorldSimplexNoise()
|
||||||
|
{
|
||||||
|
var noise = new FastNoiseLite();
|
||||||
|
|
||||||
|
noise.Seed = GD.RandRange(int.MinValue, int.MaxValue);
|
||||||
|
noise.FractalOctaves = 2;
|
||||||
|
|
||||||
|
for (int y = 0; y < worldHeight; y++)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < worldWidth; x++)
|
||||||
|
{
|
||||||
|
var rnd = noise.GetNoise2D(x, y);
|
||||||
|
|
||||||
|
if (rnd < .3f)
|
||||||
|
tileMapLayer.SetCell(new Vector2I(x, y), 0, darkGras);
|
||||||
|
else if (rnd < .6f)
|
||||||
|
tileMapLayer.SetCell(new Vector2I(x, y), 0, brightGras);
|
||||||
|
else
|
||||||
|
tileMapLayer.SetCell(new Vector2I(x, y), 0, flower);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1
scenes/world/World.cs.uid
Normal file
1
scenes/world/World.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://ctanguxj2uhw7
|
||||||
28
scenes/world/world.tscn
Normal file
28
scenes/world/world.tscn
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
[gd_scene load_steps=6 format=3 uid="uid://brbhyuelsuxyx"]
|
||||||
|
|
||||||
|
[ext_resource type="Texture2D" uid="uid://d0brwy88sjvv1" path="res://art/world/grasv2.png" id="1_f3sb7"]
|
||||||
|
[ext_resource type="Script" uid="uid://ctanguxj2uhw7" path="res://scenes/world/World.cs" id="1_rwgxs"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://drwdehf7caidt" path="res://scenes/spawner/spawner.tscn" id="3_1fp7r"]
|
||||||
|
|
||||||
|
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_0xm2m"]
|
||||||
|
texture = ExtResource("1_f3sb7")
|
||||||
|
texture_region_size = Vector2i(32, 32)
|
||||||
|
0:0/0 = 0
|
||||||
|
1:0/0 = 0
|
||||||
|
2:0/0 = 0
|
||||||
|
|
||||||
|
[sub_resource type="TileSet" id="TileSet_h2yge"]
|
||||||
|
tile_size = Vector2i(32, 32)
|
||||||
|
sources/0 = SubResource("TileSetAtlasSource_0xm2m")
|
||||||
|
|
||||||
|
[node name="World" type="Node2D"]
|
||||||
|
script = ExtResource("1_rwgxs")
|
||||||
|
algorithm = 1
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="TileMapLayer" type="TileMapLayer" parent="."]
|
||||||
|
texture_filter = 1
|
||||||
|
tile_set = SubResource("TileSet_h2yge")
|
||||||
|
|
||||||
|
[node name="Spawner" parent="." instance=ExtResource("3_1fp7r")]
|
||||||
|
position = Vector2(50, 50)
|
||||||
54
utility/Math.cs
Normal file
54
utility/Math.cs
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
namespace Ecosystem.utility;
|
||||||
|
|
||||||
|
public class Math
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Re-maps a number from one range to another.
|
||||||
|
/// For example, calling map(2, 0, 10, 0, 100) returns 20.
|
||||||
|
/// The first three arguments set the original value to 2
|
||||||
|
/// and the original range from 0 to 10. The last two
|
||||||
|
/// arguments set the target range from 0 to 100. 20's
|
||||||
|
/// position in the target range [0, 100] is proportional
|
||||||
|
/// to 2's position in the original range [0, 10].
|
||||||
|
/// The sixth parameter, withinBounds, is optional.
|
||||||
|
/// </summary>
|
||||||
|
/// <example>
|
||||||
|
/// By default, map() can return values outside the
|
||||||
|
/// target range. For example, map(11, 0, 10, 0, 100)
|
||||||
|
/// returns 110. Passing true as the sixth parameter
|
||||||
|
/// constrains the remapped value to the target range.
|
||||||
|
/// For example, map(11, 0, 10, 0, 100, true) returns 100.
|
||||||
|
/// </example>
|
||||||
|
/// <param name="value">The value to be remapped</param>
|
||||||
|
/// <param name="start1">Lower bound of the value's current range</param>
|
||||||
|
/// <param name="stop1">Upper bound of the value's current range</param>
|
||||||
|
/// <param name="start2">Lower bound of the value's target range</param>
|
||||||
|
/// <param name="stop2">Upper bound of the value's target range</param>
|
||||||
|
/// <param name="withinBounds">Constrain the value to the newly mapped value</param>
|
||||||
|
/// <returns>Remapped number</returns>
|
||||||
|
public static float Map(float value, float start1, float stop1, float start2, float stop2, bool withinBounds = false)
|
||||||
|
{
|
||||||
|
var newval = (value - start1) / (stop1 - start1) * (stop2 - start2) + start2;
|
||||||
|
if (!withinBounds) {
|
||||||
|
return newval;
|
||||||
|
}
|
||||||
|
if (start2 < stop2) {
|
||||||
|
return float.Clamp(newval, start2, stop2);
|
||||||
|
} else {
|
||||||
|
return float.Clamp(newval, stop2, start2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double Map(double value, double start1, double stop1, double start2, double stop2, bool withinBounds = false)
|
||||||
|
{
|
||||||
|
var newval = (value - start1) / (stop1 - start1) * (stop2 - start2) + start2;
|
||||||
|
if (!withinBounds) {
|
||||||
|
return newval;
|
||||||
|
}
|
||||||
|
if (start2 < stop2) {
|
||||||
|
return double.Clamp(newval, start2, stop2);
|
||||||
|
} else {
|
||||||
|
return double.Clamp(newval, stop2, start2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1
utility/Math.cs.uid
Normal file
1
utility/Math.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://ca2mnv07no1xb
|
||||||
Reference in New Issue
Block a user