servicepoint-tanks/TanksServer/GameLogic/MoveBullets.cs

26 lines
705 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-17 19:34:19 +02:00
internal sealed class MoveBullets(
MapEntityManager entityManager,
IOptions<TanksConfiguration> config
) : ITickStep
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 bullet in entityManager.Bullets)
2024-04-16 19:40:08 +02:00
MoveBullet(bullet, delta);
2024-04-07 19:52:16 +02:00
return Task.CompletedTask;
}
2024-04-16 19:40:08 +02:00
private void MoveBullet(Bullet bullet, TimeSpan delta)
2024-04-07 19:52:16 +02:00
{
2024-04-16 19:40:08 +02:00
var speed = config.Value.BulletSpeed * delta.TotalSeconds;
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-16 19:40:08 +02:00
bullet.Position.X + Math.Sin(angle) * speed,
bullet.Position.Y - Math.Cos(angle) * speed
2024-04-07 19:52:16 +02:00
);
}
2024-04-13 14:08:51 +02:00
}