2024-04-17 19:34:19 +02:00
|
|
|
using TanksServer.GameLogic;
|
|
|
|
|
|
|
|
namespace TanksServer.Graphics;
|
|
|
|
|
2024-04-22 20:58:12 +02:00
|
|
|
internal sealed class DrawPowerUpsStep(MapEntityManager entityManager) : IDrawStep
|
2024-04-17 19:34:19 +02:00
|
|
|
{
|
2024-05-03 16:45:35 +02:00
|
|
|
private readonly Sprite _genericSprite = Sprite.FromImageFile("assets/powerup_generic.png");
|
2024-05-03 16:43:15 +02:00
|
|
|
private readonly Sprite _smartSprite = Sprite.FromImageFile("assets/powerup_smart.png");
|
2024-05-04 14:34:06 +02:00
|
|
|
private readonly Sprite _magazineSprite = Sprite.FromImageFile("assets/powerup_magazine.png");
|
2024-05-04 14:36:53 +02:00
|
|
|
private readonly Sprite _explosiveSprite = Sprite.FromImageFile("assets/powerup_explosive.png");
|
2024-04-17 19:34:19 +02:00
|
|
|
|
|
|
|
public void Draw(GamePixelGrid pixels)
|
|
|
|
{
|
2024-04-22 20:58:12 +02:00
|
|
|
foreach (var powerUp in entityManager.PowerUps)
|
2024-04-17 19:34:19 +02:00
|
|
|
{
|
2024-05-03 16:45:35 +02:00
|
|
|
var sprite = powerUp switch
|
|
|
|
{
|
2024-05-04 14:34:06 +02:00
|
|
|
{ Type: PowerUpType.MagazineSize } => _magazineSprite,
|
2024-05-03 16:45:35 +02:00
|
|
|
{ Type: PowerUpType.MagazineType, MagazineType: MagazineType.Smart } => _smartSprite,
|
2024-05-04 14:36:53 +02:00
|
|
|
{ Type: PowerUpType.MagazineType, MagazineType: MagazineType.Explosive } => _explosiveSprite,
|
2024-05-03 16:45:35 +02:00
|
|
|
_ => _genericSprite
|
|
|
|
};
|
2024-04-17 19:34:19 +02:00
|
|
|
|
2024-05-03 16:43:15 +02:00
|
|
|
DrawPowerUp(pixels, sprite, powerUp.Bounds.TopLeft);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void DrawPowerUp(GamePixelGrid pixels, Sprite sprite, PixelPosition position)
|
|
|
|
{
|
|
|
|
for (byte dy = 0; dy < MapService.TileSize; dy++)
|
|
|
|
for (byte dx = 0; dx < MapService.TileSize; dx++)
|
|
|
|
{
|
|
|
|
var pixelState = sprite[dx, dy];
|
|
|
|
if (!pixelState.HasValue)
|
|
|
|
continue;
|
2024-04-17 19:34:19 +02:00
|
|
|
|
2024-05-03 16:43:15 +02:00
|
|
|
var (x, y) = position.GetPixelRelative(dx, dy);
|
|
|
|
pixels[x, y].EntityType = pixelState.Value
|
|
|
|
? GamePixelEntityType.PowerUp
|
|
|
|
: null;
|
2024-04-17 19:34:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|