delta time
This commit is contained in:
parent
dec571d8c1
commit
e16d4b1c1f
1 changed files with 29 additions and 28 deletions
|
|
@ -2,20 +2,21 @@ namespace TanksServer.GameLogic;
|
|||
|
||||
internal sealed class MoveBullets(BulletManager bullets, IOptions<TanksConfiguration> config) : ITickStep
|
||||
{
|
||||
public Task TickAsync()
|
||||
public Task TickAsync(TimeSpan delta)
|
||||
{
|
||||
foreach (var bullet in bullets.GetAll())
|
||||
MoveBullet(bullet);
|
||||
MoveBullet(bullet, delta);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private void MoveBullet(Bullet bullet)
|
||||
private void MoveBullet(Bullet bullet, TimeSpan delta)
|
||||
{
|
||||
var speed = config.Value.BulletSpeed * delta.TotalSeconds;
|
||||
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
|
||||
bullet.Position.X + Math.Sin(angle) * speed,
|
||||
bullet.Position.Y - Math.Cos(angle) * speed
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue