add explosive bullet power up

This commit is contained in:
Vinzenz Schroeter 2024-04-17 19:34:19 +02:00
parent 3f4a301993
commit a2d46bda92
30 changed files with 407 additions and 253 deletions

View file

@ -1,12 +1,14 @@
namespace TanksServer.Models;
internal sealed class Bullet(Player tankOwner, FloatPosition position, double rotation) : IMapEntity
internal sealed class Bullet(Player tankOwner, FloatPosition position, double rotation, bool isExplosive) : IMapEntity
{
public Player Owner { get; } = tankOwner;
public double Rotation { get; set; } = rotation;
public double Rotation { get; } = rotation;
public FloatPosition Position { get; set; } = position;
public bool IsExplosive { get; } = isExplosive;
public PixelBounds Bounds => new (Position.ToPixelPosition(), Position.ToPixelPosition());
}

View file

@ -28,4 +28,15 @@ internal static class PositionHelpers
Math.Pow(p1.X - p2.X, 2) +
Math.Pow(p1.Y - p2.Y, 2)
);
public static PixelBounds GetBoundsForCenter(this FloatPosition position, ushort size)
{
var sub = (short)(-size / 2d);
var add = (short)(size / 2d - 1);
var pixelPosition = position.ToPixelPosition();
return new PixelBounds(
pixelPosition.GetPixelRelative(sub, sub),
pixelPosition.GetPixelRelative(add, add)
);
}
}

View file

@ -0,0 +1,10 @@
using TanksServer.GameLogic;
namespace TanksServer.Models;
internal sealed class PowerUp(FloatPosition position): IMapEntity
{
public FloatPosition Position { get; set; } = position;
public PixelBounds Bounds => Position.GetBoundsForCenter(MapService.TileSize);
}

View file

@ -1,4 +1,5 @@
using System.Diagnostics;
using TanksServer.GameLogic;
namespace TanksServer.Models;
@ -25,16 +26,9 @@ internal sealed class Tank(Player player, FloatPosition spawnPosition) : IMapEnt
public FloatPosition Position { get; set; } = spawnPosition;
public PixelBounds Bounds => GetBoundsForCenter(Position);
public PixelBounds Bounds => Position.GetBoundsForCenter(MapService.TileSize);
public int Orientation => (int)Math.Round(Rotation * 16) % 16;
public static PixelBounds GetBoundsForCenter(FloatPosition position)
{
var pixelPosition = position.ToPixelPosition();
return new PixelBounds(
pixelPosition.GetPixelRelative(-4, -4),
pixelPosition.GetPixelRelative(3, 3)
);
}
public byte ExplosiveBullets { get; set; }
}