servicepoint-tanks/TanksServer/Models/Tank.cs

35 lines
882 B
C#
Raw Normal View History

2024-04-07 21:09:36 +02:00
using TanksServer.Services;
2024-04-07 13:02:49 +02:00
namespace TanksServer.Models;
2024-04-07 17:17:11 +02:00
internal sealed class Tank(Player player, FloatPosition spawnPosition)
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
2024-04-07 18:18:26 +02:00
/// <summary>
/// Bounds: 0 (inclusive) .. 16 (exclusive)
/// </summary>
2024-04-07 17:17:11 +02:00
public double Rotation
{
get => _rotation;
2024-04-07 18:18:26 +02:00
set => _rotation = (value + 16d) % 16d;
2024-04-07 17:17:11 +02:00
}
public FloatPosition Position { get; set; } = spawnPosition;
2024-04-07 21:09:36 +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; }
2024-04-07 21:09:36 +02:00
public (FloatPosition TopLeft, FloatPosition BottomRight) GetBounds()
{
const int halfTile = MapService.TileSize / 2;
return (
new FloatPosition(Position.X - halfTile, Position.Y - halfTile),
new FloatPosition(Position.X + halfTile, Position.Y + halfTile)
);
}
2024-04-07 13:02:49 +02:00
}