Added basic symbols for most of the resources and changed map to be revealed whilst robots are exploring.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://fegfbcnlk8p5
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user