Beispiel #1
0
        } // KeyButton

        #endregion

        #region Pressed

        /// <summary>
        /// True if the key or button was pressed.
        /// </summary>
        public bool Pressed(int gamePadNumber)
        {
            if (InputDevice == InputDevices.NoDevice)
            {
                return(false);
            }
            if (InputDevice == InputDevices.Keyboard)
            {
                return(Keyboard.KeyPressed(Key));
            }
            if (InputDevice == InputDevices.GamePad)
            {
                if (gamePadNumber == 1)
                {
                    return(GamePad.PlayerOne.ButtonPressed(GamePadButton));
                }
                if (gamePadNumber == 2)
                {
                    return(GamePad.PlayerTwo.ButtonPressed(GamePadButton));
                }
                if (gamePadNumber == 3)
                {
                    return(GamePad.PlayerThree.ButtonPressed(GamePadButton));
                }
                if (gamePadNumber == 4)
                {
                    return(GamePad.PlayerFour.ButtonPressed(GamePadButton));
                }
                // if (gamepadNumber == 0) // All gamepads at the same time.
                return(GamePad.PlayerOne.ButtonPressed(GamePadButton) || GamePad.PlayerTwo.ButtonPressed(GamePadButton) ||
                       GamePad.PlayerThree.ButtonPressed(GamePadButton) || GamePad.PlayerFour.ButtonPressed(GamePadButton));
            }
            // if (keyButton.Device == Devices.Mouse)
            return(Mouse.ButtonPressed(MouseButton));
        } // Pressed
