コード例 #1
0
        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(InputState input, GameTime gameTime)
        {
            float timeDelta = (float)(gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000.0f);

            if (input == null)
                throw new ArgumentNullException("input");

            if (input.PauseGame)
            {
                // If they pressed pause, bring up the pause menu screen.
                ScreenManager.AddScreen(new PauseMenuScreen());
            }

            m_kPlane.RotX = 0;
            m_kPlane.RotZ = 0;
            if (input.IsKeyHeld(Keys.Up))
            {
                m_kPlane.RotX += -(float)Math.PI / 9;
            }
            if (input.IsKeyHeld(Keys.Down))
            {
                m_kPlane.RotX += (float)Math.PI / 9;
            }
            if (input.IsKeyHeld(Keys.Left))
            {
                m_kPlane.RotZ += (float)Math.PI / 9;
            }
            if (input.IsKeyHeld(Keys.Right))
            {
                m_kPlane.RotZ += -(float)Math.PI / 9;
            }

            m_kPlane.setRotationOffset(player.position);

            /*
            //OLD SHIP FUNCTIONS
            player.rotationVelocity = 0;
            if (input.ShipTurnLeft)
            {
                player.rotationVelocity += 3;
            }
            if (input.ShipTurnRight)
            {
                player.rotationVelocity += -3;
            }
            Vector3 thrust = Vector3.Zero;
            if (input.ShipMove)
            {
                thrust += 3500f * player.directionVec;
            }
            if (input.ReverseThrust)
            {
                thrust += -3500f * player.directionVec;
            }
            player.netForce = thrust;
            */
        }
コード例 #2
0
        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(InputState input, GameTime gameTime)
        {
            float timeDelta = (float)(gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000.0f);

            if (input == null)
                throw new ArgumentNullException("input");

            if (input.PauseGame)
            {
                // If they pressed pause, bring up the pause menu screen.
                ScreenManager.AddScreen(new PauseMenuScreen());
            }

            m_kPlane.RotX = 0;
            m_kPlane.RotZ = 0;

            if(input.IsKeyHeld(Keys.Up)) {
                m_kPlane.RotX += -(float)Math.PI / 9;
            }
            if (input.IsKeyHeld(Keys.Down))
            {
                m_kPlane.RotX += (float)Math.PI / 9;
            }
            if (input.IsKeyHeld(Keys.Left))
            {
                m_kPlane.RotZ += (float)Math.PI / 9;
            }
            if (input.IsKeyHeld(Keys.Right))
            {
                m_kPlane.RotZ += -(float)Math.PI / 9;
            }

               //for gamepad input (untested!!)
               //for forward/backward movement
               GamePadState gamePadState = input.CurrentGamePadStates[0];
               m_kPlane.RotX += ((float)Math.PI / 9) * m_kLookingDir.Z * gamePadState.ThumbSticks.Left.Y;
               m_kPlane.RotZ += ((float)Math.PI / 9) * m_kLookingDir.X * gamePadState.ThumbSticks.Left.Y;

               //for Left/Right movement
               m_kPlane.RotX += ((float)Math.PI / 9) * m_kLookingDir.X * gamePadState.ThumbSticks.Left.X;
               m_kPlane.RotZ += ((float)Math.PI / 9) * m_kLookingDir.Z * gamePadState.ThumbSticks.Left.X;

            m_kPlane.setRotationOffset(player.position);
        }
コード例 #3
0
        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(InputState input, GameTime gameTime)
        {
            float timeDelta = (float)(gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000.0f);

            if (input == null)
                throw new ArgumentNullException("input");

            if (input.PauseGame)
            {
                // If they pressed pause, bring up the pause menu screen.
                ScreenManager.AddScreen(new PauseMenuScreen());
            }
            if (input.ShipFire)
            {
                //fireMissile();
            }
            m_kShip.rotationVelocity = 0;
            if (input.ShipTurnLeft)
            {
                m_kShip.rotationVelocity += 3;
            }
            if (input.ShipTurnRight)
            {
                m_kShip.rotationVelocity += -3;
            }
            Vector3 thrust = Vector3.Zero;
            if (input.ShipMove)
            {
                thrust += 3500f * m_kShip.directionVec;
            }
            if (input.ReverseThrust)
            {
                thrust += -3500f * m_kShip.directionVec;
            }
            m_kShip.netForce = thrust;
        }
コード例 #4
0
        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(InputState input, GameTime gameTime)
        {
            if (input.MenuSelect)
            {
                // Raise the accepted event, then exit the message box.
                if (Accepted != null)
                    Accepted(this, EventArgs.Empty);

                ExitScreen();
            }
            else if (input.MenuCancel)
            {
                // Raise the cancelled event, then exit the message box.
                if (Cancelled != null)
                    Cancelled(this, EventArgs.Empty);

                ExitScreen();
            }
        }
