servicepoint-tanks/TanksServer/GameLogic/CollideBulletsWithMap.cs

26 lines
625 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
internal sealed class CollideBulletsWithMap(
BulletManager bullets,
MapService map,
IOptions<GameRulesConfiguration> options
) : ITickStep
2024-04-07 19:52:16 +02:00
{
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;
if (options.Value.DestructibleWalls)
map.Current.DestroyWallAt(pixel);
2024-04-16 18:55:34 +02:00
return true;
}
2024-04-07 19:52:16 +02:00
}