servicepoint-tanks/TanksServer/GameLogic/RotateTanks.cs
Vinzenz Schroeter 043022186f merge options
2024-04-19 13:37:28 +02:00

36 lines
1,014 B
C#

namespace TanksServer.GameLogic;
internal sealed class RotateTanks(
MapEntityManager entityManager,
IOptions<GameRules> options,
ILogger<RotateTanks> logger
) : ITickStep
{
private readonly GameRules _config = options.Value;
public Task TickAsync(TimeSpan delta)
{
foreach (var tank in entityManager.Tanks)
{
var player = tank.Owner;
switch (player.Controls)
{
case { TurnRight: true, TurnLeft: true }:
case { TurnRight: false, TurnLeft: false }:
continue;
case { TurnLeft: true }:
tank.Rotation -= _config.TurnSpeed * delta.TotalSeconds;
break;
case { TurnRight: true }:
tank.Rotation += _config.TurnSpeed * delta.TotalSeconds;
break;
}
logger.LogTrace("rotated tank to {}", tank.Rotation);
}
return Task.CompletedTask;
}
}