servicepoint-tanks/TanksServer/Models/Tank.cs

41 lines
1.1 KiB
C#
Raw Normal View History

2024-04-12 18:32:10 +02:00
using System.Diagnostics;
2024-04-10 19:25:45 +02:00
using TanksServer.GameLogic;
2024-04-07 21:09:36 +02:00
2024-04-07 13:02:49 +02:00
namespace TanksServer.Models;
2024-04-12 18:32:10 +02:00
internal sealed class Tank(Player player, FloatPosition spawnPosition) : IMapEntity
2024-04-07 13:02:49 +02:00
{
2024-04-07 17:17:11 +02:00
private double _rotation;
2024-04-07 18:18:26 +02:00
2024-04-07 13:02:49 +02:00
public Player Owner { get; } = player;
2024-04-07 17:17:11 +02:00
public double Rotation
{
get => _rotation;
2024-04-12 18:32:10 +02:00
set
{
var newRotation = (value % 1d + 1d) % 1d;
Debug.Assert(newRotation is >= 0 and < 1);
_rotation = newRotation;
}
2024-04-07 17:17:11 +02:00
}
public DateTime NextShotAfter { get; set; }
2024-04-07 21:09:36 +02:00
2024-04-07 19:52:16 +02:00
public bool Moved { get; set; }
public FloatPosition Position { get; set; } = spawnPosition;
public PixelBounds Bounds => GetBoundsForCenter(Position);
public static PixelBounds GetBoundsForCenter(FloatPosition position) => new(
new PixelPosition(
(ushort)(position.X - MapService.TileSize / 2d),
(ushort)(position.Y - MapService.TileSize / 2d)
), new PixelPosition(
(ushort)(position.X + MapService.TileSize / 2d - 1d),
(ushort)(position.Y + MapService.TileSize / 2d - 1d)
)
);
}