respawn, fix hit box off by half tile
This commit is contained in:
parent
3c9192ab3a
commit
a89392beb8
|
@ -25,10 +25,9 @@ internal sealed class Tank(Player player, FloatPosition spawnPosition)
|
||||||
|
|
||||||
public (FloatPosition TopLeft, FloatPosition BottomRight) GetBounds()
|
public (FloatPosition TopLeft, FloatPosition BottomRight) GetBounds()
|
||||||
{
|
{
|
||||||
const int halfTile = MapService.TileSize / 2;
|
|
||||||
return (
|
return (
|
||||||
new FloatPosition(Position.X - halfTile, Position.Y - halfTile),
|
Position,
|
||||||
new FloatPosition(Position.X + halfTile, Position.Y + halfTile)
|
new FloatPosition(Position.X + MapService.TileSize , Position.Y + MapService.TileSize )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,9 @@ using TanksServer.Services;
|
||||||
|
|
||||||
namespace TanksServer.TickSteps;
|
namespace TanksServer.TickSteps;
|
||||||
|
|
||||||
internal sealed class CollideBulletsWithTanks(BulletManager bullets, TankManager tanks) : ITickStep
|
internal sealed class CollideBulletsWithTanks(
|
||||||
|
BulletManager bullets, TankManager tanks, SpawnQueueProvider spawnQueueProvider
|
||||||
|
) : ITickStep
|
||||||
{
|
{
|
||||||
public Task TickAsync()
|
public Task TickAsync()
|
||||||
{
|
{
|
||||||
|
@ -16,15 +18,17 @@ internal sealed class CollideBulletsWithTanks(BulletManager bullets, TankManager
|
||||||
foreach (var tank in tanks)
|
foreach (var tank in tanks)
|
||||||
{
|
{
|
||||||
var (topLeft, bottomRight) = tank.GetBounds();
|
var (topLeft, bottomRight) = tank.GetBounds();
|
||||||
if (bullet.Position.X <= topLeft.X || bullet.Position.X >= bottomRight.X ||
|
if (bullet.Position.X < topLeft.X || bullet.Position.X > bottomRight.X ||
|
||||||
bullet.Position.Y <= topLeft.Y || bullet.Position.Y >= bottomRight.Y)
|
bullet.Position.Y < topLeft.Y || bullet.Position.Y > bottomRight.Y)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (bullet.Owner != tank.Owner)
|
if (bullet.Owner != tank.Owner)
|
||||||
bullet.Owner.Kills++;
|
bullet.Owner.Kills++;
|
||||||
tank.Owner.Deaths++;
|
tank.Owner.Deaths++;
|
||||||
|
|
||||||
tanks.Remove(tank);
|
tanks.Remove(tank);
|
||||||
|
spawnQueueProvider.Queue.Enqueue(tank.Owner);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue