show tank infos in client
This commit is contained in:
parent
a50a9770c9
commit
0f4eec6343
9 changed files with 73 additions and 26 deletions
|
@ -11,13 +11,13 @@ internal sealed class CollideBullets(
|
|||
|
||||
public Task TickAsync(TimeSpan _)
|
||||
{
|
||||
entityManager.RemoveBulletsWhere(BulletHitsTank);
|
||||
entityManager.RemoveBulletsWhere(TryHitAndDestroyWall);
|
||||
entityManager.RemoveBulletsWhere(TimeoutBullet);
|
||||
entityManager.RemoveWhere(BulletHitsTank);
|
||||
entityManager.RemoveWhere(BulletHitsWall);
|
||||
entityManager.RemoveWhere(BulletTimesOut);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private bool TimeoutBullet(Bullet bullet)
|
||||
private bool BulletTimesOut(Bullet bullet)
|
||||
{
|
||||
if (bullet.Timeout > DateTime.Now)
|
||||
return false;
|
||||
|
@ -27,7 +27,7 @@ internal sealed class CollideBullets(
|
|||
return true;
|
||||
}
|
||||
|
||||
private bool TryHitAndDestroyWall(Bullet bullet)
|
||||
private bool BulletHitsWall(Bullet bullet)
|
||||
{
|
||||
var pixel = bullet.Position.ToPixelPosition();
|
||||
if (!map.Current.IsWall(pixel))
|
||||
|
|
|
@ -9,6 +9,7 @@ internal sealed class MapEntityManager(
|
|||
private readonly HashSet<Bullet> _bullets = [];
|
||||
private readonly HashSet<Tank> _tanks = [];
|
||||
private readonly HashSet<PowerUp> _powerUps = [];
|
||||
private readonly Dictionary<Player, Tank> _playerTanks = [];
|
||||
private readonly TimeSpan _bulletTimeout = TimeSpan.FromMilliseconds(options.Value.BulletTimeoutMs);
|
||||
|
||||
public IEnumerable<Bullet> Bullets => _bullets;
|
||||
|
@ -31,14 +32,16 @@ internal sealed class MapEntityManager(
|
|||
OwnerCollisionAfter = DateTime.Now + TimeSpan.FromSeconds(1),
|
||||
});
|
||||
|
||||
public void RemoveBulletsWhere(Predicate<Bullet> predicate) => _bullets.RemoveWhere(predicate);
|
||||
public void RemoveWhere(Predicate<Bullet> predicate) => _bullets.RemoveWhere(predicate);
|
||||
|
||||
public void SpawnTank(Player player)
|
||||
{
|
||||
_tanks.Add(new Tank(player, ChooseSpawnPosition())
|
||||
var tank = new Tank(player, ChooseSpawnPosition())
|
||||
{
|
||||
Rotation = Random.Shared.NextDouble()
|
||||
});
|
||||
};
|
||||
_tanks.Add(tank);
|
||||
_playerTanks[player] = tank;
|
||||
logger.LogInformation("Tank added for player {}", player.Id);
|
||||
}
|
||||
|
||||
|
@ -50,6 +53,7 @@ internal sealed class MapEntityManager(
|
|||
{
|
||||
logger.LogInformation("Tank removed for player {}", tank.Owner.Id);
|
||||
_tanks.Remove(tank);
|
||||
_playerTanks.Remove(tank.Owner);
|
||||
}
|
||||
|
||||
public FloatPosition ChooseSpawnPosition()
|
||||
|
@ -75,4 +79,6 @@ internal sealed class MapEntityManager(
|
|||
var min = candidates.MaxBy(pair => pair.Value).Key;
|
||||
return min.ToPixelPosition().GetPixelRelative(4, 4).ToFloatPosition();
|
||||
}
|
||||
|
||||
public Tank? GetCurrentTankOfPlayer(Player player) => _playerTanks.GetValueOrDefault(player);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ internal sealed class MoveTanks(
|
|||
public Task TickAsync(TimeSpan delta)
|
||||
{
|
||||
foreach (var tank in entityManager.Tanks)
|
||||
tank.Moved = TryMoveTank(tank, delta);
|
||||
tank.Moving = TryMoveTank(tank, delta);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ internal sealed class ShootFromTanks(
|
|||
|
||||
public Task TickAsync(TimeSpan _)
|
||||
{
|
||||
foreach (var tank in entityManager.Tanks.Where(t => !t.Moved))
|
||||
foreach (var tank in entityManager.Tanks.Where(t => !t.Moving))
|
||||
Shoot(tank);
|
||||
|
||||
return Task.CompletedTask;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue