Exemple #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)
        {
            if (GamePad.GetState(1).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Key.Escape))
            {
                sceneManager.Exit();
            }

            CheckInput();
            //ai input

            systemManager.ActionUpdateSystems(entityManager);

            //Add your update logic here

            Entity player = entityManager.FindEntity("Player");

            if (player != null)
            {
                ComponentLives playerLivesComponent = (ComponentLives)player.FindComponent(ComponentTypes.COMPONENT_LIVES);

                ComponentScore scoreComp = (ComponentScore)player.FindComponent(ComponentTypes.COMPONENT_SCORE);
                float          score     = scoreComp.Score;

                if (playerLivesComponent.Lives <= 0)
                {
                    sceneManager.SetScene(new GameOverScene(sceneManager, score));
                }

                List <Entity> foodList = entityManager.FindEntities("Food_");
                if (foodList.Count == 0)
                {
                    sceneManager.SetScene(new GameOverScene(sceneManager, score));
                }
            }

            //--------------------

            systemManager.ActionCollisionSystems(entityManager);

            //final systems must action last
            systemManager.ActionFinalSystems(entityManager);

            //move camera
            camera.Update();

            // update OpenAL
            listenerPosition  = camera.Position;
            listenerDirection = camera.Direction;
            listenerUp        = camera.Up;
            AL.Listener(ALListener3f.Position, ref listenerPosition);
            AL.Listener(ALListenerfv.Orientation, ref listenerDirection, ref listenerUp);
        }