Added basic symbols for most of the resources and changed map to be revealed whilst robots are exploring.

This commit is contained in:
=
2026-04-29 19:19:13 +02:00
parent c54ff3088e
commit 95455597da
25 changed files with 350 additions and 24 deletions
+20 -2
View File
@@ -1,3 +1,4 @@
using System;
using Godot;
using static GameData;
@@ -7,14 +8,31 @@ public partial class Camera3d : Camera3D
[Export] public float MouseSensitivity = 0.2f;
[Export] public float ScrollStrength = 5.0f;
private bool isShowingMap = false;
private Vector3 previousPosition;
private Vector2 _mouseDelta;
public override void _Process(double delta)
{
if (canMove) MoveCamera(delta);
if (Input.IsActionJustPressed("map"))
{
isShowingMap = !isShowingMap;
canMove = !isShowingMap;
if (isShowingMap)
{
previousPosition = Position;
Position = new Vector3(layerSize * tileWidth / 2 - tileWidth / 2, 90 - visibleLayer * 4, layerSize * tileWidth / 2 - tileWidth / 2);
RotationDegrees = new Vector3(-90, 0, 0);
}
else
{
Position = previousPosition;
RotationDegrees = new Vector3(-75, 0, 0);
}
if (!canMove) return;
}
}
public void MoveCamera(double delta)
+2
View File
@@ -22,6 +22,8 @@ public class MoveNode : ProgramNode
if (distance < 0.1f)
{
robot.Position = pathPoints[0];
Vector3I mapIndex = Pathfinding.GetClosestStartPoint(robot.Position);
GameData.map[mapIndex.Y].tiles[mapIndex.X, mapIndex.Z].wasVisited = true;
pathPoints.Remove(pathPoints[0]);
if (pathPoints.Count <= 0)
{
+13
View File
@@ -56,4 +56,17 @@ public partial class ResourceLoader
};
return nodes;
}
public static Dictionary<string, Texture2D> LoadResourceSymbols()
{
Dictionary<string, Texture2D> symbols = new()
{
{ "Iron ore", GD.Load<Texture2D>($"res://Assets/IronSymbol.png") },
{ "Tin ore", GD.Load<Texture2D>($"res://Assets/TinSymbol.png") },
{ "Copper ore", GD.Load<Texture2D>($"res://Assets/CopperSymbol.png") },
{ "Mushroom", GD.Load<Texture2D>($"res://Assets/MushroomSymbol.png") },
{ "Spiderweb", GD.Load<Texture2D>($"res://Assets/SpiderwebSymbol.png") },
};
return symbols;
}
}
+10
View File
@@ -8,6 +8,7 @@ public partial class UIHandler : Control
[Export] RobotList robotList;
[Export] Information information;
[Export] Camera3D mainCam;
[Export] Map map;
public override void _Ready()
{
GetNode<ColorPickerButton>("./MainUI/HeaderContainer/Header/LightColor").Color = GameData.lightColor;
@@ -21,6 +22,15 @@ public partial class UIHandler : Control
mainCam.Position = new Vector3(robot.Position.X, mainCam.Position.Y, robot.Position.Z + 3f);
ShowCodingWindow(robot);
};
if (Input.IsActionJustPressed("map"))
{
map.Visible = !map.Visible;
if (map.Visible)
{
map.ShowMap();
}
}
}
public void ChangeColor(Color color)
+70
View File
@@ -0,0 +1,70 @@
using Godot;
using System;
public partial class Map : PanelContainer
{
[Export] GridContainer grid;
// 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)
{
//TODO: This has to be temporary! Drawing each frame is way too expensive.
if (Visible)
{
ShowMap();
}
}
public void ShowMap()
{
grid.Columns = GameData.layerSize;
grid.AddThemeConstantOverride("h_separation", (int)(GameData.tileWidth * 2.5f));
grid.AddThemeConstantOverride("v_separation", (int)(GameData.tileWidth * 2.5f));
foreach (Node node in grid.GetChildren())
{
grid.RemoveChild(node);
node.QueueFree();
}
TextureRect texture;
Tile[,] tiles = GameData.map[GameData.currentLayer].tiles;
for (int z = 0; z < GameData.layerSize; z++)
{
for (int x = 0; x < GameData.layerSize; x++)
{
texture = new TextureRect();
if (tiles[x, z].wasVisited)
{
if (tiles[x, z].containsResource)
{
texture.Texture = ResourceDistributor.resources[tiles[x, z].resource.name];
}
else
{
texture.Texture = GenerateTexture(32, new Color(0,0,0,0));
}
}
else
{
texture.Texture = GenerateTexture(32, new Color(0,0,0,1));
}
grid.AddChild(texture);
}
}
}
public Texture2D GenerateTexture(int size, Color fillColor)
{
Image image = Image.CreateEmpty(size, size, false, Image.Format.Rgba8);
image.Fill(fillColor);
return ImageTexture.CreateFromImage(image);
}
}
+1
View File
@@ -0,0 +1 @@
uid://fegfbcnlk8p5
+3 -11
View File
@@ -4,22 +4,14 @@ using Godot;
public class ResourceDistributor
{
public static List<string> resourceNames = new()
{
"Iron ore",
"Stone",
"Copper ore",
"Spiderweb",
"Mushroom",
"Tin ore"
};
public static Dictionary<string, Texture2D> resources = ResourceLoader.LoadResourceSymbols();
public static string GetResource(List<string> current)
{
List<string> diff = resourceNames.Except(current).ToList();
List<string> diff = resources.Keys.Except(current).ToList();
if (diff.Count <= 0)
{
return resourceNames[GameData.rand.Next(resourceNames.Count)];
return resources.Keys.ToList()[GameData.rand.Next(resources.Keys.Count)];
}
else
{
+1
View File
@@ -13,6 +13,7 @@ public partial class Tile
public bool containsLight, containsDecoration, containsResource;
public GameResource resource;
public bool wasVisited;
public void SetMeshes(Dictionary<string, MeshInstance3D> tileMeshes)