Added resource weights and layer unlock UI to the game.

This commit is contained in:
2026-05-09 13:53:00 +02:00
parent 677d8595db
commit 9fa1909dcb
7 changed files with 101 additions and 29 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ public partial class Layer : Node3D
private Node3D decorationRoot;
public Tile[,] tiles;
private int layerSize;
private int level;
public int level;
private bool updateFailed = false;
public bool hasContentGenerated = false;
public Vector2I gateCoordinate;
+27 -20
View File
@@ -4,30 +4,37 @@ using Godot;
public class ResourceDistributor
{
public static Dictionary<string, Texture2D> resources = ResourceLoader.LoadResourceSymbols();
public static Dictionary<string, float[]> weights = ResourceLoader.LoadResourceWeights();
public static string GetResource(List<string> current)
public static string GetResource(int layer)
{
List<string> availableResources = GetUnusedResources(current);
if (availableResources.Count <= 0)
{
availableResources = new List<string>(resources.Keys);
}
return availableResources[GameData.rand.Next(availableResources.Count)];
return ChooseWeighted(layer);
}
private static List<string> GetUnusedResources(List<string> current)
{
List<string> result = new List<string>();
private static string ChooseWeighted(int layer)
{
float totalWeight = 0f;
float weightLerp;
foreach (string resource in resources.Keys)
{
if (!current.Contains(resource))
{
result.Add(resource);
}
}
foreach (string resource in resources.Keys)
{
weightLerp = Mathf.Lerp(weights[resource][0], weights[resource][1], layer);
totalWeight += weightLerp;
}
return result;
}
float r = (float)(GameData.rand.NextDouble() * totalWeight);
float cumulative = 0f;
foreach (string resource in resources.Keys)
{
weightLerp = Mathf.Lerp(weights[resource][0], weights[resource][1], layer);
cumulative += weightLerp;
if (r <= cumulative)
return resource;
}
return "stone";
}
}
+8 -1
View File
@@ -50,6 +50,8 @@ public partial class World : Node3D
robot.Position = map[0].tiles[0, 0].Position;
AddChild(robot);
robots.Add(robot);
SetGateRequirements();
}
private Dictionary<string, MultiMeshInstance3D> CreateMultiMeshes(Dictionary<string, Mesh> meshLibrary)
@@ -206,7 +208,7 @@ public partial class World : Node3D
if (layer.tiles[posX, posY].containsResource) continue;
layer.tiles[posX, posY].containsResource = true;
layer.tiles[posX, posY].resource = new GameResource(ResourceDistributor.GetResource(layer.currentResources));
layer.tiles[posX, posY].resource = new GameResource(ResourceDistributor.GetResource(layer.level));
layer.currentResources.Add(layer.tiles[posX, posY].resource.name);
currentResource++;
}
@@ -225,4 +227,9 @@ public partial class World : Node3D
data.Tile.SpawnContent(contentMeshes, data.Transform, data.Placeholders);
}
}
private void SetGateRequirements()
{
}
}