implement fast bullets
This commit is contained in:
parent
9ccb7c8df8
commit
9164d90443
7 changed files with 30 additions and 24 deletions
|
@ -6,6 +6,7 @@ internal sealed class MapEntityManager(
|
|||
IOptions<GameRules> options
|
||||
)
|
||||
{
|
||||
private readonly GameRules _rules = options.Value;
|
||||
private readonly HashSet<Bullet> _bullets = [];
|
||||
private readonly HashSet<PowerUp> _powerUps = [];
|
||||
private readonly Dictionary<Player, Tank> _playerTanks = [];
|
||||
|
@ -15,24 +16,31 @@ internal sealed class MapEntityManager(
|
|||
public IEnumerable<Tank> Tanks => _playerTanks.Values;
|
||||
public IEnumerable<PowerUp> PowerUps => _powerUps;
|
||||
|
||||
public void SpawnBullet(Player tankOwner, FloatPosition position, double rotation, bool isExplosive)
|
||||
=> _bullets.Add(new Bullet
|
||||
public void SpawnBullet(Player tankOwner, FloatPosition position, double rotation, MagazineType type)
|
||||
{
|
||||
var speed = _rules.BulletSpeed * (type.HasFlag(MagazineType.Fast) ? 2 : 1);
|
||||
_bullets.Add(new Bullet
|
||||
{
|
||||
Owner = tankOwner,
|
||||
Position = position,
|
||||
Rotation = rotation,
|
||||
IsExplosive = isExplosive,
|
||||
IsExplosive = type.HasFlag(MagazineType.Explosive),
|
||||
Timeout = DateTime.Now + _bulletTimeout,
|
||||
OwnerCollisionAfter = DateTime.Now + TimeSpan.FromSeconds(1),
|
||||
Speed = speed
|
||||
});
|
||||
}
|
||||
|
||||
public void RemoveWhere(Predicate<Bullet> predicate) => _bullets.RemoveWhere(predicate);
|
||||
|
||||
public void SpawnTank(Player player)
|
||||
{
|
||||
var tank = new Tank(player, ChooseSpawnPosition())
|
||||
var tank = new Tank
|
||||
{
|
||||
Rotation = Random.Shared.NextDouble()
|
||||
Owner = player,
|
||||
Position = ChooseSpawnPosition(),
|
||||
Rotation = Random.Shared.NextDouble(),
|
||||
Magazine = new Magazine(MagazineType.Basic, 0, _rules.MagazineSize)
|
||||
};
|
||||
_playerTanks[player] = tank;
|
||||
logger.LogInformation("Tank added for player {}", player.Name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue