2024-04-10 19:25:45 +02:00
|
|
|
namespace TanksServer.GameLogic;
|
2024-04-07 19:52:16 +02:00
|
|
|
|
|
|
|
internal sealed class CollideBulletsWithMap(BulletManager bullets, MapService map) : ITickStep
|
|
|
|
{
|
2024-04-16 19:40:08 +02:00
|
|
|
public Task TickAsync(TimeSpan _)
|
2024-04-07 19:52:16 +02:00
|
|
|
{
|
2024-04-16 18:55:34 +02:00
|
|
|
bullets.RemoveWhere(TryHitAndDestroyWall);
|
2024-04-07 19:52:16 +02:00
|
|
|
return Task.CompletedTask;
|
|
|
|
}
|
|
|
|
|
2024-04-16 18:55:34 +02:00
|
|
|
private bool TryHitAndDestroyWall(Bullet bullet)
|
|
|
|
{
|
|
|
|
var pixel = bullet.Position.ToPixelPosition();
|
|
|
|
if (!map.Current.IsWall(pixel))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
map.Current.DestroyWallAt(pixel);
|
|
|
|
return true;
|
|
|
|
}
|
2024-04-07 19:52:16 +02:00
|
|
|
}
|