wip client "secret"

This commit is contained in:
Vinzenz Schroeter 2024-04-13 18:35:36 +02:00
parent 698271ae9f
commit b192cd7da0
15 changed files with 117 additions and 71 deletions

View file

@ -2,17 +2,15 @@ using System.Text.Json.Serialization;
namespace TanksServer.Models;
internal sealed class Player(string name)
internal sealed class Player(string name, Guid id)
{
public string Name => name;
public Guid Id { get; } = Guid.NewGuid();
[JsonIgnore] public Guid Id => id;
[JsonIgnore] public PlayerControls Controls { get; } = new();
public int Kills { get; set; }
public int Deaths { get; set; }
public Scores Scores { get; } = new();
public DateTime LastInput { get; set; } = DateTime.Now;
}

View file

@ -23,8 +23,8 @@ internal static class PositionHelpers
public static FloatPosition ToFloatPosition(this PixelPosition position) => new(position.X, position.Y);
public static double Distance(this FloatPosition p1, FloatPosition p2) =>
Math.Sqrt(
public static double Distance(this FloatPosition p1, FloatPosition p2)
=> Math.Sqrt(
Math.Pow(p1.X - p2.X, 2) +
Math.Pow(p1.Y - p2.Y, 2)
);

View file

@ -0,0 +1,8 @@
namespace TanksServer.Models;
internal sealed record class Scores(int Kills = 0, int Deaths = 0)
{
public int Kills { get; set; } = Kills;
public int Deaths { get; set; } = Deaths;
}

View file

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