Compare commits

...

6 Commits

Author SHA1 Message Date
gdz
ffaee18654 Test for calling method of Node. 2025-08-26 18:22:25 +02:00
gdz
50cea7f096 HUD Rework and integration 2025-08-26 18:21:20 +02:00
gdz
3b254ea1f7 infoPanel integration. 2025-08-26 18:20:11 +02:00
gdz
28ac1753ec Refactor. 2025-08-26 18:17:23 +02:00
gdz
1116487c10 Refactoring of the Class and new generation Algorithm. Grid generation. 2025-08-26 18:15:16 +02:00
gdz
1fae8c07d3 camera movement with WASD. Not working! 2025-08-26 10:38:13 +02:00
14 changed files with 480 additions and 287 deletions

View File

@@ -0,0 +1,9 @@
<component name="libraryTable">
<library name="GdSdk" type="GdScript">
<CLASSES />
<JAVADOC />
<SOURCES>
<root url="file://$APPLICATION_HOME_DIR$/plugins/rider-gdscript/sdk/extracted/4.4.1" />
</SOURCES>
</library>
</component>

View File

@@ -1,10 +0,0 @@
<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>

121
scenes/HUD/hud.tscn Normal file
View File

@@ -0,0 +1,121 @@
[gd_scene load_steps=4 format=3 uid="uid://djgeio24bm6i4"]
[ext_resource type="Script" uid="uid://ce6mehx86c03f" path="res://scenes/main/hud.gd" id="1_jjobl"]
[ext_resource type="Script" uid="uid://8vkyddmxqfaf" path="res://scenes/HUD/menu_bar.gd" id="2_epp0c"]
[ext_resource type="Script" uid="uid://cmoqidhmxlccq" path="res://scenes/HUD/options_menu.gd" id="3_r7rnh"]
[node name="HUD" type="CanvasLayer"]
script = ExtResource("1_jjobl")
[node name="MenuBar" type="MenuBar" parent="."]
anchors_preset = 10
anchor_right = 1.0
grow_horizontal = 2
script = ExtResource("2_epp0c")
[node name="Entity" type="PopupMenu" parent="MenuBar"]
auto_translate_mode = 1
size = Vector2i(109, 100)
[node name="Spawn" type="PopupMenu" parent="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="Options" type="PopupMenu" parent="MenuBar"]
auto_translate_mode = 1
item_count = 2
item_0/text = "Camera"
item_0/id = 0
item_1/text = "World"
item_1/id = 1
script = ExtResource("3_r7rnh")
[node name="Camera" type="PopupMenu" parent="MenuBar/Options"]
auto_translate_mode = 1
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="MenuBar/Options"]
auto_translate_mode = 1
item_count = 1
item_0/text = "Generate"
item_0/id = 0
[node name="Info" type="PopupMenu" parent="MenuBar"]
auto_translate_mode = 1
item_count = 2
item_0/text = "Camera"
item_0/id = 0
item_1/text = "World"
item_1/id = 1
[node name="SpawnMenuButton" type="MenuButton" parent="."]
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="."]
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="."]
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="InformationPanel" type="MarginContainer" parent="."]
anchors_preset = 12
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 0
[node name="VBoxContainer" type="VBoxContainer" parent="InformationPanel"]
layout_mode = 2
[node name="HBoxContainer" type="HBoxContainer" parent="InformationPanel/VBoxContainer"]
layout_mode = 2
[node name="EntityInformationContainer" type="VBoxContainer" parent="InformationPanel/VBoxContainer/HBoxContainer"]
layout_mode = 2
[node name="NameLabel" type="Label" parent="InformationPanel/VBoxContainer"]
layout_mode = 2
[connection signal="index_pressed" from="MenuBar/Options" to="MenuBar" method="options_index_pressed"]

View File

@@ -0,0 +1,29 @@
extends MarginContainer
@onready var NameLabel: Label = $VBoxContainer/NameLabel
func _ready() -> void:
defaultInfoPanel()
ShowInfoPanel()
func BuildInfoPanel(source: Node2D) -> void:
NameLabel.text = source.name
func defaultInfoPanel() -> void:
NameLabel.text = "Nothing to show..."
func worldInfoPanel() -> void:
NameLabel.text = "World"
var sizeLabel: Label = Label.new()
sizeLabel.text = "Viewportsize: {size}".format({"size": get_viewport_rect().size})
$VBoxContainer/HBoxContainer/EntityInformationContainer.add_child(sizeLabel)
func ShowInfoPanel() -> void:
show()
func HideInfoPanel() -> void:
hide()

View File

@@ -0,0 +1 @@
uid://cm0m3up5ufny2

View File

@@ -14,8 +14,22 @@ func options_camera_pressed(target_position):
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()
func info_index_pressed(index):
var infoPanel: Node = get_parent().get_node("InformationPanel")
if index == 0: #Camera
pass
elif index == 1: #World
infoPanel.call("worldInfoPanel")
infoPanel.call("ShowInfoPanel")
elif index == 2: #Close
infoPanel.call("HideInfoPanel")

View File

@@ -4,10 +4,10 @@ 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;
public float zoomMin = 0.1f;
public float zoomMax = 4.0f;
[Export] public float dragSensitivity = 0.35f;
[Export] public float cameraStepSize = 10.0f;
public override void _Input(InputEvent @event)
{
@@ -18,6 +18,27 @@ public partial class GobalCamera : Camera2D
Position -= mouseMotion.Relative * dragSensitivity / Zoom;
}
if (@event is InputEventAction eventAction && eventAction.IsPressed())
{
switch (eventAction.AsText())
{
case "camera_up":
Position -= new Vector2(0, cameraStepSize);
break;
case "camera_down":
Position += new Vector2(0, cameraStepSize);
break;
case "camera_left":
Position -= new Vector2(cameraStepSize, 0);
break;
case "camera_right":
Position += new Vector2(cameraStepSize, 0);
break;
}
GD.Print(eventAction.AsText());
}
if (@event is InputEventMouseButton mouseButton)
{
switch (mouseButton.ButtonIndex)

View File

@@ -13,15 +13,18 @@ public partial class Main : Node
screenSize = GetViewport().GetVisibleRect().Size;
camera = GetNode<Camera2D>("GlobalCamera");
spawner = GetNode("World/Spawner");
GetNode<Node2D>("Grid").Call("generateGrid");
Node2D grid = GetNode<Node2D>("World/Grid");
camera.Position = new Vector2(screenSize.X / 2, screenSize.Y / 2);
var flyPosition = camera.Position;
spawner.Call("spawn_fly", flyPosition);
Node2D fly = (Node2D)spawner.GetChild(0);
GD.Print(grid.Call("worldToGrid", fly.Position));
GetNode<MarginContainer>("HUD").Call("buildInfoPanel", (Node)fly);
GetNode<MarginContainer>("HUD").Call("ShowInfoPanel");
}
}

View File

@@ -3,27 +3,36 @@ extends Node2D
@export var width: int = 12
@export var height: int = 12
@export var cell_size: int = 128
@export var cell_size: Vector2 = Vector2(128, 128)
@export var show_debug: bool = false
@export var show_grid: bool = true
@export var show_label: bool = true
var grid: Dictionary = {}
func generateGrid():
print("Generating Grid")
for x in width:
for y in height:
grid[Vector2(x,y)] = null
if show_debug:
if show_grid:
var rect = ReferenceRect.new()
rect.position = gridToWorld(Vector2(x,y))
rect.size = Vector2(cell_size, cell_size)
rect.size = cell_size
rect.editor_only = false
$Debug.add_child(rect)
# print("Adding Rect ", x, "| ", y)
if show_label:
var label = Label.new()
label.position = gridToWorld(Vector2(x,y))
label.text = str(Vector2(x,y))
$Debug.add_child(label)
print("Grid generation done.")
func _draw() -> void:
if show_debug:
$Debug.show()
func gridToWorld(_pos: Vector2) -> Vector2:
return _pos * cell_size

18
scenes/main/hud.gd Normal file
View File

@@ -0,0 +1,18 @@
extends CanvasLayer
@onready var InfoMenu = $MenuBar/Info
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta: float) -> void:
# pass
func GetMenuPressed(index) -> String:
if index == 0: return "Camera"
elif index == 1: return "World"
else: return ""

