Refactoring of the Class and new generation Algorithm. Grid generation.
This commit is contained in:
@@ -1,85 +1,130 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using System;
|
using System;
|
||||||
|
using Godot.Collections;
|
||||||
|
|
||||||
public partial class World : Node2D
|
public partial class World : Node2D
|
||||||
{
|
{
|
||||||
public enum GeneratorAlgorithm
|
public enum GeneratorAlgorithm
|
||||||
{
|
{
|
||||||
RANDOM,
|
Random,
|
||||||
FAST_NOISE_LITE,
|
Simple,
|
||||||
COMPLEX
|
Complex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Vector2I darkGras = new Vector2I(0, 0);
|
Vector2I _darkGras = new Vector2I(0, 0);
|
||||||
Vector2I brightGras = new Vector2I(1, 0);
|
Vector2I _brightGras = new Vector2I(1, 0);
|
||||||
Vector2I flower = new Vector2I(2, 0);
|
Vector2I _flower = new Vector2I(2, 0);
|
||||||
TileMapLayer tileMapLayer;
|
TileMapLayer _tileMapLayer;
|
||||||
|
|
||||||
Vector2 screenSize;
|
Vector2 _screenSize;
|
||||||
float worldWidth;
|
float _worldWidth;
|
||||||
float worldHeight;
|
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()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
screenSize = GetViewportRect().Size;
|
GD.Print("World Node Ready");
|
||||||
worldWidth = screenSize.X;
|
|
||||||
worldHeight = screenSize.Y;
|
|
||||||
|
|
||||||
tileMapLayer = GetNode<TileMapLayer>("TileMapLayer");
|
|
||||||
|
|
||||||
generationTimeout = GetNode<Timer>("GenerationTimeout");
|
GD.Print("Getting Screen Size");
|
||||||
|
_screenSize = GetViewportRect().Size;
|
||||||
|
GD.Print("Setting World Size");
|
||||||
|
_worldWidth = _screenSize.X;
|
||||||
|
_worldHeight = _screenSize.Y;
|
||||||
|
|
||||||
|
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();
|
GD.Randomize();
|
||||||
GenerateWorld();
|
|
||||||
|
// World generation
|
||||||
|
GD.Print("Generating World");
|
||||||
|
if (_generationTimeout.IsNodeReady())
|
||||||
|
GenerateWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Process(double delta)
|
// public override void _Process(double delta)
|
||||||
{
|
// {
|
||||||
GD.Print(algorithm);
|
// GD.Print(algorithm);
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
private void GenerateWorld()
|
private void GenerateWorld()
|
||||||
{
|
{
|
||||||
if (generationTimeout.IsStopped())
|
try
|
||||||
{
|
{
|
||||||
switch (algorithm)
|
if (_generationTimeout.IsStopped())
|
||||||
{
|
{
|
||||||
case GeneratorAlgorithm.RANDOM:
|
switch (Algorithm)
|
||||||
GenerateWorldRandom();
|
{
|
||||||
break;
|
case GeneratorAlgorithm.Random:
|
||||||
case GeneratorAlgorithm.FAST_NOISE_LITE:
|
GenerateWorldRandom();
|
||||||
GenerateWorldSimplexNoise();
|
break;
|
||||||
break;
|
case GeneratorAlgorithm.Simple:
|
||||||
case GeneratorAlgorithm.COMPLEX:
|
GenerateWorldSimplexNoise();
|
||||||
GenerateWorldComplex();
|
break;
|
||||||
break;
|
case GeneratorAlgorithm.Complex:
|
||||||
default:
|
GenerateWorldComplex();
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_generationTimeout.Start();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
GD.PrintErr(e);
|
||||||
}
|
}
|
||||||
generationTimeout.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GenerateWorldRandom()
|
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();
|
float rnd = GD.Randf();
|
||||||
|
|
||||||
if (rnd < .7f)
|
if (rnd < .7f)
|
||||||
tileMapLayer.SetCell(new Vector2I(x, y), 0, darkGras);
|
_tileMapLayer.SetCell(new Vector2I(x, y), 0, _darkGras);
|
||||||
else if (rnd < .9f)
|
else if (rnd < .9f)
|
||||||
tileMapLayer.SetCell(new Vector2I(x, y), 0, brightGras);
|
_tileMapLayer.SetCell(new Vector2I(x, y), 0, _brightGras);
|
||||||
else
|
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.Seed = GD.RandRange(int.MinValue, int.MaxValue);
|
||||||
noise.FractalOctaves = 2;
|
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);
|
var rnd = noise.GetNoise2D(x, y);
|
||||||
|
|
||||||
@@ -101,11 +146,11 @@ public partial class World : Node2D
|
|||||||
// var yRnd = noise.GetNoise1D(y);
|
// var yRnd = noise.GetNoise1D(y);
|
||||||
|
|
||||||
if (rnd < .3f)
|
if (rnd < .3f)
|
||||||
tileMapLayer.SetCell(new Vector2I(x, y), 0, darkGras);
|
_tileMapLayer.SetCell(new Vector2I(x, y), 0, _darkGras);
|
||||||
else if (rnd < .6f)
|
else if (rnd < .6f)
|
||||||
tileMapLayer.SetCell(new Vector2I(x, y), 0, brightGras);
|
_tileMapLayer.SetCell(new Vector2I(x, y), 0, _brightGras);
|
||||||
else
|
else
|
||||||
tileMapLayer.SetCell(new Vector2I(x, y), 0, flower);
|
_tileMapLayer.SetCell(new Vector2I(x, y), 0, _flower);
|
||||||
|
|
||||||
|
|
||||||
// if (yRnd < .3f)
|
// 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]
|
[Export]
|
||||||
public FastNoiseLite.NoiseTypeEnum NoiseType
|
public FastNoiseLite.NoiseTypeEnum NoiseType
|
||||||
{
|
{
|
||||||
@@ -140,205 +175,235 @@ public partial class World : Node2D
|
|||||||
GenerateWorld();
|
GenerateWorld();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
[Export] public int NoiseSeed
|
||||||
[Export] public float NoiseFrequency
|
|
||||||
{
|
{
|
||||||
get => noiseFrequency;
|
get => _noiseSeed;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
noiseFrequency = value;
|
_noiseSeed = value;
|
||||||
GenerateWorld();
|
GenerateWorld();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Export] public Vector3 NoiseOffset
|
[Export] public Vector3 NoiseOffset
|
||||||
{
|
{
|
||||||
get => noiseOffset;
|
get => _noiseOffset;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
noiseOffset = value;
|
_noiseOffset = value;
|
||||||
|
GenerateWorld();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[ExportGroup("Perlin and Simplex")]
|
||||||
|
[Export] public float NoiseFrequency
|
||||||
|
{
|
||||||
|
get => _noiseFrequency;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_noiseFrequency = value;
|
||||||
GenerateWorld();
|
GenerateWorld();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Export] public FastNoiseLite.FractalTypeEnum NoiseFractalType
|
[Export] public FastNoiseLite.FractalTypeEnum NoiseFractalType
|
||||||
{
|
{
|
||||||
get => noiseFractalType;
|
get => _noiseFractalType;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
noiseFractalType = value;
|
_noiseFractalType = value;
|
||||||
GenerateWorld();
|
GenerateWorld();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Export] public int NoiseFractalOctaves
|
[Export] public int NoiseFractalOctaves
|
||||||
{
|
{
|
||||||
get => noiseFractalOctaves;
|
get => _noiseFractalOctaves;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
noiseFractalOctaves = value;
|
_noiseFractalOctaves = value;
|
||||||
GenerateWorld();
|
GenerateWorld();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Export] public float NoiseFractalLacunarity
|
[Export] public float NoiseFractalLacunarity
|
||||||
{
|
{
|
||||||
get => noiseFractalLacunarity;
|
get => _noiseFractalLacunarity;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
noiseFractalLacunarity = value;
|
_noiseFractalLacunarity = value;
|
||||||
GenerateWorld();
|
GenerateWorld();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Export] public float NoiseFractalGain
|
[Export] public float NoiseFractalGain
|
||||||
{
|
{
|
||||||
get => noiseFractalGain;
|
get => _noiseFractalGain;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
noiseFractalGain = value;
|
_noiseFractalGain = value;
|
||||||
GenerateWorld();
|
GenerateWorld();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Export] public float NoiseFractalWeightedStrength
|
[Export] public float NoiseFractalWeightedStrength
|
||||||
{
|
{
|
||||||
get => noiseFractalWeightedStrength;
|
get => _noiseFractalWeightedStrength;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
noiseFractalWeightedStrength = value;
|
_noiseFractalWeightedStrength = value;
|
||||||
GenerateWorld();
|
GenerateWorld();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Export] public float NoiseFractalPingPongStrength
|
[Export] public float NoiseFractalPingPongStrength
|
||||||
{
|
{
|
||||||
get => noiseFractalPingPongStrength;
|
get => _noiseFractalPingPongStrength;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
noiseFractalPingPongStrength = value;
|
_noiseFractalPingPongStrength = value;
|
||||||
|
GenerateWorld();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[ExportGroup("Cellular")]
|
||||||
|
[Export] public float NoiseCellularJitter
|
||||||
|
{
|
||||||
|
get => _noiseCellularJitter;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_noiseCellularJitter = value;
|
||||||
GenerateWorld();
|
GenerateWorld();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Export] public float NoiseCellularJitter
|
[Export]
|
||||||
|
public FastNoiseLite.CellularDistanceFunctionEnum NoiseCellularDistanceFunction
|
||||||
{
|
{
|
||||||
get => noiseCellularJitter;
|
get => _noiseCellularDistanceFunction;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
noiseCellularJitter = value;
|
_noiseCellularDistanceFunction = value;
|
||||||
GenerateWorld();
|
GenerateWorld();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Export] public FastNoiseLite.CellularReturnTypeEnum NoiseCellularReturnType
|
[Export] public FastNoiseLite.CellularReturnTypeEnum NoiseCellularReturnType
|
||||||
{
|
{
|
||||||
get => noiseCellularReturnType;
|
get => _noiseCellularReturnType;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
noiseCellularReturnType = value;
|
_noiseCellularReturnType = value;
|
||||||
GenerateWorld();
|
GenerateWorld();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ExportGroup("Domain Warp")]
|
||||||
[Export] public bool NoiseDomainWarpEnabled
|
[Export] public bool NoiseDomainWarpEnabled
|
||||||
{
|
{
|
||||||
get => noiseDomainWarpEnabled;
|
get => _noiseDomainWarpEnabled;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
noiseDomainWarpEnabled = value;
|
_noiseDomainWarpEnabled = value;
|
||||||
GenerateWorld();
|
GenerateWorld();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Export] public FastNoiseLite.DomainWarpTypeEnum NoiseDomainWarpType
|
[Export] public FastNoiseLite.DomainWarpTypeEnum NoiseDomainWarpType
|
||||||
{
|
{
|
||||||
get => noiseDomainWarpType;
|
get => _noiseDomainWarpType;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
noiseDomainWarpType = value;
|
_noiseDomainWarpType = value;
|
||||||
GenerateWorld();
|
GenerateWorld();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Export] public float NoiseDomainWarpAmplitude
|
[Export] public float NoiseDomainWarpAmplitude
|
||||||
{
|
{
|
||||||
get => noiseDomainWarpAmplitude;
|
get => _noiseDomainWarpAmplitude;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
noiseDomainWarpAmplitude = value;
|
_noiseDomainWarpAmplitude = value;
|
||||||
GenerateWorld();
|
GenerateWorld();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Export] public float NoiseDomainWarpFrequency
|
[Export] public float NoiseDomainWarpFrequency
|
||||||
{
|
{
|
||||||
get => noiseDomainWarpFrequency;
|
get => _noiseDomainWarpFrequency;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
noiseDomainWarpFrequency = value;
|
_noiseDomainWarpFrequency = value;
|
||||||
GenerateWorld();
|
GenerateWorld();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Export] public FastNoiseLite.DomainWarpFractalTypeEnum NoiseDomainWarpFractalType
|
[Export] public FastNoiseLite.DomainWarpFractalTypeEnum NoiseDomainWarpFractalType
|
||||||
{
|
{
|
||||||
get => noiseDomainWarpFractalType;
|
get => _noiseDomainWarpFractalType;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
noiseDomainWarpFractalType = value;
|
_noiseDomainWarpFractalType = value;
|
||||||
GenerateWorld();
|
GenerateWorld();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Export] public int NoiseDomainWarpFractalOctaves
|
[Export] public int NoiseDomainWarpFractalOctaves
|
||||||
{
|
{
|
||||||
get => noiseDomainWarpFractalOctaves;
|
get => _noiseDomainWarpFractalOctaves;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
noiseDomainWarpFractalOctaves = value;
|
_noiseDomainWarpFractalOctaves = value;
|
||||||
GenerateWorld();
|
GenerateWorld();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Export] public float NoiseDomainWarpFractalLacunarity
|
[Export] public float NoiseDomainWarpFractalLacunarity
|
||||||
{
|
{
|
||||||
get => noiseDomainWarpFractalLacunarity;
|
get => _noiseDomainWarpFractalLacunarity;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
noiseDomainWarpFractalLacunarity = value;
|
_noiseDomainWarpFractalLacunarity = value;
|
||||||
GenerateWorld();
|
GenerateWorld();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Export] public float NoiseDomainWarpFractalGain
|
[Export] public float NoiseDomainWarpFractalGain
|
||||||
{
|
{
|
||||||
get => noiseDomainWarpFractalGain;
|
get => _noiseDomainWarpFractalGain;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
noiseDomainWarpFractalGain = value;
|
_noiseDomainWarpFractalGain = value;
|
||||||
GenerateWorld();
|
GenerateWorld();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public float noiseFrequency;
|
// General
|
||||||
public Vector3 noiseOffset;
|
private int _noiseSeed;
|
||||||
public FastNoiseLite.FractalTypeEnum noiseFractalType;
|
private FastNoiseLite.NoiseTypeEnum _noiseType;
|
||||||
public int noiseFractalOctaves;
|
|
||||||
public float noiseFractalLacunarity;
|
// Simplex and Perlin
|
||||||
public float noiseFractalGain;
|
private float _noiseFrequency = 0.01f;
|
||||||
public float noiseFractalWeightedStrength;
|
private Vector3 _noiseOffset = new(0.0f, 0.0f, 0.0f);
|
||||||
public float noiseFractalPingPongStrength;
|
private FastNoiseLite.FractalTypeEnum _noiseFractalType = FastNoiseLite.FractalTypeEnum.Fbm;
|
||||||
public float noiseCellularJitter;
|
private int _noiseFractalOctaves = 5;
|
||||||
public FastNoiseLite.CellularReturnTypeEnum noiseCellularReturnType;
|
private float _noiseFractalLacunarity = 2.0f;
|
||||||
public bool noiseDomainWarpEnabled;
|
private float _noiseFractalGain = 0.5f;
|
||||||
public FastNoiseLite.DomainWarpTypeEnum noiseDomainWarpType;
|
private float _noiseFractalWeightedStrength = 0.0f;
|
||||||
public float noiseDomainWarpAmplitude;
|
private float _noiseFractalPingPongStrength = 2.0f;
|
||||||
public float noiseDomainWarpFrequency;
|
|
||||||
public FastNoiseLite.DomainWarpFractalTypeEnum noiseDomainWarpFractalType;
|
// Cellular
|
||||||
public int noiseDomainWarpFractalOctaves;
|
private float _noiseCellularJitter = 1.0f;
|
||||||
public float noiseDomainWarpFractalLacunarity;
|
private FastNoiseLite.CellularDistanceFunctionEnum _noiseCellularDistanceFunction;
|
||||||
public float noiseDomainWarpFractalGain;
|
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()
|
private void GenerateWorldComplex()
|
||||||
{
|
{
|
||||||
@@ -350,39 +415,39 @@ public partial class World : Node2D
|
|||||||
GD.Print(noise.Seed);
|
GD.Print(noise.Seed);
|
||||||
|
|
||||||
noise.NoiseType = _noiseType;
|
noise.NoiseType = _noiseType;
|
||||||
noise.Frequency = noiseFrequency;
|
noise.Frequency = _noiseFrequency;
|
||||||
noise.Offset = noiseOffset;
|
noise.Offset = _noiseOffset;
|
||||||
noise.FractalType = noiseFractalType;
|
noise.FractalType = _noiseFractalType;
|
||||||
noise.FractalOctaves = noiseFractalOctaves;
|
noise.FractalOctaves = _noiseFractalOctaves;
|
||||||
noise.FractalLacunarity = noiseFractalLacunarity;
|
noise.FractalLacunarity = _noiseFractalLacunarity;
|
||||||
noise.FractalGain = noiseFractalGain;
|
noise.FractalGain = _noiseFractalGain;
|
||||||
noise.FractalWeightedStrength = noiseFractalWeightedStrength;
|
noise.FractalWeightedStrength = _noiseFractalWeightedStrength;
|
||||||
noise.FractalPingPongStrength = noiseFractalPingPongStrength;
|
noise.FractalPingPongStrength = _noiseFractalPingPongStrength;
|
||||||
noise.CellularJitter = noiseCellularJitter;
|
noise.CellularJitter = _noiseCellularJitter;
|
||||||
noise.CellularReturnType = noiseCellularReturnType;
|
noise.CellularReturnType = _noiseCellularReturnType;
|
||||||
noise.DomainWarpEnabled = noiseDomainWarpEnabled;
|
noise.DomainWarpEnabled = _noiseDomainWarpEnabled;
|
||||||
noise.DomainWarpType = noiseDomainWarpType;
|
noise.DomainWarpType = _noiseDomainWarpType;
|
||||||
noise.DomainWarpAmplitude = noiseDomainWarpAmplitude;
|
noise.DomainWarpAmplitude = _noiseDomainWarpAmplitude;
|
||||||
noise.DomainWarpFrequency = noiseDomainWarpFrequency;
|
noise.DomainWarpFrequency = _noiseDomainWarpFrequency;
|
||||||
noise.DomainWarpFractalType = noiseDomainWarpFractalType;
|
noise.DomainWarpFractalType = _noiseDomainWarpFractalType;
|
||||||
noise.DomainWarpFractalOctaves = noiseDomainWarpFractalOctaves;
|
noise.DomainWarpFractalOctaves = _noiseDomainWarpFractalOctaves;
|
||||||
noise.DomainWarpFractalLacunarity = noiseDomainWarpFractalLacunarity;
|
noise.DomainWarpFractalLacunarity = _noiseDomainWarpFractalLacunarity;
|
||||||
noise.DomainWarpFractalGain = noiseDomainWarpFractalGain;
|
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);
|
var rnd = noise.GetNoise2D(x, y);
|
||||||
|
|
||||||
if (rnd < .3f)
|
if (rnd < .3f)
|
||||||
tileMapLayer.SetCell(new Vector2I(x, y), 0, darkGras);
|
_tileMapLayer.SetCell(new Vector2I(x, y), 0, _darkGras);
|
||||||
else if (rnd < .6f)
|
else if (rnd < .6f)
|
||||||
tileMapLayer.SetCell(new Vector2I(x, y), 0, brightGras);
|
_tileMapLayer.SetCell(new Vector2I(x, y), 0, _brightGras);
|
||||||
else
|
else
|
||||||
tileMapLayer.SetCell(new Vector2I(x, y), 0, flower);
|
_tileMapLayer.SetCell(new Vector2I(x, y), 0, _flower);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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="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="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="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"]
|
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_0xm2m"]
|
||||||
texture = ExtResource("1_f3sb7")
|
texture = ExtResource("1_f3sb7")
|
||||||
@@ -17,7 +18,6 @@ sources/0 = SubResource("TileSetAtlasSource_0xm2m")
|
|||||||
|
|
||||||
[node name="World" type="Node2D"]
|
[node name="World" type="Node2D"]
|
||||||
script = ExtResource("1_rwgxs")
|
script = ExtResource("1_rwgxs")
|
||||||
algorithm = 1
|
|
||||||
metadata/_edit_group_ = true
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
[node name="TileMapLayer" type="TileMapLayer" parent="."]
|
[node name="TileMapLayer" type="TileMapLayer" parent="."]
|
||||||
@@ -25,7 +25,12 @@ texture_filter = 1
|
|||||||
tile_set = SubResource("TileSet_h2yge")
|
tile_set = SubResource("TileSet_h2yge")
|
||||||
|
|
||||||
[node name="Spawner" parent="." instance=ExtResource("3_1fp7r")]
|
[node name="Spawner" parent="." instance=ExtResource("3_1fp7r")]
|
||||||
position = Vector2(50, 50)
|
|
||||||
|
|
||||||
[node name="GenerationTimeout" type="Timer" parent="."]
|
[node name="GenerationTimeout" type="Timer" parent="."]
|
||||||
one_shot = true
|
one_shot = true
|
||||||
|
|
||||||
|
[node name="Grid" type="Node2D" parent="."]
|
||||||
|
script = ExtResource("4_6m72w")
|
||||||
|
show_debug = true
|
||||||
|
|
||||||
|
[node name="Debug" type="Node2D" parent="Grid"]
|
||||||
|
|||||||
Reference in New Issue
Block a user