servicepoint-tanks/TanksServer/GameLogic/MoveBullets.cs
Vinzenz Schroeter 1f0e6ba8fa formatting
2024-04-13 14:08:51 +02:00

22 lines
615 B
C#

namespace TanksServer.GameLogic;
internal sealed class MoveBullets(BulletManager bullets, IOptions<TanksConfiguration> config) : ITickStep
{
public Task TickAsync()
{
foreach (var bullet in bullets.GetAll())
MoveBullet(bullet);
return Task.CompletedTask;
}
private void MoveBullet(Bullet bullet)
{
var angle = bullet.Rotation * 2 * Math.PI;
bullet.Position = new FloatPosition(
bullet.Position.X + Math.Sin(angle) * config.Value.BulletSpeed,
bullet.Position.Y - Math.Cos(angle) * config.Value.BulletSpeed
);
}
}