servicepoint-tanks/TanksServer/GameLogic/MoveBullets.cs
2024-04-13 12:33:08 +02:00

21 lines
614 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
);
}
}