position is now center, socket improvements

This commit is contained in:
Vinzenz Schroeter 2024-04-13 14:07:14 +02:00
parent 40eba7a7c7
commit d4d0abd013
18 changed files with 134 additions and 106 deletions

View file

@ -1,16 +0,0 @@
using DisplayCommands;
using TanksServer.GameLogic;
namespace TanksServer.Graphics;
internal sealed class BulletDrawer(BulletManager bullets) : IDrawStep
{
public void Draw(PixelGrid buffer)
{
foreach (var bullet in bullets.GetAll())
{
var pos = bullet.Position.ToPixelPosition();
buffer[pos.X, pos.Y] = true;
}
}
}

View file

@ -0,0 +1,13 @@
using DisplayCommands;
using TanksServer.GameLogic;
namespace TanksServer.Graphics;
internal sealed class DrawBulletsStep(BulletManager bullets) : IDrawStep
{
public void Draw(PixelGrid buffer)
{
foreach (var position in bullets.GetAll().Select(b => b.Position.ToPixelPosition()))
buffer[position.X, position.Y] = true;
}
}

View file

@ -3,7 +3,7 @@ using TanksServer.GameLogic;
namespace TanksServer.Graphics;
internal sealed class MapDrawer(MapService map) : IDrawStep
internal sealed class DrawMapStep(MapService map) : IDrawStep
{
public void Draw(PixelGrid buffer)
{
@ -22,4 +22,4 @@ internal sealed class MapDrawer(MapService map) : IDrawStep
}
}
}
}
}

View file

@ -5,13 +5,13 @@ using TanksServer.GameLogic;
namespace TanksServer.Graphics;
internal sealed class TankDrawer : IDrawStep
internal sealed class DrawTanksStep : IDrawStep
{
private readonly TankManager _tanks;
private readonly bool[] _tankSprite;
private readonly int _tankSpriteWidth;
public TankDrawer(TankManager tanks)
public DrawTanksStep(TankManager tanks)
{
_tanks = tanks;
@ -22,9 +22,7 @@ internal sealed class TankDrawer : IDrawStep
var i = 0;
for (var y = 0; y < tankImage.Height; y++)
for (var x = 0; x < tankImage.Width; x++, i++)
{
_tankSprite[i] = tankImage[x, y] == whitePixel;
}
_tankSpriteWidth = tankImage.Width;
}
@ -33,7 +31,7 @@ internal sealed class TankDrawer : IDrawStep
{
foreach (var tank in _tanks)
{
var tankPosition = tank.Position.ToPixelPosition();
var tankPosition = tank.Bounds.TopLeft;
var orientation = (int)Math.Round(tank.Rotation * 16d) % 16;
for (byte dy = 0; dy < MapService.TileSize; dy++)
@ -56,4 +54,4 @@ internal sealed class TankDrawer : IDrawStep
return _tankSprite[index];
}
}
}

View file

@ -3,8 +3,9 @@ using TanksServer.GameLogic;
namespace TanksServer.Graphics;
internal sealed class DrawStateToFrame(
IEnumerable<IDrawStep> drawSteps, LastFinishedFrameProvider lastFrameProvider
internal sealed class GeneratePixelsTickStep(
IEnumerable<IDrawStep> drawSteps,
LastFinishedFrameProvider lastFrameProvider
) : ITickStep
{
private readonly List<IDrawStep> _drawSteps = drawSteps.ToList();