Added resource weights and layer unlock UI to the game.
This commit is contained in:
+30
-6
@@ -18,7 +18,7 @@
|
|||||||
[ext_resource type="Script" uid="uid://drscsrkfphpy7" path="res://Scripts/UI/Research/ResearchList.cs" id="12_4q8tf"]
|
[ext_resource type="Script" uid="uid://drscsrkfphpy7" path="res://Scripts/UI/Research/ResearchList.cs" id="12_4q8tf"]
|
||||||
[ext_resource type="Texture2D" uid="uid://dt84awx33mulb" path="res://Assets/Images/ResearchSymbol.png" id="13_alh3a"]
|
[ext_resource type="Texture2D" uid="uid://dt84awx33mulb" path="res://Assets/Images/ResearchSymbol.png" id="13_alh3a"]
|
||||||
[ext_resource type="Texture2D" uid="uid://bmcpkt6mae2qi" path="res://Assets/Images/AlarmSign.png" id="13_x3xnh"]
|
[ext_resource type="Texture2D" uid="uid://bmcpkt6mae2qi" path="res://Assets/Images/AlarmSign.png" id="13_x3xnh"]
|
||||||
[ext_resource type="Texture2D" path="res://Assets/Images/Resources/MushroomSymbol.png" id="14_food"]
|
[ext_resource type="Texture2D" uid="uid://uunnuou4g86w" path="res://Assets/Images/Resources/MushroomSymbol.png" id="14_food"]
|
||||||
|
|
||||||
[sub_resource type="CompressedTexture2D" id="CompressedTexture2D_u44n3"]
|
[sub_resource type="CompressedTexture2D" id="CompressedTexture2D_u44n3"]
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ environment = SubResource("Environment_sb48q")
|
|||||||
[node name="CanvasLayer" type="CanvasLayer" parent="." unique_id=1558432386]
|
[node name="CanvasLayer" type="CanvasLayer" parent="." unique_id=1558432386]
|
||||||
follow_viewport_enabled = true
|
follow_viewport_enabled = true
|
||||||
|
|
||||||
[node name="UIHandler" type="Control" parent="CanvasLayer" unique_id=1713248285 node_paths=PackedStringArray("codingWindow", "robotList", "mainCam", "map", "FPS", "RAM", "options", "uiContent", "menu", "inventory", "researchList", "robotAlarm", "energyLabel", "waterLabel", "hungerLabel", "survivalStatus")]
|
[node name="UIHandler" type="Control" parent="CanvasLayer" unique_id=1713248285 node_paths=PackedStringArray("codingWindow", "robotList", "mainCam", "map", "FPS", "RAM", "options", "uiContent", "menu", "inventory", "researchList", "robotAlarm", "energyLabel", "waterLabel", "hungerLabel", "survivalStatus", "currentLayer", "deepestLayer", "unlockLayer")]
|
||||||
layout_mode = 3
|
layout_mode = 3
|
||||||
anchors_preset = 15
|
anchors_preset = 15
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
@@ -96,6 +96,9 @@ energyLabel = NodePath("MainUI/HeaderContainer/VBoxContainer/RowEnergy/RichTextL
|
|||||||
waterLabel = NodePath("MainUI/HeaderContainer/VBoxContainer/RowWater/RichTextLabel")
|
waterLabel = NodePath("MainUI/HeaderContainer/VBoxContainer/RowWater/RichTextLabel")
|
||||||
hungerLabel = NodePath("MainUI/HeaderContainer/VBoxContainer/RowHunger/RichTextLabel")
|
hungerLabel = NodePath("MainUI/HeaderContainer/VBoxContainer/RowHunger/RichTextLabel")
|
||||||
survivalStatus = NodePath("MainUI/HeaderContainer/VBoxContainer/SurvivalStatus")
|
survivalStatus = NodePath("MainUI/HeaderContainer/VBoxContainer/SurvivalStatus")
|
||||||
|
currentLayer = NodePath("MainUI/HeaderContainer/VBoxContainer/CurrentLayer")
|
||||||
|
deepestLayer = NodePath("MainUI/HeaderContainer/VBoxContainer/DeepestLayer")
|
||||||
|
unlockLayer = NodePath("MainUI/HeaderContainer/VBoxContainer/UnlockLayer")
|
||||||
|
|
||||||
[node name="MainUI" type="VBoxContainer" parent="CanvasLayer/UIHandler" unique_id=1437975209]
|
[node name="MainUI" type="VBoxContainer" parent="CanvasLayer/UIHandler" unique_id=1437975209]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
@@ -111,6 +114,7 @@ theme_override_styles/panel = SubResource("StyleBoxFlat_b2bpf")
|
|||||||
|
|
||||||
[node name="VBoxContainer" type="HBoxContainer" parent="CanvasLayer/UIHandler/MainUI/HeaderContainer" unique_id=536619770]
|
[node name="VBoxContainer" type="HBoxContainer" parent="CanvasLayer/UIHandler/MainUI/HeaderContainer" unique_id=536619770]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
theme_override_constants/separation = 12
|
||||||
|
|
||||||
[node name="RowEnergy" type="HBoxContainer" parent="CanvasLayer/UIHandler/MainUI/HeaderContainer/VBoxContainer" unique_id=867560906]
|
[node name="RowEnergy" type="HBoxContainer" parent="CanvasLayer/UIHandler/MainUI/HeaderContainer/VBoxContainer" unique_id=867560906]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
@@ -146,15 +150,15 @@ autowrap_mode = 0
|
|||||||
horizontal_alignment = 1
|
horizontal_alignment = 1
|
||||||
vertical_alignment = 1
|
vertical_alignment = 1
|
||||||
|
|
||||||
[node name="RowHunger" type="HBoxContainer" parent="CanvasLayer/UIHandler/MainUI/HeaderContainer/VBoxContainer"]
|
[node name="RowHunger" type="HBoxContainer" parent="CanvasLayer/UIHandler/MainUI/HeaderContainer/VBoxContainer" unique_id=86109825]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="TextureRect" type="TextureRect" parent="CanvasLayer/UIHandler/MainUI/HeaderContainer/VBoxContainer/RowHunger"]
|
[node name="TextureRect" type="TextureRect" parent="CanvasLayer/UIHandler/MainUI/HeaderContainer/VBoxContainer/RowHunger" unique_id=866450525]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
texture = ExtResource("14_food")
|
texture = ExtResource("14_food")
|
||||||
expand_mode = 2
|
expand_mode = 2
|
||||||
|
|
||||||
[node name="RichTextLabel" type="RichTextLabel" parent="CanvasLayer/UIHandler/MainUI/HeaderContainer/VBoxContainer/RowHunger"]
|
[node name="RichTextLabel" type="RichTextLabel" parent="CanvasLayer/UIHandler/MainUI/HeaderContainer/VBoxContainer/RowHunger" unique_id=1098660752]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
text = "Food: 100/100"
|
text = "Food: 100/100"
|
||||||
@@ -163,7 +167,7 @@ autowrap_mode = 0
|
|||||||
horizontal_alignment = 1
|
horizontal_alignment = 1
|
||||||
vertical_alignment = 1
|
vertical_alignment = 1
|
||||||
|
|
||||||
[node name="SurvivalStatus" type="RichTextLabel" parent="CanvasLayer/UIHandler/MainUI/HeaderContainer/VBoxContainer"]
|
[node name="SurvivalStatus" type="RichTextLabel" parent="CanvasLayer/UIHandler/MainUI/HeaderContainer/VBoxContainer" unique_id=1364578228]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
text = "Survival stable"
|
text = "Survival stable"
|
||||||
@@ -172,6 +176,26 @@ autowrap_mode = 0
|
|||||||
horizontal_alignment = 1
|
horizontal_alignment = 1
|
||||||
vertical_alignment = 1
|
vertical_alignment = 1
|
||||||
|
|
||||||
|
[node name="CurrentLayer" type="RichTextLabel" parent="CanvasLayer/UIHandler/MainUI/HeaderContainer/VBoxContainer" unique_id=1435047910]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Current layer: XXX"
|
||||||
|
fit_content = true
|
||||||
|
autowrap_mode = 0
|
||||||
|
horizontal_alignment = 1
|
||||||
|
vertical_alignment = 1
|
||||||
|
|
||||||
|
[node name="DeepestLayer" type="RichTextLabel" parent="CanvasLayer/UIHandler/MainUI/HeaderContainer/VBoxContainer" unique_id=600512938]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Deepest layer: XXX"
|
||||||
|
fit_content = true
|
||||||
|
autowrap_mode = 0
|
||||||
|
horizontal_alignment = 1
|
||||||
|
vertical_alignment = 1
|
||||||
|
|
||||||
|
[node name="UnlockLayer" type="Button" parent="CanvasLayer/UIHandler/MainUI/HeaderContainer/VBoxContainer" unique_id=1538511285]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Unlock layer"
|
||||||
|
|
||||||
[node name="Content" type="Control" parent="CanvasLayer/UIHandler/MainUI" unique_id=45665557]
|
[node name="Content" type="Control" parent="CanvasLayer/UIHandler/MainUI" unique_id=45665557]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_vertical = 3
|
size_flags_vertical = 3
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using Godot;
|
|||||||
|
|
||||||
public partial class GameData
|
public partial class GameData
|
||||||
{
|
{
|
||||||
public static bool debugMode = false;
|
public static bool debugMode = true;
|
||||||
public static Random rand = new Random(seed);
|
public static Random rand = new Random(seed);
|
||||||
public static Layer[] map;
|
public static Layer[] map;
|
||||||
|
|
||||||
@@ -22,6 +22,7 @@ public partial class GameData
|
|||||||
public static Dictionary<string, Research> availableResearch = ResourceLoader.LoadResearch();
|
public static Dictionary<string, Research> availableResearch = ResourceLoader.LoadResearch();
|
||||||
public static SurvivalState survival = new SurvivalState();
|
public static SurvivalState survival = new SurvivalState();
|
||||||
public static RobotStats robotStats = new RobotStats();
|
public static RobotStats robotStats = new RobotStats();
|
||||||
|
public static Dictionary<int, List<Ingredient>> gateUnlocks;
|
||||||
|
|
||||||
public static Color primaryColor = new Color("#276ac2");
|
public static Color primaryColor = new Color("#276ac2");
|
||||||
public static Color lightColor = new Color("#7efff5");
|
public static Color lightColor = new Color("#7efff5");
|
||||||
|
|||||||
@@ -90,6 +90,22 @@ public partial class ResourceLoader
|
|||||||
return symbols;
|
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()
|
public static SortedDictionary<string, ItemData> LoadItems()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ public partial class UIHandler : Control
|
|||||||
[Export] RichTextLabel waterLabel;
|
[Export] RichTextLabel waterLabel;
|
||||||
[Export] RichTextLabel hungerLabel;
|
[Export] RichTextLabel hungerLabel;
|
||||||
[Export] RichTextLabel survivalStatus;
|
[Export] RichTextLabel survivalStatus;
|
||||||
|
[Export] RichTextLabel currentLayer;
|
||||||
|
[Export] RichTextLabel deepestLayer;
|
||||||
|
[Export] Button unlockLayer;
|
||||||
|
|
||||||
|
|
||||||
private bool receivedRobotJumpSignal = false;
|
private bool receivedRobotJumpSignal = false;
|
||||||
public override void _Ready()
|
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";
|
string memoryDisplay = memory > 1024 ? Math.Round(memory / 1024, 2).ToString() + " GB" : memory.ToString() + " MB";
|
||||||
RAM.Text = memoryDisplay;
|
RAM.Text = memoryDisplay;
|
||||||
DisplaySurvivalStats();
|
DisplaySurvivalStats();
|
||||||
|
DisplayWorldStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ExitGame()
|
public void ExitGame()
|
||||||
@@ -159,4 +164,16 @@ public partial class UIHandler : Control
|
|||||||
hungerLabel.Text = $"Food: {GameData.survival.hunger:0}/{GameData.survival.maxHunger:0}";
|
hungerLabel.Text = $"Food: {GameData.survival.hunger:0}/{GameData.survival.maxHunger:0}";
|
||||||
survivalStatus.Text = GameData.survival.currentStatus;
|
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;
|
private Node3D decorationRoot;
|
||||||
public Tile[,] tiles;
|
public Tile[,] tiles;
|
||||||
private int layerSize;
|
private int layerSize;
|
||||||
private int level;
|
public int level;
|
||||||
private bool updateFailed = false;
|
private bool updateFailed = false;
|
||||||
public bool hasContentGenerated = false;
|
public bool hasContentGenerated = false;
|
||||||
public Vector2I gateCoordinate;
|
public Vector2I gateCoordinate;
|
||||||
|
|||||||
@@ -4,30 +4,37 @@ using Godot;
|
|||||||
public class ResourceDistributor
|
public class ResourceDistributor
|
||||||
{
|
{
|
||||||
public static Dictionary<string, Texture2D> resources = ResourceLoader.LoadResourceSymbols();
|
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);
|
return ChooseWeighted(layer);
|
||||||
if (availableResources.Count <= 0)
|
|
||||||
{
|
|
||||||
availableResources = new List<string>(resources.Keys);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return availableResources[GameData.rand.Next(availableResources.Count)];
|
private static string ChooseWeighted(int layer)
|
||||||
}
|
|
||||||
|
|
||||||
private static List<string> GetUnusedResources(List<string> current)
|
|
||||||
{
|
{
|
||||||
List<string> result = new List<string>();
|
float totalWeight = 0f;
|
||||||
|
float weightLerp;
|
||||||
|
|
||||||
foreach (string resource in resources.Keys)
|
foreach (string resource in resources.Keys)
|
||||||
{
|
{
|
||||||
if (!current.Contains(resource))
|
weightLerp = Mathf.Lerp(weights[resource][0], weights[resource][1], layer);
|
||||||
{
|
totalWeight += weightLerp;
|
||||||
result.Add(resource);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
robot.Position = map[0].tiles[0, 0].Position;
|
||||||
AddChild(robot);
|
AddChild(robot);
|
||||||
robots.Add(robot);
|
robots.Add(robot);
|
||||||
|
|
||||||
|
SetGateRequirements();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<string, MultiMeshInstance3D> CreateMultiMeshes(Dictionary<string, Mesh> meshLibrary)
|
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;
|
if (layer.tiles[posX, posY].containsResource) continue;
|
||||||
|
|
||||||
layer.tiles[posX, posY].containsResource = true;
|
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);
|
layer.currentResources.Add(layer.tiles[posX, posY].resource.name);
|
||||||
currentResource++;
|
currentResource++;
|
||||||
}
|
}
|
||||||
@@ -225,4 +227,9 @@ public partial class World : Node3D
|
|||||||
data.Tile.SpawnContent(contentMeshes, data.Transform, data.Placeholders);
|
data.Tile.SpawnContent(contentMeshes, data.Transform, data.Placeholders);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetGateRequirements()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user