sprite helper classes
This commit is contained in:
parent
83ee185c50
commit
a486f73046
5 changed files with 82 additions and 52 deletions
|
@ -1,37 +1,14 @@
|
|||
using System.Diagnostics;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using TanksServer.GameLogic;
|
||||
|
||||
namespace TanksServer.Graphics;
|
||||
|
||||
internal sealed class DrawPowerUpsStep : IDrawStep
|
||||
internal sealed class DrawPowerUpsStep(MapEntityManager entityManager) : IDrawStep
|
||||
{
|
||||
private readonly MapEntityManager _entityManager;
|
||||
private readonly bool?[,] _explosiveSprite;
|
||||
|
||||
public DrawPowerUpsStep(MapEntityManager entityManager)
|
||||
{
|
||||
_entityManager = entityManager;
|
||||
|
||||
using var tankImage = Image.Load<Rgba32>("assets/powerup_explosive.png");
|
||||
Debug.Assert(tankImage.Width == tankImage.Height && tankImage.Width == MapService.TileSize);
|
||||
_explosiveSprite = new bool?[tankImage.Width, tankImage.Height];
|
||||
|
||||
var whitePixel = new Rgba32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
|
||||
for (var y = 0; y < tankImage.Height; y++)
|
||||
for (var x = 0; x < tankImage.Width; x++)
|
||||
{
|
||||
var pixelValue = tankImage[x, y];
|
||||
_explosiveSprite[x, y] = pixelValue.A == 0
|
||||
? null
|
||||
: pixelValue == whitePixel;
|
||||
}
|
||||
}
|
||||
private readonly Sprite _explosiveSprite = Sprite.FromImageFile("assets/powerup_explosive.png");
|
||||
|
||||
public void Draw(GamePixelGrid pixels)
|
||||
{
|
||||
foreach (var powerUp in _entityManager.PowerUps)
|
||||
foreach (var powerUp in entityManager.PowerUps)
|
||||
{
|
||||
var position = powerUp.Bounds.TopLeft;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue