servicepoint-tanks/TanksServer/GameLogic/MoveBullets.cs

22 lines
615 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-12 18:32:10 +02:00
internal sealed class MoveBullets(BulletManager bullets, IOptions<TanksConfiguration> config) : ITickStep
2024-04-07 19:52:16 +02:00
{
public Task TickAsync()
{
foreach (var bullet in bullets.GetAll())
MoveBullet(bullet);
return Task.CompletedTask;
}
2024-04-12 18:32:10 +02:00
private void MoveBullet(Bullet bullet)
2024-04-07 19:52:16 +02:00
{
2024-04-12 18:32:10 +02:00
var angle = bullet.Rotation * 2 * Math.PI;
2024-04-07 19:52:16 +02:00
bullet.Position = new FloatPosition(
2024-04-13 12:33:08 +02:00
bullet.Position.X + Math.Sin(angle) * config.Value.BulletSpeed,
bullet.Position.Y - Math.Cos(angle) * config.Value.BulletSpeed
2024-04-07 19:52:16 +02:00
);
}
2024-04-13 14:08:51 +02:00
}