コード例 #5
0
        /// <summary>
        /// Collision resolution. Kind of a hack.
        /// Called from the Update function
        /// Tweak numbers until the feel is "right"
        /// </summary>
        /// <param name="pushAway">The normalized vector that the ball should be pushed away</param>
        /// <param name="timeDelta"></param>
        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(InputState input, GameTime gameTime)
        {
            float timeDelta = (float)(gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000.0f);

            if (input == null)
                throw new ArgumentNullException("input");

            if (input.PauseGame)
            {
                // If they pressed pause, bring up the pause menu screen.
                ScreenManager.AddScreen(new PauseMenuScreen());
            }

            float RotX = 0;
            float RotZ = 0;
            //The axis are flipped from what would be expected
            //If you want to go forward/backwards, you need to switch Z and X
            //If you want to go Left/Right you keep Z and X consistent
            if (input.IsKeyHeld(Keys.Up))
            {
                RotX += ((float)Math.PI / 9) * m_kLookingDir.Z;
                RotZ += -((float)Math.PI / 9) * m_kLookingDir.X;
            }
            if (input.IsKeyHeld(Keys.Down))
            {
                RotX += -((float)Math.PI / 9) * m_kLookingDir.Z;
                RotZ += ((float)Math.PI / 9) * m_kLookingDir.X;
            }
            if (input.IsKeyHeld(Keys.Left))
            {
                RotX += -((float)Math.PI / 9) * m_kLookingDir.X;
                RotZ += -((float)Math.PI / 9) * m_kLookingDir.Z;
            }
            if (input.IsKeyHeld(Keys.Right))
            {
                RotX += ((float)Math.PI / 9) * m_kLookingDir.X;
                RotZ += ((float)Math.PI / 9) * m_kLookingDir.Z;
            }

            //Manually changing the camera rotation based on user input
            if (input.IsADown)
            {
                manualCameraRotation += (float)Math.PI / 4 * (float)gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000;
            }
            if (input.IsDDown)
            {
                manualCameraRotation -= (float)Math.PI / 4 * (float)gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000;
            }

            //camera rotation for 360 controller
            GamePadState gamePadState = input.CurrentGamePadStates[0];
            manualCameraRotation += (float)Math.PI / 4 * gamePadState.ThumbSticks.Right.X * timeDelta * 5;
            gameCamera.ManualCameraRotation(manualCameraRotation, player);

            //for forward/backward movement
            //GamePadState gamePadState = input.CurrentGamePadStates[0];
               // RotX += ((float)Math.PI / 9) * m_kLookingDir.Z;
               // RotZ += -((float)Math.PI / 9) * m_kLookingDir.X;

            RotX += ((float)Math.PI / 9) * m_kLookingDir.Z * gamePadState.ThumbSticks.Left.Y;
            RotZ += -((float)Math.PI / 9) * m_kLookingDir.X * gamePadState.ThumbSticks.Left.Y;

            //for Left/Right movement
            RotX += ((float)Math.PI / 9) * m_kLookingDir.X * gamePadState.ThumbSticks.Left.X;
            RotZ += ((float)Math.PI / 9) * m_kLookingDir.Z * gamePadState.ThumbSticks.Left.X;

            activeLevel.setRotation(RotX, RotZ, player.position);
        }
コード例 #6
0
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input, GameTime gameTime)
        {
            // Move to the previous menu entry?
            if (input.MenuUp)
            {
                selectedEntry--;

                if (selectedEntry < 0)
                    selectedEntry = menuEntries.Count - 1;
            }

            // Move to the next menu entry?
            if (input.MenuDown)
            {
                selectedEntry++;

                if (selectedEntry >= menuEntries.Count)
                    selectedEntry = 0;
            }

            // Accept or cancel the menu?
            if (input.MenuSelect)
            {
                OnSelectEntry(selectedEntry);
            }
            else if (input.MenuCancel)
            {
                OnCancel();
            }
        }