Beispiel #2
0
        } // UpdateTasks

        #endregion

        #region Render Tasks

        /// <summary>
        /// Tasks before the engine render.
        /// Some tasks are more related to the frame rendering than the update,
        /// or maybe the update frequency is too high to waste time in this kind of tasks,
        /// for that reason the pre render task exists.
        /// For example, is more correct to update the HUD information here because is related with the rendering.
        /// </summary>
        protected override void PreRenderTasks()
        {
            if (Keyboard.KeyPressed(Keys.T))
            {
                dude.ModelAnimations.LocalBoneTransforms[7] = dude.ModelAnimations.LocalBoneTransforms[7] * Matrix.CreateFromYawPitchRoll(0.3f, 0, 0);
                dude.ModelAnimations.UpdateLocalBoneTransforms();
            }
            if (Keyboard.KeyPressed(Keys.G))
            {
                dude.ModelAnimations.LocalBoneTransforms[7] = dude.ModelAnimations.LocalBoneTransforms[7] * Matrix.CreateFromYawPitchRoll(-0.3f, 0, 0);
                dude.ModelAnimations.UpdateLocalBoneTransforms();
            }

            // Rifle placement.
            // The rifle matchs the 30th bone transformation.
            // But before I made some matrix modifications because of a problem with the content creation tool, a problem not related with the engine.
            rifle.Transform.LocalMatrix = Matrix.Identity;
            rifle.Transform.Translate(new Vector3(1.2767f, 0.5312f, 0.0045f));
            rifle.Transform.Rotate(new Vector3(0, 45, 90));
            rifle.Transform.Translate(new Vector3(0, 1.1081f, -0.3243f));
            rifle.Transform.Rotate(new Vector3(0, 45, 0));
            rifle.Transform.LocalScale  = new Vector3(16, 16, 16f);
            rifle.Transform.LocalMatrix = rifle.Transform.LocalMatrix * dude.ModelAnimations.WorldBoneTransforms[30] * dude.Transform.WorldMatrix;
        } // PreRenderTasks
        } // Load

        #endregion

        #region Update Tasks

        /// <summary>
        /// Tasks executed during the update.
        /// This is the place to put the application logic.
        /// </summary>
        protected override void UpdateTasks()
        {
            // Show or hide statistics graph.
            if (Button.JustPressed("Show Statistics"))
            {
                Layer.GetLayerByNumber(26).Visible = !Layer.GetLayerByNumber(26).Visible;
            }
            // If the scene is executing...
            if (mainSceneExecuting)
            {
                // Starts the video...
                if (Time.ApplicationTime > 1 && !videoStarted)
                {
                    introVideo.VideoRenderer.Play();
                    videoStarted = true;
                }
                if (videoStarted && Keyboard.KeyPressed(Keys.Escape))
                {
                    introVideo.VideoRenderer.Stop();
                }
                // If the video is over...
                if (introVideo.VideoRenderer.State == MediaState.Stopped && videoStarted)
                {
                    Layer.GetLayerByNumber(25).Visible = true;
                    demoLegend.Transform.Position      = new Vector3(20, Screen.Height - 35f, 0f);
                    if (finalEngineLogo.Transform.Position.X < -6)
                    {
                        finalEngineLogo.Transform.Translate(Time.SmoothFrameTime * 50, 0, 0);
                        xnaLogo.Transform.Translate(Time.SmoothFrameTime * 50, 0, 0);
                    }
                    else
                    {
                        xnaLogo.Transform.Position         = new Vector3(-6, 6, 0);
                        finalEngineLogo.Transform.Position = new Vector3(-6, 6, 0);
                    }
                    if (examplesLogo.Transform.Position.X > 1.3f)
                    {
                        examplesLogo.Transform.Translate(-Time.SmoothFrameTime * 70, 0, 0);
                    }
                    else
                    {
                        examplesLogo.Transform.Position = new Vector3(1.3f, 5.7f, 0);
                    }
                    if (selectOneScene.Transform.Position.Y < -5)
                    {
                        selectOneScene.Transform.Translate(0, Time.SmoothFrameTime * 65, 0);
                    }
                    else
                    {
                        selectOneScene.Transform.Position = new Vector3(6, -5, 0);
                    }
                    // Handle input...
                    if (Button.JustPressed("Next Scene"))
                    {
                        currentScene++;
                    }
                    if (Button.JustPressed("Previous Scene"))
                    {
                        currentScene--;
                    }
                    if (currentScene >= exampleImage.Length)
                    {
                        currentScene = 0;
                    }
                    if (currentScene < 0)
                    {
                        currentScene = exampleImage.Length - 1;
                    }
                    if (Button.JustPressed("Load Scene"))
                    {
                        loading.ModelRenderer.Enabled = true;
                        mainSceneExecuting            = false;
                    }
                }
                // Set as visible only the current scene.
                for (int i = 0; i < exampleImage.Length; i++)
                {
                    if (i == currentScene)
                    {
                        exampleImage[i].Active = true;
                        exampleTitle[i].Active = true;
                        exampleText[i].Active  = true;
                        // Center the scenes information.
                        int offsetx = (Screen.Width - 1100) / 2;
                        int offsety = (Screen.Height - 400) / 2;
                        exampleImage[i].Transform.Position = new Vector3(offsetx, offsety + 50, 0);
                        exampleTitle[i].Transform.Position = new Vector3(425 + offsetx, offsety, 0);
                        exampleText[i].Transform.Position  = new Vector3(425 + offsetx, offsety + 50, 0);
                    }
                    else
                    {
                        exampleImage[i].Active = false;
                        exampleTitle[i].Active = false;
                        exampleText[i].Active  = false;
                    }
                }
            }
            else
            {
                Layer.GetLayerByNumber(25).Visible = false;
                if (loadedScene == null)
                {
                    loading.ModelRenderer.Enabled = false;
                    switch (currentScene)
                    {
                    case 0:
                        loadedScene = new WarehouseScene();
                        break;

                    case 1:
                        loadedScene = new PhysicsTestScene();
                        break;

                    case 2:
                        loadedScene = new AnimationScene();
                        break;

                    case 3:
                        loadedScene = new HelloWorldScene();
                        break;
                    }
                }
                if (Button.JustPressed("Back To Menu"))
                {
                    loadedScene.Dispose();
                    loadedScene        = null;
                    mainSceneExecuting = true;
                }
            }
        } // UpdateTasks