Exemple #1
0
    // update game state
    public void Update()
    {
        if (_GameStarting)
        {
            if (!_StartTimer.IsStarted)
            {
                _GameOver = false;
                _StartTimer.Start();
            }
            else
            {
                if (_StartTimer.Ticks / 1000 >= _StartDelay)
                {
                    _GameStarting = false;
                    _StartTimer.Stop();  // stop timer
                    _StartTimer.Reset(); // reset timer
                    ResetLevel();
                }
            }
        }


        if (!_GameStopped)
        {
            if (!SplashKit.MusicPlaying()) // play siren if not already
            {
                SplashKit.PlayMusic("siren", -1);
            }
            _Pacman.KeepInMaze(); // check collision with pivots, keeps pacman in the maze...
            _Pacman.HandleInput();
            foreach (Ghost g in _Ghosts)
            {
                g.KeepInMaze(); // check collision with 'ghost pivots' (reduced set, no cluster), keeps ghost in the maze and determines direction...
            }
            PelletCollision();  // check if pacman has eaten/collided with pellet
            CheckCollision();   // check if pacman and ghosts collide
            _Pacman.Update();   // update player
            foreach (Ghost g in _Ghosts)
            {
                g.Update(); // update ghost
            }
        }


        if (_GhostsEaten.Count > 0) // clears list of eaten ghosts each time vulnerability ends
        {
            if (!Ghost._Vulnerable && !Ghost._VulnerableTransition)
            {
                _GhostsEaten.Clear();
            }
        }
    }