Beispiel #1
0
        /// <summary>
        /// Intilises all systems required for this scene and updates SystemManager
        /// </summary>
        private void CreateSystems()
        {
            // Intialises all systems needed in this scene and add them to SystemManager
            ISystem newSystem;

            // Creates the system to calculate the SkyBox
            newSystem = new SystemSkyBox(ref sceneManager.camera);
            systemManager.AddSystem(newSystem);

            // Creates an array of light point for use in SystemRenderer
            Vector3[] array = new Vector3[] {
                new Vector3(0.0f, 1.0f, 0.0f),
                new Vector3(17.0f, 1.0f, 15.0f),
                new Vector3(17.0f, 1.0f, -15.0f),
                new Vector3(-17.0f, 1.0f, 15.0f),
                new Vector3(-17.0f, 1.0f, -15.0f)
            };
            // Creates the system to calculate all the rendering (including lighting)
            newSystem = new SystemRender(ref sceneManager.camera, array);
            systemManager.AddSystem(newSystem);
            // Creates the system to calculate all the collision (and trigger) events
            newSystem = new SystemCollider(ref entityManager, ref sceneManager.camera);
            systemManager.AddSystem(newSystem);
            // Creates the system to calculate all the AI paths and behaviours
            newSystem = new SystemAI(50, 50, entityManager.Entities().ToArray());
            systemManager.AddSystem(newSystem);
            // Creates the system to update all the audio effects
            newSystem = new SystemAudio();
            systemManager.AddSystem(newSystem);
            // Creates the system to calculate all the animation transformions
            newSystem = new SystemAnimator();
            systemManager.AddSystem(newSystem);
        }
Beispiel #2
0
        /// <summary>
        /// Creates and intialises all systems required for this game scene
        /// </summary>
        private void CreateSystems()
        {
            ISystem newSystem;

            // Creates the system to calculate the SkyBox
            newSystem = new SystemSkyBox(ref sceneManager.camera);
            systemManager.AddSystem(newSystem);

            // Creates an array of light point for use in SystemRenderer
            Vector3[] array = new Vector3[] {
                new Vector3(G1X, 13.0f, 10.0f),
                new Vector3(G2X, 13.0f, 10.0f)
            };
            // Creates the system to calculate all the rendering (including lighting)
            newSystem = new SystemRender(ref sceneManager.camera, array);
            systemManager.AddSystem(newSystem);
            // Creates the system to handle all collision on X&Y axis (Sets object to check collision against to banana)
            ComponentPosition pos = (ComponentPosition)entityManager.FindEntity("Banana").FindComponent(ComponentTypes.COMPONENT_POSITION);

            newSystem = new SystemColliderXY(ref entityManager, pos);
            systemManager.AddSystem(newSystem);
            // Creates the system to handle the animation of game objects
            newSystem = new SystemAnimator();
            systemManager.AddSystem(newSystem);
        }
Beispiel #3
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 #4
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;
                }
            }
        }