Added new Tileset (Better walls and floors) and reworked layer generation. Working on placeholders next again (Need to fix rotation)
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class DecorationHandler
|
||||
{
|
||||
public static void Spawn(List<TileRenderData> tiles, Dictionary<string, MeshInstance3D> decorationMeshes)
|
||||
{
|
||||
foreach (var data in tiles)
|
||||
{
|
||||
Node3D tileNode = data.Tile.DecorationNode;
|
||||
|
||||
foreach (var placeholder in data.Placeholders)
|
||||
{
|
||||
string key = placeholder.name.ToLower();
|
||||
|
||||
var decoration = new MeshInstance3D();
|
||||
|
||||
if (decorationMeshes.ContainsKey(key))
|
||||
{
|
||||
decoration.Mesh = decorationMeshes[key].Mesh;
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
decoration.Position = placeholder.pos;
|
||||
|
||||
if (key == "light")
|
||||
{
|
||||
decoration.AddChild(new OmniLight3D()
|
||||
{
|
||||
OmniAttenuation = 2f,
|
||||
LightColor = new Color("#eae7ad"),
|
||||
ShadowEnabled = true,
|
||||
LightEnergy = 5f,
|
||||
LightIndirectEnergy = 1.5f,
|
||||
Position = new Vector3(0.5f, 0, 0)
|
||||
});
|
||||
}
|
||||
|
||||
tileNode.AddChild(decoration);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://oe2d2ape41jj
|
||||
@@ -2,8 +2,8 @@ public partial class GameData
|
||||
{
|
||||
//Amount of layers generated
|
||||
public static int ruinSize = 10;
|
||||
//Width+Height of layers (+1 for the border)
|
||||
public static int layerSize = 20 + 1;
|
||||
//Width+Height of layers
|
||||
public static int layerSize = 20;
|
||||
//Current layer the player wants to see
|
||||
public static int currentLayer = 0;
|
||||
//The layer that is currently visible
|
||||
|
||||
+49
-17
@@ -5,12 +5,14 @@ using System.Linq;
|
||||
using static WFC;
|
||||
public partial class Layer : Node3D
|
||||
{
|
||||
Random rand = new Random();
|
||||
private Node3D decorationRoot;
|
||||
public Tile[,] tiles;
|
||||
int layerSize;
|
||||
Tile tile;
|
||||
int level;
|
||||
bool updateFailed = false;
|
||||
public bool hasContentGenerated = false;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
@@ -31,7 +33,7 @@ public partial class Layer : Node3D
|
||||
{
|
||||
foreach (var tile in tiles)
|
||||
{
|
||||
foreach (Node child in tile.DecorationNode.GetChildren())
|
||||
foreach (Node child in tile.ContentNode.GetChildren())
|
||||
{
|
||||
child.QueueFree();
|
||||
}
|
||||
@@ -63,10 +65,10 @@ public partial class Layer : Node3D
|
||||
float offsetZ;
|
||||
for (int x = 0; x < layerSize; x++)
|
||||
{
|
||||
offsetX = x * 4;
|
||||
offsetX = x * 6;
|
||||
for (int y = 0; y < layerSize; y++)
|
||||
{
|
||||
offsetZ = y * 4;
|
||||
offsetZ = y * 6;
|
||||
position = new Vector3(offsetX, offsetY, offsetZ);
|
||||
tile = new Tile();
|
||||
tile.SetMeshes(tileMeshes);
|
||||
@@ -87,7 +89,7 @@ public partial class Layer : Node3D
|
||||
};
|
||||
decorationRoot.AddChild(node);
|
||||
|
||||
tile.DecorationNode = node;
|
||||
tile.ContentNode = node;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +114,47 @@ public partial class Layer : Node3D
|
||||
{
|
||||
var tile = tiles[x, y];
|
||||
|
||||
string result = tile.Collapse("border");
|
||||
List<string> possibilities = new();
|
||||
|
||||
if(x == 0 && y == 0)
|
||||
{
|
||||
possibilities.Add("corner_down_right");
|
||||
}
|
||||
else if(x == 0 && y == layerSize - 1)
|
||||
{
|
||||
possibilities.Add("corner_up_right");
|
||||
}
|
||||
else if(x == layerSize - 1 && y == 0)
|
||||
{
|
||||
possibilities.Add("corner_down_left");
|
||||
}
|
||||
else if(x == layerSize - 1 && y == layerSize - 1)
|
||||
{
|
||||
possibilities.Add("corner_up_left");
|
||||
}
|
||||
else if(y == 0)
|
||||
{
|
||||
possibilities.Add("straight_left_right");
|
||||
possibilities.Add("t_down");
|
||||
}
|
||||
else if(y == layerSize - 1)
|
||||
{
|
||||
possibilities.Add("straight_left_right");
|
||||
possibilities.Add("t_up");
|
||||
}
|
||||
else if(x == 0)
|
||||
{
|
||||
possibilities.Add("straight_up_down");
|
||||
possibilities.Add("t_right");
|
||||
}
|
||||
else if(x == layerSize - 1)
|
||||
{
|
||||
possibilities.Add("straight_up_down");
|
||||
possibilities.Add("t_left");
|
||||
}
|
||||
|
||||
string result = tile.Collapse(possibilities[rand.Next(0, possibilities.Count)]);
|
||||
|
||||
if (result == "ERR")
|
||||
return false;
|
||||
|
||||
@@ -135,15 +177,7 @@ public partial class Layer : Node3D
|
||||
Vector2I position = GetSmallestPossibilities();
|
||||
while (true)
|
||||
{
|
||||
string keyword;
|
||||
if (position.X == 0 || position.X == layerSize - 1 || position.Y == 0 || position.Y == layerSize - 1)
|
||||
{
|
||||
keyword = tiles[position.X, position.Y].Collapse("border");
|
||||
}
|
||||
else
|
||||
{
|
||||
keyword = tiles[position.X, position.Y].Collapse("");
|
||||
}
|
||||
string keyword = tiles[position.X, position.Y].Collapse("");
|
||||
if (keyword == "ERR") return false;
|
||||
if (keyword != "")
|
||||
{
|
||||
@@ -160,8 +194,6 @@ public partial class Layer : Node3D
|
||||
if (safetyCounter == layerSize * layerSize) return false;
|
||||
}
|
||||
if (updateFailed) return false;
|
||||
//Spawn is a tile border, redo world generation
|
||||
if (tiles[1, 1].collapsedMesh == "border") return false;
|
||||
//Player has over 80% of tiles available without destroying walls => Results in about 95% success rate
|
||||
//Not necessarily needed but improves the overall generation percentage at a low resource cost
|
||||
if (!WFC.IsMapConnected(tiles, 0.8f)) return false;
|
||||
@@ -186,7 +218,7 @@ public partial class Layer : Node3D
|
||||
for (int i = 0; i < dirs.Length; i++)
|
||||
{
|
||||
Vector2I newPos = currentPos + offsets[i];
|
||||
if (!InBounds(newPos, layerSize, true)) continue;
|
||||
if (!InBounds(newPos, layerSize)) continue;
|
||||
|
||||
Tile neighborTile = tiles[newPos.X, newPos.Y];
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ using Godot;
|
||||
public class Placeholder
|
||||
{
|
||||
public string name;
|
||||
public Vector3 pos;
|
||||
public Transform3D transform;
|
||||
|
||||
public Placeholder(string name, Vector3 pos){
|
||||
public Placeholder(string name, Transform3D transform){
|
||||
this.name = name.Split("_")[0];
|
||||
this.pos = pos;
|
||||
this.transform = transform;
|
||||
}
|
||||
}
|
||||
+11
-25
@@ -53,14 +53,12 @@ public class WFC
|
||||
["corner_down_right"] = new() { Direction.Down, Direction.Right },
|
||||
|
||||
["junction"] = new() { Direction.Up, Direction.Down, Direction.Left, Direction.Right },
|
||||
["gate"] = new() { Direction.Up, Direction.Down, Direction.Left, Direction.Right },
|
||||
|
||||
["border"] = new() { }
|
||||
["gate"] = new() { Direction.Up, Direction.Down, Direction.Left, Direction.Right }
|
||||
};
|
||||
|
||||
public static Dictionary<string, float> weights = new()
|
||||
{
|
||||
["junction"] = 5f,
|
||||
["junction"] = 3f,
|
||||
["t_up"] = 3f,
|
||||
["t_down"] = 3f,
|
||||
["t_left"] = 3f,
|
||||
@@ -69,19 +67,17 @@ public class WFC
|
||||
["straight_left_right"] = 2f,
|
||||
["straight_up_down"] = 2f,
|
||||
|
||||
["corner_up_left"] = 0.5f,
|
||||
["corner_up_right"] = 0.5f,
|
||||
["corner_down_left"] = 0.5f,
|
||||
["corner_down_right"] = 0.5f,
|
||||
["corner_up_left"] = 0.7f,
|
||||
["corner_up_right"] = 0.7f,
|
||||
["corner_down_left"] = 0.7f,
|
||||
["corner_down_right"] = 0.7f,
|
||||
|
||||
["end_up"] = 0.2f,
|
||||
["end_down"] = 0.1f,
|
||||
["end_left"] = 0.2f,
|
||||
["end_right"] = 0.3f,
|
||||
|
||||
["gate"] = 0.1f,
|
||||
|
||||
["border"] = 0.0f
|
||||
["gate"] = 0.1f
|
||||
};
|
||||
|
||||
public static Direction Opposite(Direction dir)
|
||||
@@ -169,7 +165,7 @@ public class WFC
|
||||
{
|
||||
var next = position + offsets[i];
|
||||
|
||||
if (!InBounds(next, layer.GetLength(0), false))
|
||||
if (!InBounds(next, layer.GetLength(0)))
|
||||
continue;
|
||||
|
||||
if (CanWalk(layer, position, next, dirs[i]))
|
||||
@@ -189,21 +185,11 @@ public class WFC
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool InBounds(Vector2I pos, int layerSize, bool includeBorder = true)
|
||||
public static bool InBounds(Vector2I pos, int layerSize)
|
||||
{
|
||||
if (includeBorder)
|
||||
{
|
||||
return pos.X >= 0 &&
|
||||
pos.Y >= 0 &&
|
||||
return pos.X > 0 &&
|
||||
pos.Y > 0 &&
|
||||
pos.X < layerSize &&
|
||||
pos.Y < layerSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
return pos.X > 0 &&
|
||||
pos.Y > 0 &&
|
||||
pos.X < layerSize - 1 &&
|
||||
pos.Y < layerSize - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user