/// <summary> /// Check if player have fallen in hole /// </summary> private void CheckIfInHole(ISoundObserver soundObserver) { if (m_level.IsInHole(m_player.Position, m_player.Size)) { m_player.RemoveLife(); soundObserver.PlayerFallInHole(); } }
/// <summary> /// Check if player have collided with bomb /// </summary> /// <param name="soundObserver"></param> private void CheckIfCollideWithBomb(ISoundObserver soundObserver) { foreach (Bomb bomb in m_bombsList) { if (CollisionHandler.IsCollidingWithBomb(m_player, bomb)) { m_player.RemoveLife(); soundObserver.BombExplode(); } } }
/// <summary> /// Check if player have collided with coin /// </summary> /// <param name="soundObserver"></param> private void CheckIfPlayerPickedUpCoin(ISoundObserver soundObserver, IPickUpObserver pickUpObserver) { for (int i = 0; i < m_coinList.Count; i++) { if (CollisionHandler.IsCollidingWithCoin(m_player, m_coinList[i])) { pickUpObserver.PlayerPickUpCoinAt(m_coinList[i].Position); m_coinList.Remove(m_coinList[i]); soundObserver.PlayerPickUpCoin(); } } }
/// <summary> /// Check if player have passed level finish /// </summary> /// <param name="soundObserver"></param> private void CheckIfLevelFinished(ISoundObserver soundObserver) { if (m_level.IsAtLevelFinish(m_player.Position, m_player.Size) && CheckIfAllCoinsIsPickedUp()) { m_gameState = GameState.LEVEL_FINISHED; if (m_level.CurrentLevel == Level.Levels.THREE) { SetGameState = GameModel.GameState.LAST_LEVEL_FINISHED; } m_level.CurrentLevel++; soundObserver.LevelCompleted(); } }
public void Update(float totalElapsedSeconds, ISoundObserver soundObserver, IPickUpObserver pickUpObserver) { if (CanPlayerMoveRight()) { UpdatePlayer(totalElapsedSeconds); } else { MoveLeft(); UpdatePlayer(totalElapsedSeconds); } UpdateBomb(totalElapsedSeconds); CheckIfInHole(soundObserver); CheckIfCollideWithBomb(soundObserver); CheckIfDead(); CheckIfLevelFinished(soundObserver); CheckIfPlayerPickedUpCoin(soundObserver, pickUpObserver); }