Added resource weights and layer unlock UI to the game.
This commit is contained in:
@@ -4,7 +4,7 @@ using Godot;
|
||||
|
||||
public partial class GameData
|
||||
{
|
||||
public static bool debugMode = false;
|
||||
public static bool debugMode = true;
|
||||
public static Random rand = new Random(seed);
|
||||
public static Layer[] map;
|
||||
|
||||
@@ -22,6 +22,7 @@ public partial class GameData
|
||||
public static Dictionary<string, Research> availableResearch = ResourceLoader.LoadResearch();
|
||||
public static SurvivalState survival = new SurvivalState();
|
||||
public static RobotStats robotStats = new RobotStats();
|
||||
public static Dictionary<int, List<Ingredient>> gateUnlocks;
|
||||
|
||||
public static Color primaryColor = new Color("#276ac2");
|
||||
public static Color lightColor = new Color("#7efff5");
|
||||
|
||||
@@ -90,6 +90,22 @@ public partial class ResourceLoader
|
||||
return symbols;
|
||||
}
|
||||
|
||||
public static Dictionary<string, float[]> LoadResourceWeights()
|
||||
{
|
||||
Dictionary<string, float[]> weights = new Dictionary<string, float[]>()
|
||||
{
|
||||
{ "iron_ore", [0.05f,1] },
|
||||
{ "tin_ore", [0.3f,0.7f] },
|
||||
{ "copper_ore", [0.3f,0.7f] },
|
||||
{ "mushroom", [0.3f,0.1f] },
|
||||
{ "spider_silk", [0.8f,0.4f] },
|
||||
{ "coal", [1,0.3f] },
|
||||
{ "water", [0.4f,0.2f] },
|
||||
{ "stone", [1,0.5f] },
|
||||
};
|
||||
return weights;
|
||||
}
|
||||
|
||||
public static SortedDictionary<string, ItemData> LoadItems()
|
||||
{
|
||||
|
||||
|
||||
@@ -20,6 +20,10 @@ public partial class UIHandler : Control
|
||||
[Export] RichTextLabel waterLabel;
|
||||
[Export] RichTextLabel hungerLabel;
|
||||
[Export] RichTextLabel survivalStatus;
|
||||
[Export] RichTextLabel currentLayer;
|
||||
[Export] RichTextLabel deepestLayer;
|
||||
[Export] Button unlockLayer;
|
||||
|
||||
|
||||
private bool receivedRobotJumpSignal = false;
|
||||
public override void _Ready()
|
||||
@@ -94,6 +98,7 @@ public partial class UIHandler : Control
|
||||
string memoryDisplay = memory > 1024 ? Math.Round(memory / 1024, 2).ToString() + " GB" : memory.ToString() + " MB";
|
||||
RAM.Text = memoryDisplay;
|
||||
DisplaySurvivalStats();
|
||||
DisplayWorldStats();
|
||||
}
|
||||
|
||||
public void ExitGame()
|
||||
@@ -159,4 +164,16 @@ public partial class UIHandler : Control
|
||||
hungerLabel.Text = $"Food: {GameData.survival.hunger:0}/{GameData.survival.maxHunger:0}";
|
||||
survivalStatus.Text = GameData.survival.currentStatus;
|
||||
}
|
||||
|
||||
private void DisplayWorldStats()
|
||||
{
|
||||
currentLayer.Text = $"Current layer: {GameData.currentLayer}/{GameData.ruinSize}";
|
||||
deepestLayer.Text = $"Deepest layer: {GameData.lowestLayer}";
|
||||
|
||||
}
|
||||
|
||||
public void UnlockLayer()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user