Beispiel #1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="e">Provides a snapshot of timing values.</param>
        public override void Update(FrameEventArgs e)
        {
            // Checks if the player has collected all the coins needed to win the level
            if (CoinsCollected >= NumberOfCoins)
            {
                sceneManager.ChangeScene(3); return;
            }
            // Game timing related features
            float dt = (float)e.Time;

            if (PowerUpTimer > 0)
            {
                // Manages when the Power up sound effect plays and for how long and also updates playing position
                PowerUpTimer -= dt;
                SoundEffects[4].UpdateEmitterPosition(sceneManager.camera.Position);
                // This will only run once right after the power up is collected to prevent multiple sound effects playing
                if (!isPowerUpSound)
                {
                    // Updates the sound effects settings
                    SoundEffects[4].VolumeOfAudio = 0.4f;
                    SoundEffects[4].LoopPlayAudio = true;
                    SoundEffects[4].PlayAudio();
                    isPowerUpSound = true;
                }
                // If this passes then the power up period has finised and all returns to normal
                if (PowerUpTimer <= 0)
                {
                    PowerUpTimer   = 0.0f;
                    isPowerUp      = false;
                    isPowerUpSound = false;
                    // Make sure to clean up audio trail
                    SoundEffects[4].Close();
                }
            }

            // This is required for the AI (and physics) system to work as the AI require deltatime to work consitently
            SystemAI AI = (SystemAI)systemManager.FindSystem("SystemAI");

            if (DebugGhosts)
            {
                AI.UpdateDeltaTime(0.0f);
            }
            else
            {
                AI.UpdateDeltaTime(dt);
            }

            // This is requried for consitent animation across systems
            SystemAnimator Animator = (SystemAnimator)systemManager.FindSystem("SystemAnimator");

            Animator.UpdateDeltaTime(dt);
            // Updates the AI to follow the player when its position changes
            ManageGhostTargets();
            // Checks for trigger collisions that need acting on such as item pickup or ghost collision
            ManageTriggerCollisions();
            // Handles the player inputs to move the player
            ManageMovement(dt);
        }