2024-04-17 19:34:19 +02:00
|
|
|
namespace TanksServer.GameLogic;
|
|
|
|
|
|
|
|
internal sealed class CollectPowerUp(
|
|
|
|
MapEntityManager entityManager
|
|
|
|
) : ITickStep
|
|
|
|
{
|
2024-04-28 15:34:32 +02:00
|
|
|
public ValueTask TickAsync(TimeSpan delta)
|
2024-04-17 19:34:19 +02:00
|
|
|
{
|
|
|
|
entityManager.RemoveWhere(TryCollect);
|
2024-04-28 15:34:32 +02:00
|
|
|
return ValueTask.CompletedTask;
|
2024-04-17 19:34:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private bool TryCollect(PowerUp obj)
|
|
|
|
{
|
|
|
|
var position = obj.Position;
|
|
|
|
foreach (var tank in entityManager.Tanks)
|
|
|
|
{
|
|
|
|
var (topLeft, bottomRight) = tank.Bounds;
|
|
|
|
if (position.X < topLeft.X || position.X > bottomRight.X ||
|
|
|
|
position.Y < topLeft.Y || position.Y > bottomRight.Y)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// this works because now the tank overlaps the power up
|
|
|
|
tank.ExplosiveBullets += 10;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|