servicepoint-tanks/TanksServer/GameLogic/MoveBullets.cs
Vinzenz Schroeter 461a9139c2 infinite map
2024-04-12 18:32:10 +02:00

21 lines
620 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(
x: bullet.Position.X + Math.Sin(angle) * config.Value.BulletSpeed,
y: bullet.Position.Y - Math.Cos(angle) * config.Value.BulletSpeed
);
}
}