コード例 #7
0
        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(InputState input, GameTime gameTime)
        {
            float timeDelta = (float)(gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000.0f);

            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (input.PauseGame)
            {
                // If they pressed pause, bring up the pause menu screen.
                ScreenManager.AddScreen(new PauseMenuScreen());
            }


            m_kPlane.RotX = 0;
            m_kPlane.RotZ = 0;
            if (input.IsKeyHeld(Keys.Up))
            {
                m_kPlane.RotX += -(float)Math.PI / 9;
            }
            if (input.IsKeyHeld(Keys.Down))
            {
                m_kPlane.RotX += (float)Math.PI / 9;
            }
            if (input.IsKeyHeld(Keys.Left))
            {
                m_kPlane.RotZ += (float)Math.PI / 9;
            }
            if (input.IsKeyHeld(Keys.Right))
            {
                m_kPlane.RotZ += -(float)Math.PI / 9;
            }


            m_kPlane.setRotationOffset(player.position);


            /*
             * //OLD SHIP FUNCTIONS
             * player.rotationVelocity = 0;
             * if (input.ShipTurnLeft)
             * {
             *  player.rotationVelocity += 3;
             * }
             * if (input.ShipTurnRight)
             * {
             *  player.rotationVelocity += -3;
             * }
             * Vector3 thrust = Vector3.Zero;
             * if (input.ShipMove)
             * {
             *  thrust += 3500f * player.directionVec;
             * }
             * if (input.ReverseThrust)
             * {
             *  thrust += -3500f * player.directionVec;
             * }
             * player.netForce = thrust;
             */
        }
コード例 #8
0
        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(InputState input, GameTime gameTime)
        {
            float timeDelta = (float)(gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000.0f);

            if (input == null)
                throw new ArgumentNullException("input");

            if (input.PauseGame)
            {
                // If they pressed pause, bring up the pause menu screen.
                ScreenManager.AddScreen(new PauseMenuScreen());
            }

            m_kPlane.RotX = 0;
            m_kPlane.RotZ = 0;
            Vector3 m_kLookingDir = player.position - gameCamera.GetCameraPosition();
            m_kLookingDir.Y = 0f;
            m_kLookingDir.Normalize();
            //m_kLookingDir = new Vector3(-1f, 0, 0);

            //The axis are flipped from what would be expected
            //If you want to go forward/backwards, you need to switch Z and X
            //If you want to go Left/Right you keep Z and X consistent
            if (input.IsKeyHeld(Keys.Up))
            {

                m_kPlane.RotX +=  ((float)Math.PI / 9) * m_kLookingDir.Z;
                m_kPlane.RotZ += -((float)Math.PI / 9) * m_kLookingDir.X;

            }
            if (input.IsKeyHeld(Keys.Down))
            {
                m_kPlane.RotX += -((float)Math.PI / 9) * m_kLookingDir.Z;
                m_kPlane.RotZ +=  ((float)Math.PI / 9) * m_kLookingDir.X;
            }
            if (input.IsKeyHeld(Keys.Left))
            {
                m_kPlane.RotX += -((float)Math.PI / 9) * m_kLookingDir.X;
                m_kPlane.RotZ += -((float)Math.PI / 9) * m_kLookingDir.Z;
            }
            if (input.IsKeyHeld(Keys.Right))
            {
                m_kPlane.RotX +=  ((float)Math.PI / 9) * m_kLookingDir.X;
                m_kPlane.RotZ +=  ((float)Math.PI / 9) * m_kLookingDir.Z;
            }

            /*
            //for gamepad input (untested!!)
            //for forward/backward movement
            GamePadState gamePadState = input.CurrentGamePadStates[0];
            m_kPlane.RotX += ((float)Math.PI / 9) * m_kLookingDir.Z * gamePadState.ThumbSticks.Left.Y;
            m_kPlane.RotZ += -((float)Math.PI / 9) * m_kLookingDir.X * gamePadState.ThumbSticks.Left.Y;

            //for Left/Right movement
            m_kPlane.RotX += -((float)Math.PI / 9) * m_kLookingDir.X * gamePadState.ThumbSticks.Left.X;
            m_kPlane.RotZ += -((float)Math.PI / 9) * m_kLookingDir.Z * gamePadState.ThumbSticks.Left.X;
            */

            m_kPlane.setRotationOffset(player.position);

            //Manually changing the camera rotation based on user input

            if (input.IsADown)
            {
                manualCameraRotation += (float)Math.PI / 4 * (float)gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000;
            }
            if (input.IsDDown)
            {
                manualCameraRotation -= (float)Math.PI / 4 * (float)gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000;
            }

            gameCamera.ManualCameraRotation(manualCameraRotation, player);

            /*
            //OLD SHIP FUNCTIONS
            player.rotationVelocity = 0;
            if (input.ShipTurnLeft)
            {
                player.rotationVelocity += 3;
            }
            if (input.ShipTurnRight)
            {
                player.rotationVelocity += -3;
            }
            Vector3 thrust = Vector3.Zero;
            if (input.ShipMove)
            {
                thrust += 3500f * player.directionVec;
            }
            if (input.ReverseThrust)
            {
                thrust += -3500f * player.directionVec;
            }
            player.netForce = thrust;
            */
        }