More World Generation, more Camera, other stuff.
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
<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>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGodotObject_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003Fcc6cad1e861deba4a63d78e25e075fee8368b38252a9bb228d46918635_003FGodotObject_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>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AVector2_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F69e3acf0074a4ef8afaea275d4055b96522800_003Ff0_003F33983929_003FVector2_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AVisualShaderNodeClamp_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F3f91a218fc812c8c4610999525be9f3317f28063e9cf6f80589bc68e3b7364f0_003FVisualShaderNodeClamp_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://b3obsoy04p8gl
|
||||
@@ -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>("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 +0,0 @@
|
||||
uid://dte8xibis5wf7
|
||||
@@ -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))
|
||||
@@ -1 +0,0 @@
|
||||
uid://deol78luglq0w
|
||||
@@ -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>("Sprite2D");
|
||||
collisionShape = GetNode<CollisionShape2D>("CollisionShape2D");
|
||||
animationPlayer = sprite.GetNode<AnimationPlayer>("AnimationPlayer");
|
||||
|
||||
positionLabel = GetNode<Label>("MarginContainer/VBoxContainer/Label2");
|
||||
}
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
@@ -45,6 +52,12 @@ public partial class BaseEntity : Area2D
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (selected)
|
||||
positionLabel.Text = $"Position: {Position.ToString("F0")}";
|
||||
}
|
||||
|
||||
protected void entitySelected()
|
||||
{
|
||||
selected = true;
|
||||
@@ -71,11 +84,9 @@ public partial class BaseEntity : Area2D
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Bumblebee : BaseEntity
|
||||
public partial class Bumblebee : Ecosystem.scenes.entities.BaseEntity
|
||||
{
|
||||
private FastNoiseLite fastNoise = new FastNoiseLite();
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Math = Ecosystem.utility.Math;
|
||||
|
||||
namespace Ecosystem.scenes.entities.fly;
|
||||
|
||||
public partial class Fly : BaseEntity
|
||||
{
|
||||
[Export] public float _tx = 0;
|
||||
@@ -59,6 +60,7 @@ public partial class Fly : BaseEntity
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
base._Process(delta);
|
||||
step();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
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 +0,0 @@
|
||||
uid://bb6w1hp1i6k6t
|
||||
121
scenes/main.tscn
121
scenes/main.tscn
@@ -1,121 +0,0 @@
|
||||
[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"]
|
||||
33
scenes/main/grid.gd
Normal file
33
scenes/main/grid.gd
Normal file
@@ -0,0 +1,33 @@
|
||||
class_name Grid
|
||||
extends Node2D
|
||||
|
||||
@export var width: int = 12
|
||||
@export var height: int = 12
|
||||
@export var cell_size: int = 128
|
||||
|
||||
@export var show_debug: bool = false
|
||||
|
||||
var grid: Dictionary = {}
|
||||
|
||||
func generateGrid():
|
||||
for x in width:
|
||||
for y in height:
|
||||
grid[Vector2(x,y)] = null
|
||||
if show_debug:
|
||||
var rect = ReferenceRect.new()
|
||||
rect.position = gridToWorld(Vector2(x,y))
|
||||
rect.size = Vector2(cell_size, cell_size)
|
||||
rect.editor_only = false
|
||||
$Debug.add_child(rect)
|
||||
var label = Label.new()
|
||||
label.position = gridToWorld(Vector2(x,y))
|
||||
label.text = str(Vector2(x,y))
|
||||
$Debug.add_child(label)
|
||||
|
||||
|
||||
func gridToWorld(_pos: Vector2) -> Vector2:
|
||||
return _pos * cell_size
|
||||
|
||||
|
||||
func worldToGrid(_pos: Vector2) -> Vector2:
|
||||
return floor(_pos / cell_size)
|
||||
1
scenes/main/grid.gd.uid
Normal file
1
scenes/main/grid.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cqrt5x30j5vm6
|
||||
@@ -1,20 +0,0 @@
|
||||
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 +0,0 @@
|
||||
uid://8vkyddmxqfaf
|
||||
@@ -1 +0,0 @@
|
||||
extends PopupMenu
|
||||
@@ -1 +0,0 @@
|
||||
uid://cmoqidhmxlccq
|
||||
@@ -6,46 +6,64 @@ public partial class World : Node2D
|
||||
public enum GeneratorAlgorithm
|
||||
{
|
||||
RANDOM,
|
||||
FAST_NOISE_LITE
|
||||
FAST_NOISE_LITE,
|
||||
COMPLEX
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
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;
|
||||
|
||||
|
||||
private Timer generationTimeout;
|
||||
|
||||
[Export] GeneratorAlgorithm algorithm = GeneratorAlgorithm.RANDOM;
|
||||
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
screenSize = GetViewportRect().Size;
|
||||
worldWidth = screenSize.X;
|
||||
worldHeight = screenSize.Y;
|
||||
|
||||
|
||||
tileMapLayer = GetNode<TileMapLayer>("TileMapLayer");
|
||||
|
||||
generationTimeout = GetNode<Timer>("GenerationTimeout");
|
||||
|
||||
GD.Randomize();
|
||||
GenerateWorld();
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
GD.Print(algorithm);
|
||||
|
||||
}
|
||||
|
||||
private void GenerateWorld()
|
||||
{
|
||||
switch (algorithm)
|
||||
if (generationTimeout.IsStopped())
|
||||
{
|
||||
case GeneratorAlgorithm.RANDOM:
|
||||
GenerateWorldRandom();
|
||||
break;
|
||||
case GeneratorAlgorithm.FAST_NOISE_LITE:
|
||||
GenerateWorldSimplexNoise();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
switch (algorithm)
|
||||
{
|
||||
case GeneratorAlgorithm.RANDOM:
|
||||
GenerateWorldRandom();
|
||||
break;
|
||||
case GeneratorAlgorithm.FAST_NOISE_LITE:
|
||||
GenerateWorldSimplexNoise();
|
||||
break;
|
||||
case GeneratorAlgorithm.COMPLEX:
|
||||
GenerateWorldComplex();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
generationTimeout.Start();
|
||||
}
|
||||
|
||||
private void GenerateWorldRandom()
|
||||
@@ -55,12 +73,12 @@ public partial class World : Node2D
|
||||
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
|
||||
else
|
||||
tileMapLayer.SetCell(new Vector2I(x, y), 0, flower);
|
||||
}
|
||||
}
|
||||
@@ -72,20 +90,300 @@ public partial class World : Node2D
|
||||
|
||||
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);
|
||||
|
||||
// var xRnd = noise.GetNoise1D(x);
|
||||
// var yRnd = noise.GetNoise1D(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);
|
||||
|
||||
|
||||
// if (yRnd < .3f)
|
||||
// tileMapLayer.SetCell(new Vector2I(x, y), 0, darkGras);
|
||||
// else if (xRnd < .6f)
|
||||
// tileMapLayer.SetCell(new Vector2I(x, y), 0, brightGras);
|
||||
// else
|
||||
// tileMapLayer.SetCell(new Vector2I(x, y), 0, flower);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int _noiseSeed;
|
||||
[Export] public int NoiseSeed
|
||||
{
|
||||
get => _noiseSeed;
|
||||
set
|
||||
{
|
||||
_noiseSeed = value;
|
||||
GenerateWorld();
|
||||
}
|
||||
}
|
||||
|
||||
private FastNoiseLite.NoiseTypeEnum _noiseType;
|
||||
[Export]
|
||||
public FastNoiseLite.NoiseTypeEnum NoiseType
|
||||
{
|
||||
get => _noiseType;
|
||||
set
|
||||
{
|
||||
_noiseType = value;
|
||||
GenerateWorld();
|
||||
}
|
||||
}
|
||||
|
||||
[Export] public float NoiseFrequency
|
||||
{
|
||||
get => noiseFrequency;
|
||||
set
|
||||
{
|
||||
noiseFrequency = value;
|
||||
GenerateWorld();
|
||||
}
|
||||
}
|
||||
|
||||
[Export] public Vector3 NoiseOffset
|
||||
{
|
||||
get => noiseOffset;
|
||||
set
|
||||
{
|
||||
noiseOffset = value;
|
||||
GenerateWorld();
|
||||
}
|
||||
}
|
||||
|
||||
[Export] public FastNoiseLite.FractalTypeEnum NoiseFractalType
|
||||
{
|
||||
get => noiseFractalType;
|
||||
set
|
||||
{
|
||||
noiseFractalType = value;
|
||||
GenerateWorld();
|
||||
}
|
||||
}
|
||||
|
||||
[Export] public int NoiseFractalOctaves
|
||||
{
|
||||
get => noiseFractalOctaves;
|
||||
set
|
||||
{
|
||||
noiseFractalOctaves = value;
|
||||
GenerateWorld();
|
||||
}
|
||||
}
|
||||
|
||||
[Export] public float NoiseFractalLacunarity
|
||||
{
|
||||
get => noiseFractalLacunarity;
|
||||
set
|
||||
{
|
||||
noiseFractalLacunarity = value;
|
||||
GenerateWorld();
|
||||
}
|
||||
}
|
||||
|
||||
[Export] public float NoiseFractalGain
|
||||
{
|
||||
get => noiseFractalGain;
|
||||
set
|
||||
{
|
||||
noiseFractalGain = value;
|
||||
GenerateWorld();
|
||||
}
|
||||
}
|
||||
|
||||
[Export] public float NoiseFractalWeightedStrength
|
||||
{
|
||||
get => noiseFractalWeightedStrength;
|
||||
set
|
||||
{
|
||||
noiseFractalWeightedStrength = value;
|
||||
GenerateWorld();
|
||||
}
|
||||
}
|
||||
|
||||
[Export] public float NoiseFractalPingPongStrength
|
||||
{
|
||||
get => noiseFractalPingPongStrength;
|
||||
set
|
||||
{
|
||||
noiseFractalPingPongStrength = value;
|
||||
GenerateWorld();
|
||||
}
|
||||
}
|
||||
|
||||
[Export] public float NoiseCellularJitter
|
||||
{
|
||||
get => noiseCellularJitter;
|
||||
set
|
||||
{
|
||||
noiseCellularJitter = value;
|
||||
GenerateWorld();
|
||||
}
|
||||
}
|
||||
|
||||
[Export] public FastNoiseLite.CellularReturnTypeEnum NoiseCellularReturnType
|
||||
{
|
||||
get => noiseCellularReturnType;
|
||||
set
|
||||
{
|
||||
noiseCellularReturnType = value;
|
||||
GenerateWorld();
|
||||
}
|
||||
}
|
||||
|
||||
[Export] public bool NoiseDomainWarpEnabled
|
||||
{
|
||||
get => noiseDomainWarpEnabled;
|
||||
set
|
||||
{
|
||||
noiseDomainWarpEnabled = value;
|
||||
GenerateWorld();
|
||||
}
|
||||
}
|
||||
|
||||
[Export] public FastNoiseLite.DomainWarpTypeEnum NoiseDomainWarpType
|
||||
{
|
||||
get => noiseDomainWarpType;
|
||||
set
|
||||
{
|
||||
noiseDomainWarpType = value;
|
||||
GenerateWorld();
|
||||
}
|
||||
}
|
||||
|
||||
[Export] public float NoiseDomainWarpAmplitude
|
||||
{
|
||||
get => noiseDomainWarpAmplitude;
|
||||
set
|
||||
{
|
||||
noiseDomainWarpAmplitude = value;
|
||||
GenerateWorld();
|
||||
}
|
||||
}
|
||||
|
||||
[Export] public float NoiseDomainWarpFrequency
|
||||
{
|
||||
get => noiseDomainWarpFrequency;
|
||||
set
|
||||
{
|
||||
noiseDomainWarpFrequency = value;
|
||||
GenerateWorld();
|
||||
}
|
||||
}
|
||||
|
||||
[Export] public FastNoiseLite.DomainWarpFractalTypeEnum NoiseDomainWarpFractalType
|
||||
{
|
||||
get => noiseDomainWarpFractalType;
|
||||
set
|
||||
{
|
||||
noiseDomainWarpFractalType = value;
|
||||
GenerateWorld();
|
||||
}
|
||||
}
|
||||
|
||||
[Export] public int NoiseDomainWarpFractalOctaves
|
||||
{
|
||||
get => noiseDomainWarpFractalOctaves;
|
||||
set
|
||||
{
|
||||
noiseDomainWarpFractalOctaves = value;
|
||||
GenerateWorld();
|
||||
}
|
||||
}
|
||||
|
||||
[Export] public float NoiseDomainWarpFractalLacunarity
|
||||
{
|
||||
get => noiseDomainWarpFractalLacunarity;
|
||||
set
|
||||
{
|
||||
noiseDomainWarpFractalLacunarity = value;
|
||||
GenerateWorld();
|
||||
}
|
||||
}
|
||||
|
||||
[Export] public float NoiseDomainWarpFractalGain
|
||||
{
|
||||
get => noiseDomainWarpFractalGain;
|
||||
set
|
||||
{
|
||||
noiseDomainWarpFractalGain = value;
|
||||
GenerateWorld();
|
||||
}
|
||||
}
|
||||
|
||||
public float noiseFrequency;
|
||||
public Vector3 noiseOffset;
|
||||
public FastNoiseLite.FractalTypeEnum noiseFractalType;
|
||||
public int noiseFractalOctaves;
|
||||
public float noiseFractalLacunarity;
|
||||
public float noiseFractalGain;
|
||||
public float noiseFractalWeightedStrength;
|
||||
public float noiseFractalPingPongStrength;
|
||||
public float noiseCellularJitter;
|
||||
public FastNoiseLite.CellularReturnTypeEnum noiseCellularReturnType;
|
||||
public bool noiseDomainWarpEnabled;
|
||||
public FastNoiseLite.DomainWarpTypeEnum noiseDomainWarpType;
|
||||
public float noiseDomainWarpAmplitude;
|
||||
public float noiseDomainWarpFrequency;
|
||||
public FastNoiseLite.DomainWarpFractalTypeEnum noiseDomainWarpFractalType;
|
||||
public int noiseDomainWarpFractalOctaves;
|
||||
public float noiseDomainWarpFractalLacunarity;
|
||||
public float noiseDomainWarpFractalGain;
|
||||
|
||||
private void GenerateWorldComplex()
|
||||
{
|
||||
var noise = new FastNoiseLite();
|
||||
if (NoiseSeed == 0)
|
||||
noise.Seed = GD.RandRange(int.MinValue, int.MaxValue);
|
||||
else
|
||||
noise.Seed = NoiseSeed;
|
||||
GD.Print(noise.Seed);
|
||||
|
||||
noise.NoiseType = _noiseType;
|
||||
noise.Frequency = noiseFrequency;
|
||||
noise.Offset = noiseOffset;
|
||||
noise.FractalType = noiseFractalType;
|
||||
noise.FractalOctaves = noiseFractalOctaves;
|
||||
noise.FractalLacunarity = noiseFractalLacunarity;
|
||||
noise.FractalGain = noiseFractalGain;
|
||||
noise.FractalWeightedStrength = noiseFractalWeightedStrength;
|
||||
noise.FractalPingPongStrength = noiseFractalPingPongStrength;
|
||||
noise.CellularJitter = noiseCellularJitter;
|
||||
noise.CellularReturnType = noiseCellularReturnType;
|
||||
noise.DomainWarpEnabled = noiseDomainWarpEnabled;
|
||||
noise.DomainWarpType = noiseDomainWarpType;
|
||||
noise.DomainWarpAmplitude = noiseDomainWarpAmplitude;
|
||||
noise.DomainWarpFrequency = noiseDomainWarpFrequency;
|
||||
noise.DomainWarpFractalType = noiseDomainWarpFractalType;
|
||||
noise.DomainWarpFractalOctaves = noiseDomainWarpFractalOctaves;
|
||||
noise.DomainWarpFractalLacunarity = noiseDomainWarpFractalLacunarity;
|
||||
noise.DomainWarpFractalGain = noiseDomainWarpFractalGain;
|
||||
|
||||
|
||||
|
||||
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
|
||||
else
|
||||
tileMapLayer.SetCell(new Vector2I(x, y), 0, flower);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,3 +26,6 @@ tile_set = SubResource("TileSet_h2yge")
|
||||
|
||||
[node name="Spawner" parent="." instance=ExtResource("3_1fp7r")]
|
||||
position = Vector2(50, 50)
|
||||
|
||||
[node name="GenerationTimeout" type="Timer" parent="."]
|
||||
one_shot = true
|
||||
|
||||
Reference in New Issue
Block a user