diff --git a/Scripts/Camera3d.cs b/Scripts/Camera3d.cs index bbae2a3..9d1f34d 100644 --- a/Scripts/Camera3d.cs +++ b/Scripts/Camera3d.cs @@ -11,7 +11,14 @@ public partial class Camera3d : Camera3D public override void _Process(double delta) { - if(!canMove) return; + if (canMove) MoveCamera(delta); + + if (!canMove) return; + + } + + public void MoveCamera(double delta) + { float d = (float)delta; var rotation = RotationDegrees; @@ -37,42 +44,4 @@ public partial class Camera3d : Camera3D Position = new Vector3(Position.X, 10 - visibleLayer * 4, Position.Z); } } - - public override void _Input(InputEvent @event) - { - if (@event is InputEventMouseButton mouse && - mouse.ButtonIndex == MouseButton.Left && - mouse.Pressed) - { - var camera = GetViewport().GetCamera3D(); - - Vector2 mousePos = mouse.Position; - - Vector3 from = camera.ProjectRayOrigin(mousePos); - Vector3 to = from + camera.ProjectRayNormal(mousePos) * 1000f; - - var spaceState = GetWorld3D().DirectSpaceState; - - var query = PhysicsRayQueryParameters3D.Create(from, to); - - query.CollisionMask = 1 << 1; - - var result = spaceState.IntersectRay(query); - - if (result.Count > 0) - { - Variant colliderVariant = result["collider"]; - - Node hit = colliderVariant.As(); - - GD.Print($"Clicked robot: {hit.Name}"); - - // Optional: call method on robot - if (hit is Node robot) - { - robot.Call("OnClicked"); - } - } - } - } } diff --git a/Scripts/Crafting/Building.cs b/Scripts/Crafting/Building.cs new file mode 100644 index 0000000..ba88a9d --- /dev/null +++ b/Scripts/Crafting/Building.cs @@ -0,0 +1,5 @@ +using Godot; + +public class Building +{ +} \ No newline at end of file diff --git a/Scripts/Crafting/Building.cs.uid b/Scripts/Crafting/Building.cs.uid new file mode 100644 index 0000000..bac56b0 --- /dev/null +++ b/Scripts/Crafting/Building.cs.uid @@ -0,0 +1 @@ +uid://cl2yvllo35qbb diff --git a/Scripts/Crafting/GameResource.cs b/Scripts/Crafting/GameResource.cs new file mode 100644 index 0000000..7111260 --- /dev/null +++ b/Scripts/Crafting/GameResource.cs @@ -0,0 +1,30 @@ +using Godot; + +public class GameResource +{ + int maxAmount; + int currentAmount; + bool isEndless; + float extractionSpeed; + public string name; + + public GameResource(string name) + { + this.name = name; + maxAmount = GameData.rand.Next(1000, 10000); + currentAmount = maxAmount; + isEndless = false; + extractionSpeed = 1f; + } + + public bool Extract() + { + if(isEndless) return true; + if (currentAmount > 0) + { + currentAmount--; + return true; + } + return false; + } +} \ No newline at end of file diff --git a/Scripts/Crafting/GameResource.cs.uid b/Scripts/Crafting/GameResource.cs.uid new file mode 100644 index 0000000..abb4096 --- /dev/null +++ b/Scripts/Crafting/GameResource.cs.uid @@ -0,0 +1 @@ +uid://bh4m8ufiv5kt8 diff --git a/Scripts/Crafting/Item.cs b/Scripts/Crafting/Item.cs new file mode 100644 index 0000000..e388af9 --- /dev/null +++ b/Scripts/Crafting/Item.cs @@ -0,0 +1,5 @@ +using Godot; + +public class Item +{ +} \ No newline at end of file diff --git a/Scripts/Crafting/Item.cs.uid b/Scripts/Crafting/Item.cs.uid new file mode 100644 index 0000000..590b5d7 --- /dev/null +++ b/Scripts/Crafting/Item.cs.uid @@ -0,0 +1 @@ +uid://dpq18vk7hbakh diff --git a/Scripts/Helpers/GameData.cs b/Scripts/Helpers/GameData.cs index 28dde25..aba0569 100644 --- a/Scripts/Helpers/GameData.cs +++ b/Scripts/Helpers/GameData.cs @@ -1,8 +1,10 @@ +using System; using System.Collections.Generic; using Godot; public partial class GameData { + public static Random rand = new Random(seed); public static Layer[] map; //Current layer the player wants to see public static int currentLayer = 0; @@ -13,6 +15,8 @@ public partial class GameData public static int maxRobotCount = 1000; public static List robots = new List(); public static float robotSpeed = 5f; + public static float tileWidth = 6; + public static float tileHeight = 4; //--- PLAYER ADJUSTABLE VALUES --- //Color used in primary objects (e.g. Robots) @@ -23,5 +27,7 @@ public partial class GameData public static int ruinSize = 10; //Width+Height of layers public static int layerSize = 20; + //Seed used for all random generation except WFC + public static int seed = 12345; } diff --git a/Scripts/Robot/Robot.cs b/Scripts/Robot/Robot.cs index 13b5475..cd40eba 100644 --- a/Scripts/Robot/Robot.cs +++ b/Scripts/Robot/Robot.cs @@ -33,11 +33,6 @@ public partial class Robot : Node3D } - public void OnClicked() - { - GetNode("/root/Main/CanvasLayer/UIHandler").ShowCodingWindow(this); - } - public void SetupExecution(List nodes) { this.nodes = [.. nodes]; diff --git a/Scripts/WorldGeneration/Layer.cs b/Scripts/WorldGeneration/Layer.cs index 5ada55d..12b3572 100644 --- a/Scripts/WorldGeneration/Layer.cs +++ b/Scripts/WorldGeneration/Layer.cs @@ -5,7 +5,6 @@ using System.Linq; using static WFC; public partial class Layer : Node3D { - Random rand = new Random(); private Node3D decorationRoot; public Tile[,] tiles; int layerSize; @@ -14,10 +13,12 @@ public partial class Layer : Node3D bool updateFailed = false; public bool hasContentGenerated = false; public Vector2I gateCoordinate; + public List currentResources; // Called when the node enters the scene tree for the first time. public override void _Ready() { + currentResources = new(); decorationRoot = new Node3D { Name = "Decorations" @@ -28,6 +29,7 @@ public partial class Layer : Node3D // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(double delta) { + } public void ClearDecorations() @@ -62,14 +64,14 @@ public partial class Layer : Node3D { Vector3 position; float offsetX; - float offsetY = level * 4 * -1; + float offsetY = level * GameData.tileHeight * -1; float offsetZ; for (int x = 0; x < layerSize; x++) { - offsetX = x * 6; + offsetX = x * GameData.tileWidth; for (int y = 0; y < layerSize; y++) { - offsetZ = y * 6; + offsetZ = y * GameData.tileWidth; position = new Vector3(offsetX, offsetY, offsetZ); tile = new Tile(); tile.SetMeshes(tileMeshes); @@ -120,7 +122,7 @@ public partial class Layer : Node3D if (possibilities.Count == 0) continue; - tile.Collapse(possibilities[rand.Next(possibilities.Count)]); + tile.Collapse(possibilities[GameData.rand.Next(possibilities.Count)]); Propagate(new Vector2I(x, z)); } } @@ -136,14 +138,15 @@ public partial class Layer : Node3D int posX, posY; while (true) { - posX = rand.Next(layerSize); - posY = rand.Next(layerSize); + posX = GameData.rand.Next(layerSize); + posY = GameData.rand.Next(layerSize); if (tiles[posX, posY].collapsedMesh != null) continue; if (tiles[posX, posY].tileMeshes.ContainsKey("gate")) { tiles[posX, posY].Collapse("gate"); gateCoordinate = new Vector2I(posX, posY); + GD.Print(gateCoordinate); Propagate(gateCoordinate); break; } diff --git a/Scripts/WorldGeneration/ResourceDistributor.cs b/Scripts/WorldGeneration/ResourceDistributor.cs new file mode 100644 index 0000000..5000c26 --- /dev/null +++ b/Scripts/WorldGeneration/ResourceDistributor.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using System.Linq; +using Godot; + +public class ResourceDistributor +{ + public static List resourceNames = new() + { + "Iron ore", + "Stone", + "Copper ore", + "Spiderweb", + "Mushroom", + "Tin ore" + }; + + public static string GetResource(List current) + { + List diff = resourceNames.Except(current).ToList(); + if (diff.Count <= 0) + { + return resourceNames[GameData.rand.Next(resourceNames.Count)]; + } + else + { + return diff[GameData.rand.Next(diff.Count)]; + } + } +} \ No newline at end of file diff --git a/Scripts/WorldGeneration/ResourceDistributor.cs.uid b/Scripts/WorldGeneration/ResourceDistributor.cs.uid new file mode 100644 index 0000000..f41bf33 --- /dev/null +++ b/Scripts/WorldGeneration/ResourceDistributor.cs.uid @@ -0,0 +1 @@ +uid://fao1lrpbrhuc diff --git a/Scripts/WorldGeneration/Tile.cs b/Scripts/WorldGeneration/Tile.cs index 73bb48e..e898cf8 100644 --- a/Scripts/WorldGeneration/Tile.cs +++ b/Scripts/WorldGeneration/Tile.cs @@ -7,12 +7,12 @@ public partial class Tile { public Dictionary tileMeshes; public string collapsedMesh; - Random rand = new Random(); public Vector3 Position; public Vector2I GridPosition; public Node3D ContentNode; public bool containsLight, containsDecoration, containsResource; + public GameResource resource; public void SetMeshes(Dictionary tileMeshes) @@ -38,7 +38,7 @@ public partial class Tile totalWeight += WFC.weights[tile]; } - float r = (float)(rand.NextDouble() * totalWeight); + float r = (float)(GameData.rand.NextDouble() * totalWeight); float cumulative = 0f; diff --git a/Scripts/WorldGeneration/WFC.cs b/Scripts/WorldGeneration/WFC.cs index 33448ae..5283bce 100644 --- a/Scripts/WorldGeneration/WFC.cs +++ b/Scripts/WorldGeneration/WFC.cs @@ -6,7 +6,6 @@ using Godot; public class WFC { public static Dictionary>> adjacency = new Dictionary>>(); - public static Random rand = new Random(); public enum Direction { Backward, @@ -217,7 +216,7 @@ public class WFC while (true) { if (toCheck.Count <= 0) break; - int index = rand.Next(toCheck.Count); + int index = GameData.rand.Next(toCheck.Count); position = toCheck[index]; toCheck[index] = toCheck[^1]; toCheck.RemoveAt(toCheck.Count - 1); diff --git a/Scripts/WorldGeneration/World.cs b/Scripts/WorldGeneration/World.cs index dfc0e0d..0efddf5 100644 --- a/Scripts/WorldGeneration/World.cs +++ b/Scripts/WorldGeneration/World.cs @@ -6,7 +6,6 @@ using static GameData; public partial class World : Node3D { - Random rand = new Random(); public Dictionary tileMeshes; public Dictionary contentMeshes; public Dictionary> tilePlaceholders; @@ -179,6 +178,8 @@ public partial class World : Node3D posY = rand.Next(layerSize); 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.currentResources.Add(layer.tiles[posX, posY].resource.name); currentResource++; } }