/// <summary> /// Updates weapons currently in the game. /// </summary> /// <param name="elapsedTime"></param> public void Update(float elapsedTime) { _timer += elapsedTime; bool spriteRemoved = false; Equipment equipment; Weapon weapon; bool attacking; bool collisionCreated; foreach (Player player in _game.PlayerComponent.All) { equipment = _equipmentComponent[player.EntityID]; attacking = _playerInfoComponent[player.EntityID].State == PlayerState.Attacking; weapon = _weaponComponent[equipment.WeaponID]; collisionCreated = _collisionComponent.Contains(equipment.WeaponID); //Handle sprites if (_weaponSpriteComponent.Contains(player.EntityID)) { //If the player has a weapon sprite update it spriteRemoved = UpdateWeaponSprite(_weaponSpriteComponent[player.EntityID]); } else if (attacking) { //Otherwise create a new sprite and sound. _game.WeaponFactory.CreateWeaponSprite(equipment.WeaponID, equipment.EntityID); PlayWeaponSound(equipment.WeaponID); } //Handle more weapon logic. if (attacking) { if (weapon.AttackType == WeaponAttackType.Ranged) { _bulletTimer += elapsedTime; if (_bulletTimer >= weapon.Speed) { CreateBulletAndSprite(equipment.EntityID, equipment.WeaponID); _bulletTimer = 0; } } else { if (collisionCreated) { UpdateWeaponCollision(equipment.EntityID, equipment.WeaponID); } else { CreateWeaponCollision(equipment.EntityID, equipment.WeaponID); } } } else if (collisionCreated) //Not attacking but the collision box is there. { _collisionComponent.Remove(equipment.WeaponID); } } }
public void Update(GameTime gameTime) { foreach (var entity in _entities.Where(e => !e.IsDestroyed)) { entity.Update(gameTime); } _collisionSpace.Update(gameTime); foreach (var e in _entities.Where(e => e.IsDestroyed).ToList()) { _entities.Remove(e); if (e is ICollisionActor actor) { _collisionSpace.Remove(actor); } } }