예제 #1
0
 private void DecrementPlayerHealth(int decrementAmount)
 {
     _playerHealth -= decrementAmount;
     if (_playerHealth <= 0)
     {
         _playerHealth = 0; // ensure a negative value isn't shown
         GameEventManager.GameOver();
     }
     DisplayPlayerHealth();
 }
예제 #2
0
        /// <summary>
        /// Routine called when a Ghost collides with Pacman.
        /// </summary>
        private IEnumerator Die()
        {
            debugger.Info("has died");

            currentLives--;

            audioManager.PauseAllSounds();
            goManager.StopMovingEntities();
            audioManager.Pause(SoundNames.GHOST_MOVE);
            audioManager.GetSound(SoundNames.GHOST_MOVE).source.pitch = Constants.GHOST_MOVE_PITCH;

            yield return(new WaitForSeconds(1f));

            audioManager.Play(SoundNames.PACMAN_DEATH);
            yield return(new WaitForSeconds(audioManager.GetSound(SoundNames.PACMAN_DEATH).clip.length + 1f));

            goManager.ResetEntityPositions();

            if (currentLives < 0)
            {
                bool             newHighscore     = false;
                int              score            = pacmanScore.GetScore();
                HighscoreManager highscoreManager = HighscoreManager.instance;

                if (score > highscoreManager.GetLocalHighscore())
                {
                    highscoreManager.SaveLocalHighscore(score);
                    newHighscore = true;
                }

                gameEventManager.GameOver(newHighscore);
            }
            else
            {
                pacmanHud.RemoveLife(currentLives);
                gameEventManager.RespawnPacman();
                audioManager.Play(SoundNames.GHOST_MOVE);
            }
        }