servicepoint-tanks/tanks-backend/TanksServer/Models/Tank.cs

35 lines
804 B
C#
Raw Normal View History

2024-04-12 18:32:10 +02:00
using System.Diagnostics;
2024-04-17 19:34:19 +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-29 16:59:37 +02:00
internal sealed class Tank : 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-29 16:59:37 +02:00
public required Player Owner { get; init; }
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-22 19:44:28 +02:00
public bool Moving { get; set; }
2024-04-29 16:59:37 +02:00
public required FloatPosition Position { get; set; }
2024-04-17 19:34:19 +02:00
public PixelBounds Bounds => Position.GetBoundsForCenter(MapService.TileSize);
2024-04-13 18:35:36 +02:00
public int Orientation => (int)Math.Round(Rotation * 16) % 16;
2024-04-29 16:59:37 +02:00
public required Magazine Magazine { get; set; }
}