servicepoint-tanks/TanksServer/Models/Tank.cs

41 lines
1 KiB
C#
Raw Normal View History

2024-04-12 18:32:10 +02:00
using System.Diagnostics;
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);
2024-04-13 18:35:36 +02:00
public int Orientation => (int)Math.Round(Rotation * 16) % 16;
2024-04-13 16:27:45 +02:00
public static PixelBounds GetBoundsForCenter(FloatPosition position)
{
var pixelPosition = position.ToPixelPosition();
return new PixelBounds(
2024-04-13 18:35:36 +02:00
pixelPosition.GetPixelRelative(-4, -4),
pixelPosition.GetPixelRelative(3, 3)
2024-04-13 16:27:45 +02:00
);
}
}