Esempio n. 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);
        }
Esempio n. 2
0
        /// <summary>
        /// Method to organise the trigger collsion detection
        /// </summary>
        private void ManageTriggerCollisions()
        {
            // Get access to the collision system to find out which entity (if any) have caused a trigger
            // (Trigger describes entity with collision that is not rigid e.g. pickup item compared to a wall)
            SystemCollider collide = (SystemCollider)systemManager.FindSystem("SystemCollider");

            // Checks to make sure checks only run if a trigger has occured
            if (collide.GetEntityCollisionTrigger() != null && collide.GetEntityCollisionTrigger() != "")
            {
                // First check is to see if the player has collided with any of the ghosts
                // Works by developing the entities xml file with consitent and sensible names per entity
                if (collide.GetEntityCollisionTrigger().Contains("Ghost"))
                {
                    // If the player picked up a power up within the last 10seconds then the player damages the ghost
                    // Otherwise the ghost damages the player, removing a life and reseting both player and ghosts positions to the starting points
                    if (isPowerUp)
                    {
                        // Updates sound effects settings and plays sound effect
                        SoundEffects[3].UpdateEmitterPosition(sceneManager.camera.Position);
                        SoundEffects[3].VolumeOfAudio = 1.0f;
                        SoundEffects[3].PlayAudio();
                        // Sets the positon of the ghost that was hit to the starting position
                        ComponentPosition Pos = (ComponentPosition)entityManager.FindEntity(collide.GetEntityCollisionTrigger()).FindComponent(ComponentTypes.COMPONENT_POSITION);
                        Pos.Position = StartPosition_Ghost;
                        // Updates the players score
                        PlayerScore += 10;
                    }
                    else
                    {
                        // Player has been hit by a ghost so a life is taken off and players position set back to the starting positon
                        NumberOfLives--;
                        sceneManager.camera.Position = StartPosition_Player;
                        // This could be improved, the collision detection keeps track of players last position
                        // If it isn't updated the after the player is moved to the starting point they will be moved straight back again
                        collide.UpdateLastPosition(StartPosition_Player);
                        // Plays sound effect for player getting hit by a ghost and updates it settings
                        SoundEffects[1].UpdateEmitterPosition(sceneManager.camera.Position);
                        SoundEffects[1].VolumeOfAudio = 20.0f;
                        SoundEffects[1].PlayAudio();
                        // All ghosts will have their positions reset to the starting position
                        for (int i = 0; i < NumberOfGhost; i++)
                        {
                            ComponentPosition Pos = (ComponentPosition)entityManager.FindEntityWithMask(ComponentTypes.COMPONENT_AI)[i].FindComponent(ComponentTypes.COMPONENT_POSITION);
                            Pos.Position = StartPosition_Ghost;
                        }
                        // Finally checks if the player has run out of lives and if so it moves to the game over scene
                        if (NumberOfLives <= 0)
                        {
                            sceneManager.NextScene();
                        }
                    }
                    // Clears the last trigger so it doesn't get stuck in an infinite loop
                    collide.ClearLastTrigger();
                }
                // Checks if the player has collided with one of the coins
                // Again making use of using consitent and sensible names in the entities xml files
                else if (collide.GetEntityCollisionTrigger().Contains("coin"))
                {
                    // Plays the pick up sound for a coin and updates the sound effects settings
                    SoundEffects[0].UpdateEmitterPosition(sceneManager.camera.Position);
                    SoundEffects[0].VolumeOfAudio = 0.2f;
                    SoundEffects[0].PlayAudio();
                    // Coin has been hit so it is now removed from the entity list so it wont be managed anymore in this instance of this game scene
                    entityManager.RemoveEntity(collide.GetEntityCollisionTrigger());
                    // Clears pickable collision check
                    collide.ClearLastPickable();
                    // Updates the players score and how many coins their have collected
                    // These are seperate as the players score can be added to by things outside of pickups such as killing a ghost
                    PlayerScore++;
                    CoinsCollected++;
                }
                // Checks if the player has collcied with one of the powerup items
                // Again making use of using consitent and sensible names in the entities xml files
                else if (collide.GetEntityCollisionTrigger().Contains("power"))
                {
                    // Sets the bool for is the player powered up or not to true
                    isPowerUp = true;
                    // Sets the value for how long the powerup is to last 1.0f = 1 second
                    PowerUpTimer = 10.0f;
                    // Plays the sound effect for the power up being picked up
                    SoundEffects[2].UpdateEmitterPosition(sceneManager.camera.Position);
                    SoundEffects[2].VolumeOfAudio = 0.4f;
                    SoundEffects[2].PlayAudio();
                    // Just like the coin it has been collected so needs to be removed for entity list so its no longer managed
                    entityManager.RemoveEntity(collide.GetEntityCollisionTrigger());
                    collide.ClearLastPickable();
                    // Updates the players score and items collected
                    PlayerScore += 5;
                    CoinsCollected++;
                }
            }
        }