Removed popup from the game, added simple options and menu. Added spawn to tiles and reworked content spawning

This commit is contained in:
=
2026-05-01 18:34:48 +02:00
parent 95455597da
commit dd81c2ff2e
13 changed files with 181 additions and 113 deletions
+5
View File
@@ -13,6 +13,11 @@ public partial class Camera3d : Camera3D
private Vector2 _mouseDelta;
public override void _Ready()
{
Position = new Vector3(0, 0, tileWidth/2);
}
public override void _Process(double delta)
{
if (canMove) MoveCamera(delta);
+7 -1
View File
@@ -7,9 +7,15 @@ public class LightHandler
public static void RedrawLights(Color color)
{
List<OmniLight3D> availableLights = new();
foreach(OmniLight3D light in lights)
{
light.LightColor = color;
if (GodotObject.IsInstanceValid(light))
{
light.LightColor = color;
availableLights.Add(light);
}
}
lights = [..availableLights];
}
}
+50 -2
View File
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Godot;
@@ -6,12 +7,16 @@ public partial class UIHandler : Control
{
[Export] CodingWindow codingWindow;
[Export] RobotList robotList;
[Export] Information information;
[Export] Camera3D mainCam;
[Export] Map map;
[Export] RichTextLabel FPS;
[Export] RichTextLabel RAM;
[Export] PanelContainer options;
[Export] Control uiContent;
[Export] PanelContainer menu;
public override void _Ready()
{
GetNode<ColorPickerButton>("./MainUI/HeaderContainer/Header/LightColor").Color = GameData.lightColor;
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
@@ -31,6 +36,31 @@ public partial class UIHandler : Control
map.ShowMap();
}
}
if (Input.IsActionJustPressed("menu"))
{
HandleMenu();
}
DisplayStats();
}
public void HandleMenu()
{
bool shouldMenuOpen = true;
foreach (PanelContainer element in uiContent.GetChildren())
{
if (element.Visible)
{
element.Visible = false;
shouldMenuOpen = false;
}
}
if (shouldMenuOpen)
{
menu.Visible = true;
}
}
public void ChangeColor(Color color)
@@ -43,4 +73,22 @@ public partial class UIHandler : Control
{
codingWindow.ShowWindow(robot);
}
public void DisplayStats()
{
FPS.Text = Engine.GetFramesPerSecond().ToString() + " FPS";
double memory = Process.GetCurrentProcess().WorkingSet64 / (1024 * 1024);
string memoryDisplay = memory > 1024 ? Math.Round(memory / 1024, 2).ToString() + " GB" : memory.ToString() + " MB";
RAM.Text = memoryDisplay;
}
public void ShowOptions()
{
options.Visible = true;
}
public void ExitGame()
{
GetTree().ChangeSceneToFile("res://Scenes/MainMenu.tscn");
}
}
-29
View File
@@ -1,29 +0,0 @@
using Godot;
using System;
public partial class Information : PanelContainer
{
[Export] RichTextLabel title;
[Export] RichTextLabel content;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
public void DisplayInformation(string title, string content)
{
this.title.Text = title;
this.content.Text = content;
Visible = true;
}
public void HideInformation()
{
Visible = false;
}
}
-1
View File
@@ -1 +0,0 @@
uid://c3v2vdj3ghp78
+12 -2
View File
@@ -29,7 +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()
@@ -113,6 +113,8 @@ public partial class Layer : Node3D
{
for (int z = 0; z < layerSize; z++)
{
//Exclude spawn from border generation
if(x == 0 && z == 0) continue;
if (!IsBorder(x, z))
continue;
@@ -135,6 +137,13 @@ public partial class Layer : Node3D
private void GenerateNecessaryTiles()
{
//Generate spawn only in the first layer
if (level == 0)
{
tiles[0,0].Collapse("spawn");
Propagate(new Vector2I());
}
//Randomly position the gate to the next layer
int posX, posY;
while (true)
{
@@ -146,11 +155,12 @@ public partial class Layer : Node3D
{
tiles[posX, posY].Collapse("gate");
gateCoordinate = new Vector2I(posX, posY);
GD.Print(gateCoordinate);
Propagate(gateCoordinate);
break;
}
}
}
public bool GenerateLayer(Vector2I collapseOrigin)
+1
View File
@@ -78,6 +78,7 @@ public partial class Tile
public void SpawnContent(Dictionary<string, MeshInstance3D> contentMeshes, Transform3D transform, List<Placeholder> placeholders)
{
if(!wasVisited) return;
foreach (Placeholder placeholder in placeholders)
{
if (containsLight && placeholder.name == "light") SpawnLight(contentMeshes["light"], placeholder, transform);
+5 -2
View File
@@ -66,7 +66,9 @@ public class WFC
["corner_down_right"] = new() { Direction.Forward, Direction.Right, Direction.Up },
["junction"] = new() { Direction.Backward, Direction.Forward, Direction.Left, Direction.Right, Direction.Up },
["gate"] = new() { Direction.Backward, Direction.Forward, Direction.Left, Direction.Right, Direction.Up, Direction.Down }
["gate"] = new() { Direction.Backward, Direction.Forward, Direction.Left, Direction.Right, Direction.Up, Direction.Down },
["spawn"] = new() { Direction.Forward, Direction.Left },
};
public static Dictionary<string, float> weights = new()
@@ -90,7 +92,8 @@ public class WFC
["end_left"] = 0.2f,
["end_right"] = 0.3f,
["gate"] = 0.0f
["gate"] = 0.0f,
["spawn"] = 0.0f
};
public static Direction Opposite(Direction dir)
+10 -1
View File
@@ -90,7 +90,7 @@ public partial class World : Node3D
{
Robot robot = ResourceLoader.LoadRobotPrefab().Instantiate<Robot>();
robot.Name = $"Robot #{robots.Count + 1}";
robot.Position = map[0].tiles[rand.Next(layerSize), rand.Next(layerSize)].Position;
robot.Position = map[0].tiles[0,0].Position;
AddChild(robot);
robots.Add(robot);
}
@@ -113,6 +113,15 @@ public partial class World : Node3D
map[layer] = layerNode;
}
map[0].tiles[0,0].wasVisited = true;
map[0].tiles[0,0].containsDecoration = true;
map[0].tiles[0,0].containsLight = true;
map[0].tiles[0,0].containsResource = false;
}
private void HandleTileVisit(int level)
{
HandleRenderData(BuildRenderData(level));
}
private List<TileRenderData> BuildRenderData(int layerIndex)