servicepoint-tanks/tanks-backend/TanksServer/GameLogic/RotateTanks.cs

36 lines
1,014 B
C#
Raw Normal View History

2024-04-10 19:25:45 +02:00
namespace TanksServer.GameLogic;
2024-04-07 19:52:16 +02:00
2024-04-13 18:35:36 +02:00
internal sealed class RotateTanks(
2024-04-17 19:34:19 +02:00
MapEntityManager entityManager,
2024-04-19 13:37:28 +02:00
IOptions<GameRules> options,
2024-04-13 18:35:36 +02:00
ILogger<RotateTanks> logger
) : ITickStep
2024-04-07 19:52:16 +02:00
{
2024-04-19 13:37:28 +02:00
private readonly GameRules _config = options.Value;
2024-04-07 19:52:16 +02:00
2024-04-16 19:40:08 +02:00
public Task TickAsync(TimeSpan delta)
2024-04-07 19:52:16 +02:00
{
2024-04-17 19:34:19 +02:00
foreach (var tank in entityManager.Tanks)
2024-04-07 19:52:16 +02:00
{
var player = tank.Owner;
2024-04-13 18:35:36 +02:00
switch (player.Controls)
{
case { TurnRight: true, TurnLeft: true }:
case { TurnRight: false, TurnLeft: false }:
continue;
case { TurnLeft: true }:
2024-04-16 19:40:08 +02:00
tank.Rotation -= _config.TurnSpeed * delta.TotalSeconds;
2024-04-13 18:35:36 +02:00
break;
case { TurnRight: true }:
2024-04-16 19:40:08 +02:00
tank.Rotation += _config.TurnSpeed * delta.TotalSeconds;
2024-04-13 18:35:36 +02:00
break;
}
logger.LogTrace("rotated tank to {}", tank.Rotation);
2024-04-07 19:52:16 +02:00
}
return Task.CompletedTask;
}
}