servicepoint-tanks/tanks-backend/TanksServer/Graphics/DrawTanksStep.cs

30 lines
1,009 B
C#
Raw Permalink Normal View History

2024-04-10 19:25:45 +02:00
using TanksServer.GameLogic;
2024-04-10 19:25:45 +02:00
namespace TanksServer.Graphics;
2024-04-22 20:14:46 +02:00
internal sealed class DrawTanksStep(MapEntityManager entityManager) : IDrawStep
{
2024-04-22 20:58:12 +02:00
private readonly SpriteSheet _tankSprites =
SpriteSheet.FromImageFile("assets/tank.png", (int)MapService.TileSize, (int)MapService.TileSize);
public void Draw(GamePixelGrid pixels)
{
2024-04-22 20:14:46 +02:00
foreach (var tank in entityManager.Tanks)
{
var tankPosition = tank.Bounds.TopLeft;
2024-04-12 18:32:10 +02:00
for (byte dy = 0; dy < MapService.TileSize; dy++)
for (byte dx = 0; dx < MapService.TileSize; dx++)
{
var pixel = _tankSprites[tank.Orientation][dx, dy];
if (!pixel.HasValue || !pixel.Value)
continue;
var (x, y) = tankPosition.GetPixelRelative(dx, dy);
pixels[x, y].EntityType = GamePixelEntityType.Tank;
pixels[x, y].BelongsTo = tank.Owner;
}
}
}
}