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);
        }
Beispiel #2
0
        /// <summary>
        /// Game engine gameplay update
        /// </summary>
        /// <param name="e"></param>
        public override void Update(FrameEventArgs e)
        {
            float dt = (float)e.Time;

            // Checks if the game is over and acts accordingly
            if (Rounds <= 0)
            {
                sceneManager.NextScene();
            }

            // Handle AI player turn
            if (!isPlayer1 && isAI)
            {
                AiInputTimer += dt;
                if (AiInputTimer >= 0.5f)
                {
                    GenerateAiInput(InputID);
                    AiInputTimer = 0.0f;
                    InputID++;
                }
            }
            // Handles the banana and its animation
            Handle_BananaTrajectory(dt);
            SystemAnimator Animator = (SystemAnimator)systemManager.FindSystem("SystemAnimator");

            Animator.UpdateDeltaTime(dt);

            // Handles the hitting sun effect where its texture gets changed
            if (hasHitSun)
            {
                sunHitTimer += dt;
                if (sunHitTimer >= 2.0f)
                {
                    ComponentTexture texture = (ComponentTexture)entityManager.FindEntity("SunFace").FindComponent(ComponentTypes.COMPONENT_TEXTURE);
                    texture.Texture = ResourceManager.LoadTexture("Textures/sun_1.png");
                    sunHitTimer     = 0.0f;
                    hasHitSun       = false;
                }
            }
        }