Exemplo n.º 1
0
        private void RespondPlayerGhost(Entity player, Entity ghost)
        {
            //Debug.WriteLine("collision between player and ghost");

            //if ghost is chasing
            {
                //play ghost sound
                ComponentTransform ghostTransform = (ComponentTransform)ghost.FindComponent(ComponentTypes.COMPONENT_TRANSFORM);
                ComponentAudio     ghostAudio     = (ComponentAudio)ghost.FindComponent(ComponentTypes.COMPONENT_AUDIO);

                Vector3 emitterPosition = (ghostTransform).Position;
                int     source          = (ghostAudio).Source;

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

                ghostAudio.Play();

                //kill player
                ComponentLives livesComponent = (ComponentLives)player.FindComponent(ComponentTypes.COMPONENT_LIVES);
                livesComponent.Lives -= 1;

                ComponentTransform transformComponent = (ComponentTransform)player.FindComponent(ComponentTypes.COMPONENT_TRANSFORM);
                transformComponent.Position = new Vector3(0, 1, 2);
                ComponentMovement movementComponent = (ComponentMovement)player.FindComponent(ComponentTypes.COMPONENT_MOVEMENT);
                movementComponent.DesiredLocation = new Vector3(0, 1, 2);
            }
            //else if ghost is fleeing
            //kill ghost
            //add 100 points to player
        }
Exemplo 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);
        }