experiments-monogame/Lighthouse/Lighthouse/Components/Minimap.cs
2024-12-16 21:27:11 -06:00

66 lines
2.2 KiB
C#

using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Nez;
namespace Lighthouse
{
public class Minimap : RenderableComponent, IUpdatable
{
private Texture2D _texture;
private Texture2D _shroudTex;
private Color[] _shroudData;
private readonly World _world;
public override float Width => 100;
public override float Height => 100;
public Minimap(World world)
{
_world = world;
_shroudTex = Graphics.CreateSingleColorTexture(1000, 1000, Color.Black);
_shroudData = new Color[1000*1000];
_texture = Graphics.CreateSingleColorTexture(1000, 1000, Color.Black);
var data = new Color[1000*1000];
var colors = new Dictionary<string, Color>();
colors["water"] = new Color(0, 100, 200);
colors["ground"] = new Color(0, 200, 0);
colors["wall"] = new Color(128, 128, 128);
colors[""] = new Color(255, 0, 0);
for (var x = 0; x < 1000; x++)
{
for (var y = 0; y < 1000; y++)
{
_shroudData[x+y*1000] = Color.Black;
data[x+y*1000] = colors[world.GetTileType(x, y)];
}
}
_texture.SetData(data);
LayerDepth = 0.2f;
}
public void Update()
{
for (var x = _world.Player.X-20; x < _world.Player.X+20; x++)
{
for (var y = _world.Player.Y-10; y < _world.Player.Y+10; y++)
{
_shroudData[x + y * 1000] = new Color(0, 0, 0, 0);
}
}
_shroudTex.SetData(_shroudData);
}
public override void Render(Batcher batcher, Camera camera)
{
batcher.Draw(_texture, new Rectangle(540, 260, 100, 100),
new Rectangle(_world.Player.X-50, _world.Player.Y-50, 100, 100),
Color.White
);
batcher.Draw(_shroudTex, new Rectangle(540, 260, 100, 100),
new Rectangle(_world.Player.X-50, _world.Player.Y-50, 100, 100),
Color.White
);
}
}
}