Esempio n. 1
0
        private void RespondPlayerFood(Entity player, Entity food)
        {
            //play food sound
            ComponentTransform foodTransform = (ComponentTransform)food.FindComponent(ComponentTypes.COMPONENT_TRANSFORM);
            ComponentAudio     foodAudio     = (ComponentAudio)food.FindComponent(ComponentTypes.COMPONENT_AUDIO);

            Vector3 emitterPosition = (foodTransform).Position;
            int     source          = (foodAudio).Source;

            AL.Source(source, ALSource3f.Position, ref emitterPosition);

            foodAudio.Play();

            //increase the score
            ComponentScore scoreComponent = (ComponentScore)player.FindComponent(ComponentTypes.COMPONENT_SCORE);
            float          score          = scoreComponent.Score;

            ComponentValue valueComponent = (ComponentValue)food.FindComponent(ComponentTypes.COMPONENT_VALUE);
            float          value          = valueComponent.Value;

            score += value;

            scoreComponent.Score = score;
            food.Enabled         = false;
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        private void RespondPlayerPowerup(Entity player, Entity food)
        {
            ComponentScore scoreComponent = (ComponentScore)player.FindComponent(ComponentTypes.COMPONENT_SCORE);
            float          score          = scoreComponent.Score;

            ComponentValue valueComponent = (ComponentValue)food.FindComponent(ComponentTypes.COMPONENT_VALUE);
            float          value          = valueComponent.Value;

            score += value;

            //change AI state
            //done through the AI system

            scoreComponent.Score = score;
            food.Enabled         = false;
        }
Esempio n. 4
0
        public void Keyboard_KeyDown(object sender, KeyboardKeyEventArgs e)
        {
            if (e.Key == Key.B)
            {
                CreateFood();
            }
            if (e.Key == Key.L)
            {
                Debug.WriteLine("Position: " + camera.Position);
            }

            if (e.Key == Key.C)
            {
                if (freeCam)
                {
                    camera.Control("Player");
                    freeCam = !freeCam;
                }
                else
                {
                    camera.Detatch();
                    freeCam = !freeCam;
                }
            }

            if (e.Key == Key.G)
            {
                List <Entity> ghosts = entityManager.FindEntities("Ghost");

                foreach (Entity ghost in ghosts)
                {
                    ghost.Enabled = !ghost.Enabled;
                }
            }

            if (e.Key == Key.BackSpace)
            {
                ComponentScore scoreComp = (ComponentScore)entityManager.FindEntity("Player").FindComponent(ComponentTypes.COMPONENT_SCORE);
                float          score     = scoreComp.Score;
                sceneManager.SetScene(new GameOverScene(sceneManager, score));
            }
        }