diff --git a/Scenes/Game.tscn b/Scenes/Game.tscn index 8198fc7..fdab27a 100644 --- a/Scenes/Game.tscn +++ b/Scenes/Game.tscn @@ -18,7 +18,7 @@ [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://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"] @@ -68,7 +68,7 @@ environment = SubResource("Environment_sb48q") [node name="CanvasLayer" type="CanvasLayer" parent="." unique_id=1558432386] 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 anchors_preset = 15 anchor_right = 1.0 @@ -96,6 +96,9 @@ energyLabel = NodePath("MainUI/HeaderContainer/VBoxContainer/RowEnergy/RichTextL waterLabel = NodePath("MainUI/HeaderContainer/VBoxContainer/RowWater/RichTextLabel") hungerLabel = NodePath("MainUI/HeaderContainer/VBoxContainer/RowHunger/RichTextLabel") 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] 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] layout_mode = 2 +theme_override_constants/separation = 12 [node name="RowEnergy" type="HBoxContainer" parent="CanvasLayer/UIHandler/MainUI/HeaderContainer/VBoxContainer" unique_id=867560906] layout_mode = 2 @@ -146,15 +150,15 @@ autowrap_mode = 0 horizontal_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 -[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 texture = ExtResource("14_food") 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 size_flags_horizontal = 3 text = "Food: 100/100" @@ -163,7 +167,7 @@ autowrap_mode = 0 horizontal_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 size_flags_horizontal = 3 text = "Survival stable" @@ -172,6 +176,26 @@ autowrap_mode = 0 horizontal_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] layout_mode = 2 size_flags_vertical = 3 diff --git a/Scripts/Core/GameData.cs b/Scripts/Core/GameData.cs index b802502..85c9c2a 100644 --- a/Scripts/Core/GameData.cs +++ b/Scripts/Core/GameData.cs @@ -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 availableResearch = ResourceLoader.LoadResearch(); public static SurvivalState survival = new SurvivalState(); public static RobotStats robotStats = new RobotStats(); + public static Dictionary> gateUnlocks; public static Color primaryColor = new Color("#276ac2"); public static Color lightColor = new Color("#7efff5"); diff --git a/Scripts/Core/ResourceLoader.cs b/Scripts/Core/ResourceLoader.cs index ccbcdf8..1a1ab5f 100644 --- a/Scripts/Core/ResourceLoader.cs +++ b/Scripts/Core/ResourceLoader.cs @@ -90,6 +90,22 @@ public partial class ResourceLoader return symbols; } + public static Dictionary LoadResourceWeights() + { + Dictionary weights = new Dictionary() + { + { "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 LoadItems() { diff --git a/Scripts/UI/Common/UIHandler.cs b/Scripts/UI/Common/UIHandler.cs index 5ca67f2..e92e0e8 100644 --- a/Scripts/UI/Common/UIHandler.cs +++ b/Scripts/UI/Common/UIHandler.cs @@ -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() + { + + } } diff --git a/Scripts/World/Layer.cs b/Scripts/World/Layer.cs index ca74d93..34438e6 100644 --- a/Scripts/World/Layer.cs +++ b/Scripts/World/Layer.cs @@ -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; diff --git a/Scripts/World/ResourceDistributor.cs b/Scripts/World/ResourceDistributor.cs index af94223..f259117 100644 --- a/Scripts/World/ResourceDistributor.cs +++ b/Scripts/World/ResourceDistributor.cs @@ -4,30 +4,37 @@ using Godot; public class ResourceDistributor { public static Dictionary resources = ResourceLoader.LoadResourceSymbols(); + public static Dictionary weights = ResourceLoader.LoadResourceWeights(); - public static string GetResource(List current) + public static string GetResource(int layer) { - List availableResources = GetUnusedResources(current); - if (availableResources.Count <= 0) - { - availableResources = new List(resources.Keys); - } - - return availableResources[GameData.rand.Next(availableResources.Count)]; + return ChooseWeighted(layer); } - private static List GetUnusedResources(List current) - { - List result = new List(); + 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"; + } } diff --git a/Scripts/World/World.cs b/Scripts/World/World.cs index b565684..7a2c2e6 100644 --- a/Scripts/World/World.cs +++ b/Scripts/World/World.cs @@ -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 CreateMultiMeshes(Dictionary 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() + { + + } }