1
scenes/main/hud.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://ce6mehx86c03f

View File

@@ -1,34 +1,26 @@
[gd_scene load_steps=8 format=3 uid="uid://bkw0abirq18mt"]
[gd_scene load_steps=7 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="PackedScene" uid="uid://djgeio24bm6i4" path="res://scenes/HUD/hud.tscn" id="4_ow5a4"]
[ext_resource type="Script" uid="uid://cm0m3up5ufny2" path="res://scenes/HUD/information_panel.gd" id="5_hujxm"]
[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)
Algorithm = 2
NoiseType = 3
NoiseSeed = 521632
NoiseFrequency = 0.03
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="Grid" parent="World" index="3"]
show_debug = false
show_grid = false
show_label = false
[node name="GlobalCamera" type="Camera2D" parent="."]
drag_left_margin = 0.5
@@ -36,108 +28,23 @@ drag_top_margin = 0.5
drag_right_margin = 0.5
drag_bottom_margin = 0.5
script = ExtResource("3_ow5a4")
cameraStepSize = 200.0
[node name="HUD" type="CanvasLayer" parent="."]
[node name="HUD" parent="." instance=ExtResource("4_ow5a4")]
[node name="MenuBar" type="MenuBar" parent="HUD"]
anchors_preset = 10
anchor_right = 1.0
grow_horizontal = 2
script = ExtResource("4_tbgi4")
[node name="Info" parent="HUD/MenuBar" index="3"]
item_count = 3
item_2/text = "Close"
item_2/id = 2
[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="InformationPanel" parent="HUD" index="4"]
custom_minimum_size = Vector2(100, 0)
script = ExtResource("5_hujxm")
[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"]
[connection signal="index_pressed" from="HUD/MenuBar/Info" to="HUD/MenuBar" method="info_index_pressed"]
[editable path="World"]
[editable path="HUD"]

View File

@@ -1,85 +1,130 @@
using Godot;
using System;
using Godot.Collections;
public partial class World : Node2D
{
public enum GeneratorAlgorithm
{
RANDOM,
FAST_NOISE_LITE,
COMPLEX
Random,
Simple,
Complex
}
Vector2I darkGras = new Vector2I(0, 0);
Vector2I brightGras = new Vector2I(1, 0);
Vector2I flower = new Vector2I(2, 0);
TileMapLayer tileMapLayer;
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;
Vector2 _screenSize;
float _worldWidth;
float _worldHeight;
private Vector2I _tileSize;
private Timer _generationTimeout;
private Timer generationTimeout;
[Export] public GeneratorAlgorithm Algorithm = GeneratorAlgorithm.Random;
[Export] GeneratorAlgorithm algorithm = GeneratorAlgorithm.RANDOM;
private void GenerateGrid()
{
Dictionary grid = new Dictionary();
for (int x = 0; x < _worldHeight; x++)
{
for (int y = 0; y < _worldWidth; y++)
{
// grid[new Vector2(x, y)] = null;
}
}
}
private Vector2 gridToWorld(Vector2 pos) => pos * _tileSize.X;
// private Vector2 worldToGrid(Vector2 pos) => Godot.Mathf.Floor(pos / _tileSize.X);
public override void _Ready()
{
screenSize = GetViewportRect().Size;
worldWidth = screenSize.X;
worldHeight = screenSize.Y;
GD.Print("World Node Ready");
tileMapLayer = GetNode<TileMapLayer>("TileMapLayer");
GD.Print("Getting Screen Size");
_screenSize = GetViewportRect().Size;
GD.Print("Setting World Size");
_worldWidth = _screenSize.X;
_worldHeight = _screenSize.Y;
generationTimeout = GetNode<Timer>("GenerationTimeout");
GD.Print("Getting Tilemap Layer and Setting Tile Size");
_tileMapLayer = GetNode<TileMapLayer>("TileMapLayer");
_tileSize = _tileMapLayer.TileSet.TileSize;
GD.Print("Getting Timer");
_generationTimeout = GetNode<Timer>("GenerationTimeout");
// Grid generation
GD.Print("Setting Grid Properties");
Node2D grid = GetNode<Node2D>("Grid");
grid.Set("width", _worldHeight / _tileSize.X);
grid.Set("height", _worldHeight / _tileSize.Y);
grid.Set("cell_size", _tileSize);
GD.Print("Calling generateGrid");
grid.Call("generateGrid");
GD.Print("Randomizing Seed");
GD.Randomize();
GenerateWorld();
// World generation
GD.Print("Generating World");
if (_generationTimeout.IsNodeReady())
GenerateWorld();
}
public override void _Process(double delta)
{
GD.Print(algorithm);
}
// public override void _Process(double delta)
// {
// GD.Print(algorithm);
//
// }
private void GenerateWorld()
{
if (generationTimeout.IsStopped())
try
{
switch (algorithm)
if (_generationTimeout.IsStopped())
{
case GeneratorAlgorithm.RANDOM:
GenerateWorldRandom();
break;
case GeneratorAlgorithm.FAST_NOISE_LITE:
GenerateWorldSimplexNoise();
break;
case GeneratorAlgorithm.COMPLEX:
GenerateWorldComplex();
break;
default:
break;
switch (Algorithm)
{
case GeneratorAlgorithm.Random:
GenerateWorldRandom();
break;
case GeneratorAlgorithm.Simple:
GenerateWorldSimplexNoise();
break;
case GeneratorAlgorithm.Complex:
GenerateWorldComplex();
break;
default:
break;
}
}
_generationTimeout.Start();
}
catch (Exception e)
{
GD.PrintErr(e);
}
generationTimeout.Start();
}
private void GenerateWorldRandom()
{
for (int y = 0; y < worldHeight; y++)
for (int y = 0; y < _worldHeight; y++)
{
for (int x = 0; x < worldWidth; x++)
for (int x = 0; x < _worldWidth; x++)
{
float rnd = GD.Randf();
if (rnd < .7f)
tileMapLayer.SetCell(new Vector2I(x, y), 0, darkGras);
_tileMapLayer.SetCell(new Vector2I(x, y), 0, _darkGras);
else if (rnd < .9f)
tileMapLayer.SetCell(new Vector2I(x, y), 0, brightGras);
_tileMapLayer.SetCell(new Vector2I(x, y), 0, _brightGras);
else
tileMapLayer.SetCell(new Vector2I(x, y), 0, flower);
_tileMapLayer.SetCell(new Vector2I(x, y), 0, _flower);
}
}
}
@@ -91,9 +136,9 @@ 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 y = 0; y < _worldHeight; y++)
{
for (int x = 0; x < worldWidth; x++)
for (int x = 0; x < _worldWidth; x++)
{
var rnd = noise.GetNoise2D(x, y);
@@ -101,11 +146,11 @@ public partial class World : Node2D
// var yRnd = noise.GetNoise1D(y);
if (rnd < .3f)
tileMapLayer.SetCell(new Vector2I(x, y), 0, darkGras);
_tileMapLayer.SetCell(new Vector2I(x, y), 0, _darkGras);
else if (rnd < .6f)
tileMapLayer.SetCell(new Vector2I(x, y), 0, brightGras);
_tileMapLayer.SetCell(new Vector2I(x, y), 0, _brightGras);
else
tileMapLayer.SetCell(new Vector2I(x, y), 0, flower);
_tileMapLayer.SetCell(new Vector2I(x, y), 0, _flower);
// if (yRnd < .3f)
@@ -118,18 +163,8 @@ public partial class World : Node2D
}
}
private int _noiseSeed;
[Export] public int NoiseSeed
{
get => _noiseSeed;
set
{
_noiseSeed = value;
GenerateWorld();
}
}
private FastNoiseLite.NoiseTypeEnum _noiseType;
[ExportGroup("General")]
[Export]
public FastNoiseLite.NoiseTypeEnum NoiseType
{
@@ -140,205 +175,235 @@ public partial class World : Node2D
GenerateWorld();
}
}
[Export] public float NoiseFrequency
[Export] public int NoiseSeed
{
get => noiseFrequency;
get => _noiseSeed;
set
{
noiseFrequency = value;
_noiseSeed = value;
GenerateWorld();
}
}
[Export] public Vector3 NoiseOffset
{
get => noiseOffset;
get => _noiseOffset;
set
{
noiseOffset = value;
_noiseOffset = value;
GenerateWorld();
}
}
[ExportGroup("Perlin and Simplex")]
[Export] public float NoiseFrequency
{
get => _noiseFrequency;
set
{
_noiseFrequency = value;
GenerateWorld();
}
}
[Export] public FastNoiseLite.FractalTypeEnum NoiseFractalType
{
get => noiseFractalType;
get => _noiseFractalType;
set
{
noiseFractalType = value;
_noiseFractalType = value;
GenerateWorld();
}
}
[Export] public int NoiseFractalOctaves
{
get => noiseFractalOctaves;
get => _noiseFractalOctaves;
set
{
noiseFractalOctaves = value;
_noiseFractalOctaves = value;
GenerateWorld();
}
}
[Export] public float NoiseFractalLacunarity
{
get => noiseFractalLacunarity;
get => _noiseFractalLacunarity;
set
{
noiseFractalLacunarity = value;
_noiseFractalLacunarity = value;
GenerateWorld();
}
}
[Export] public float NoiseFractalGain
{
get => noiseFractalGain;
get => _noiseFractalGain;
set
{
noiseFractalGain = value;
_noiseFractalGain = value;
GenerateWorld();
}
}
[Export] public float NoiseFractalWeightedStrength
{
get => noiseFractalWeightedStrength;
get => _noiseFractalWeightedStrength;
set
{
noiseFractalWeightedStrength = value;
_noiseFractalWeightedStrength = value;
GenerateWorld();
}
}
[Export] public float NoiseFractalPingPongStrength
{
get => noiseFractalPingPongStrength;
get => _noiseFractalPingPongStrength;
set
{
noiseFractalPingPongStrength = value;
_noiseFractalPingPongStrength = value;
GenerateWorld();
}
}
[ExportGroup("Cellular")]
[Export] public float NoiseCellularJitter
{
get => noiseCellularJitter;
get => _noiseCellularJitter;
set
{
noiseCellularJitter = value;
_noiseCellularJitter = value;
GenerateWorld();
}
}
[Export]
public FastNoiseLite.CellularDistanceFunctionEnum NoiseCellularDistanceFunction
{
get => _noiseCellularDistanceFunction;
set
{
_noiseCellularDistanceFunction = value;
GenerateWorld();
}
}
[Export] public FastNoiseLite.CellularReturnTypeEnum NoiseCellularReturnType
{
get => noiseCellularReturnType;
get => _noiseCellularReturnType;
set
{
noiseCellularReturnType = value;
_noiseCellularReturnType = value;
GenerateWorld();
}
}
[ExportGroup("Domain Warp")]
[Export] public bool NoiseDomainWarpEnabled
{
get => noiseDomainWarpEnabled;
get => _noiseDomainWarpEnabled;
set
{
noiseDomainWarpEnabled = value;
_noiseDomainWarpEnabled = value;
GenerateWorld();
}
}
[Export] public FastNoiseLite.DomainWarpTypeEnum NoiseDomainWarpType
{
get => noiseDomainWarpType;
get => _noiseDomainWarpType;
set
{
noiseDomainWarpType = value;
_noiseDomainWarpType = value;
GenerateWorld();
}
}
[Export] public float NoiseDomainWarpAmplitude
{
get => noiseDomainWarpAmplitude;
get => _noiseDomainWarpAmplitude;
set
{
noiseDomainWarpAmplitude = value;
_noiseDomainWarpAmplitude = value;
GenerateWorld();
}
}
[Export] public float NoiseDomainWarpFrequency
{
get => noiseDomainWarpFrequency;
get => _noiseDomainWarpFrequency;
set
{
noiseDomainWarpFrequency = value;
_noiseDomainWarpFrequency = value;
GenerateWorld();
}
}
[Export] public FastNoiseLite.DomainWarpFractalTypeEnum NoiseDomainWarpFractalType
{
get => noiseDomainWarpFractalType;
get => _noiseDomainWarpFractalType;
set
{
noiseDomainWarpFractalType = value;
_noiseDomainWarpFractalType = value;
GenerateWorld();
}
}
[Export] public int NoiseDomainWarpFractalOctaves
{
get => noiseDomainWarpFractalOctaves;
get => _noiseDomainWarpFractalOctaves;
set
{
noiseDomainWarpFractalOctaves = value;
_noiseDomainWarpFractalOctaves = value;
GenerateWorld();
}
}
[Export] public float NoiseDomainWarpFractalLacunarity
{
get => noiseDomainWarpFractalLacunarity;
get => _noiseDomainWarpFractalLacunarity;
set
{
noiseDomainWarpFractalLacunarity = value;
_noiseDomainWarpFractalLacunarity = value;
GenerateWorld();
}
}
[Export] public float NoiseDomainWarpFractalGain
{
get => noiseDomainWarpFractalGain;
get => _noiseDomainWarpFractalGain;
set
{
noiseDomainWarpFractalGain = value;
_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;
// General
private int _noiseSeed;
private FastNoiseLite.NoiseTypeEnum _noiseType;
// Simplex and Perlin
private float _noiseFrequency = 0.01f;
private Vector3 _noiseOffset = new(0.0f, 0.0f, 0.0f);
private FastNoiseLite.FractalTypeEnum _noiseFractalType = FastNoiseLite.FractalTypeEnum.Fbm;
private int _noiseFractalOctaves = 5;
private float _noiseFractalLacunarity = 2.0f;
private float _noiseFractalGain = 0.5f;
private float _noiseFractalWeightedStrength = 0.0f;
private float _noiseFractalPingPongStrength = 2.0f;
// Cellular
private float _noiseCellularJitter = 1.0f;
private FastNoiseLite.CellularDistanceFunctionEnum _noiseCellularDistanceFunction;
private FastNoiseLite.CellularReturnTypeEnum _noiseCellularReturnType = FastNoiseLite.CellularReturnTypeEnum.Distance;
// Domain Warp
private bool _noiseDomainWarpEnabled = false;
private FastNoiseLite.DomainWarpTypeEnum _noiseDomainWarpType = FastNoiseLite.DomainWarpTypeEnum.SimplexReduced;
private float _noiseDomainWarpAmplitude = 30.0f;
private float _noiseDomainWarpFrequency = 0.05f;
private FastNoiseLite.DomainWarpFractalTypeEnum _noiseDomainWarpFractalType =
FastNoiseLite.DomainWarpFractalTypeEnum.Progressive;
private int _noiseDomainWarpFractalOctaves = 5;
private float _noiseDomainWarpFractalLacunarity = 6.0f;
private float _noiseDomainWarpFractalGain = 0.5f;
private void GenerateWorldComplex()
{
@@ -350,39 +415,39 @@ public partial class World : Node2D
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;
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 y = 0; y < _worldHeight; y++)
{
for (int x = 0; x < worldWidth; x++)
for (int x = 0; x < _worldWidth; x++)
{
var rnd = noise.GetNoise2D(x, y);
if (rnd < .3f)
tileMapLayer.SetCell(new Vector2I(x, y), 0, darkGras);
_tileMapLayer.SetCell(new Vector2I(x, y), 0, _darkGras);
else if (rnd < .6f)
tileMapLayer.SetCell(new Vector2I(x, y), 0, brightGras);
_tileMapLayer.SetCell(new Vector2I(x, y), 0, _brightGras);
else
tileMapLayer.SetCell(new Vector2I(x, y), 0, flower);
_tileMapLayer.SetCell(new Vector2I(x, y), 0, _flower);
}
}
}

View File

@@ -1,8 +1,9 @@
[gd_scene load_steps=6 format=3 uid="uid://brbhyuelsuxyx"]
[gd_scene load_steps=7 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"]
[ext_resource type="Script" uid="uid://cqrt5x30j5vm6" path="res://scenes/main/grid.gd" id="4_6m72w"]
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_0xm2m"]
texture = ExtResource("1_f3sb7")
@@ -17,7 +18,6 @@ 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="."]
@@ -25,7 +25,12 @@ texture_filter = 1
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
[node name="Grid" type="Node2D" parent="."]
script = ExtResource("4_6m72w")
show_debug = true
[node name="Debug" type="Node2D" parent="Grid"]