/// <summary>
        /// Updates Main Gameplay Loop code here, this is affected by whether or not the scene is paused.
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="otherScreenHasFocus"></param>
        /// <param name="coveredByOtherScreen"></param>
        public override void UpdateScene(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            character.Update((float)gameTime.ElapsedGameTime.TotalSeconds, vxEngine.InputManager.PreviousKeyboardState,
                             vxEngine.InputManager.KeyboardState, vxEngine.InputManager.PreviousGamePadState, vxEngine.InputManager.GamePadState);

            if (this.IsActive)
            {
                vxEngine.InputManager.ShowCursor = false;
            }
            else
            {
                vxEngine.InputManager.ShowCursor = true;
            }

            //Update grabber
            if (vxEngine.InputManager.MouseState.RightButton == ButtonState.Pressed && !grabber.IsGrabbing)
            {
                //Find the earliest ray hit
                RayCastResult raycastResult;
                if (BEPUPhyicsSpace.RayCast(new Ray(Camera.Position, Camera.WorldMatrix.Forward), 500, rayCastFilter, out raycastResult))
                {
                    var entityCollision = raycastResult.HitObject as EntityCollidable;
                    //If there's a valid ray hit, then grab the connected object!
                    if (entityCollision != null && entityCollision.Entity.IsDynamic)
                    {
                        Console.WriteLine("GRABBING ITEM: {0}", entityCollision.Entity.GetType().ToString());
                        grabber.Setup(entityCollision.Entity, raycastResult.HitData.Location);
                        //grabberGraphic.IsDrawing = true;
                        grabDistance = raycastResult.HitData.T;
                    }
                }
            }

            if (vxEngine.InputManager.MouseState.RightButton == ButtonState.Pressed && grabber.IsUpdating)
            {
                if (grabDistance < 4)
                {
                    grabDistance         = 3;
                    grabber.GoalPosition = Camera.Position + Camera.WorldMatrix.Forward * grabDistance;
                }
            }

            else if (vxEngine.InputManager.MouseState.RightButton == ButtonState.Released && grabber.IsUpdating)
            {
                grabber.Release();
            }

            base.UpdateScene(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }
Exemple #2
0
        public override void Update(Fix64 dt)
        {
            #region Kapow-Shooter Input

            //Update kapow-shooter
            if (!vehicle.IsActive)
#if !WINDOWS
            { if (Game.GamePadInput.IsButtonDown(Buttons.RightTrigger))
#else
            { if (Game.MouseInput.LeftButton == ButtonState.Pressed)
#endif
              {
                  if (character.IsActive)   //Keep the ball out of the character's body if its being used.
                  {
                      kapow.Position = Game.Camera.Position + Game.Camera.WorldMatrix.Forward * 3;
                  }
                  else
                  {
                      kapow.Position = Game.Camera.Position + Game.Camera.WorldMatrix.Forward;
                  }
                  kapow.AngularVelocity = Vector3.Zero;
                  kapow.LinearVelocity  = Game.Camera.WorldMatrix.Forward * 30;
              } }

            #endregion

            #region Grabber Input

            //Update grabber

#if !WINDOWS
            if (Game.GamePadInput.IsButtonDown(Buttons.RightShoulder) && !grabber.IsUpdating)
#else
            if (Game.MouseInput.RightButton == ButtonState.Pressed && !grabber.IsGrabbing)
#endif
            {
                //Find the earliest ray hit
                RayCastResult raycastResult;
                if (Space.RayCast(new Ray(Game.Camera.Position, Game.Camera.WorldMatrix.Forward), 1000, rayCastFilter, out raycastResult))
                {
                    var entityCollision = raycastResult.HitObject as EntityCollidable;
                    //If there's a valid ray hit, then grab the connected object!
                    if (entityCollision != null && entityCollision.Entity.IsDynamic)
                    {
                        grabber.Setup(entityCollision.Entity, raycastResult.HitData.Location);
                        grabberGraphic.IsDrawing = true;
                        grabDistance             = raycastResult.HitData.T;
                    }
                }
            }
#if !WINDOWS
            if (Game.GamePadInput.IsButtonDown(Buttons.RightShoulder) && grabber.IsUpdating)
#else
            else if (Game.MouseInput.RightButton == ButtonState.Pressed && grabber.IsUpdating)
#endif
            {
                grabber.GoalPosition = Game.Camera.Position + Game.Camera.WorldMatrix.Forward * grabDistance;
            }
#if !WINDOWS
            if (!Game.GamePadInput.IsButtonDown(Buttons.RightShoulder) && grabber.IsUpdating)
#else
            else if (Game.MouseInput.RightButton == ButtonState.Released && grabber.IsUpdating)
#endif
            {
                grabber.Release();
                grabberGraphic.IsDrawing = false;
            }

            #endregion

            #region Control State Input

#if !WINDOWS
            if (!vehicle.IsActive && Game.WasButtonPressed(Buttons.LeftTrigger))
            {
                kapowMaker.Position = kapow.Position;
                kapowMaker.Explode();
            }
            if (Game.WasButtonPressed(Buttons.A))
            {//Toggle character perspective.
                if (!character.IsActive)
                {
                    vehicle.Deactivate();
                    character.Activate();
                }
                else
                {
                    character.Deactivate();
                }
            }
            if (Game.WasButtonPressed(Buttons.B))
            {//Toggle vehicle perspective.
                if (!vehicle.IsActive)
                {
                    character.Deactivate();
                    vehicle.Activate();
                }
                else
                {
                    vehicle.Deactivate();
                }
            }
#else
            if (!vehicle.IsActive && Game.WasKeyPressed(Keys.Space))
            {
                //Detonate the bomb
                kapowMaker.Position = kapow.Position;
                kapowMaker.Explode();
            }
            if (Game.WasKeyPressed(Keys.C))
            {
                //Toggle character perspective.
                if (!character.IsActive)
                {
                    vehicle.Deactivate();
                    character.Activate();
                }
                else
                {
                    character.Deactivate();
                }
            }


            if (Game.WasKeyPressed(Keys.V))
            {
                //Toggle vehicle perspective.
                if (!vehicle.IsActive)
                {
                    character.Deactivate();
                    vehicle.Activate(Game.Camera.Position);
                }
                else
                {
                    vehicle.Deactivate();
                }
            }
#endif

            #endregion

            base.Update(dt); //Base.update updates the space, which needs to be done before the camera is updated.

            character.Update(dt, Game.PreviousKeyboardInput, Game.KeyboardInput, Game.PreviousGamePadInput, Game.GamePadInput);
            vehicle.Update(dt, Game.KeyboardInput, Game.GamePadInput);
            //If neither are active, just use the default camera movement style.
            if (!character.IsActive && !vehicle.IsActive)
            {
                freeCameraControlScheme.Update(dt);
            }
        }
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            // TODO: Add your update logic here

            if (playerInput != null)
            {
                playerInput.Update(
                    gameTime.ElapsedGameTime.Seconds,
                    core.Input.PreviousKeyboardState,
                    core.Input.KeyboardState,
                    core.Input.PreviousGamePadState,
                    core.Input.GamePadState);
            }

            core.Update(gameTime.ElapsedGameTime);

            KeyboardState ks = Keyboard.GetState();

            if (ks.IsKeyDown(Keys.F) && stopwatch.ElapsedMilliseconds > nextBallTime)
            {
                FireSphere();
                nextBallTime = stopwatch.ElapsedMilliseconds + minBallTime;
            }

            if (ks.IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // Next sound
            if (core.Input.KeyboardState.IsKeyDown(Keys.Right) && !core.Input.PreviousKeyboardState.IsKeyDown(Keys.Right))
            {
                if (++soundIndex >= core.SoundManager.Count)
                {
                    soundIndex = core.SoundManager.Count - 1;
                }

                LoadSound();
                PlaySound();
            }

            // Next sound
            if (core.Input.KeyboardState.IsKeyDown(Keys.Left) && !core.Input.PreviousKeyboardState.IsKeyDown(Keys.Left))
            {
                if (--soundIndex < 0)
                {
                    soundIndex = 0;
                }

                LoadSound();
                PlaySound();
            }

            // Play sound
            if (core.Input.KeyboardState.IsKeyDown(Keys.Enter) && !core.Input.PreviousKeyboardState.IsKeyDown(Keys.Enter))
            {
                PlaySound();
            }

            base.Update(gameTime);
        }
Exemple #4
0
        public override void Update(GameTime gameTime)
        {
            if (fading)
            {
                alpha += deltaA;
                if (alpha >= 255)
                {
                    alpha             = 255;
                    GameManager.State = GameState.GameOver;
                }
                return;
            }
            if (character.IsActive)
            {
                character.Update((float)gameTime.ElapsedGameTime.TotalSeconds);

                Vector3       startPosition = RenderingDevice.Camera.Position + RenderingDevice.Camera.World.Forward * 2;
                RayCastResult raycastResult;
                if (GameManager.Space.RayCast(new Ray(startPosition, RenderingDevice.Camera.World.Forward), 5, rayCastFilter, out raycastResult))
                {
                    Actor actorCollision;
                    if (raycastResult.HitObject is ConvexCollidable && (actorCollision = (raycastResult.HitObject as ConvexCollidable).Entity.Tag as Actor) != null)
                    {
                        KeypressEventArgs args = KeypressEventArgs.FromCurrentInput(Program.Game.Player, actorCollision);
                        if (args != null)
                        {
                            // I'm doing this all backwards.
                            actorCollision.DoEvent(args);
                        }
                    }
                }

                timing += (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (!swinging && timing > 0.5f && (Input.MouseState.LeftButton == ButtonState.Pressed || Input.CurrentPad.IsButtonDown(Buttons.RightTrigger)))
                {
                    swinging  = true;
                    timing    = 0;
                    swingQuat = Quaternion.CreateFromYawPitchRoll(0, -MathHelper.PiOver2, 0);
                }
                if (swinging && timing > 0.5f)
                {
                    swinging     = false;
                    timing       = 0;
                    swingQuat    = Quaternion.Identity;
                    hitThisSwing = false;
                }

                //if(sword.Ent.Space == null)
                //{
                //    Matrix newWorld;
                //    newWorld = Matrix.CreateRotationX(-MathHelper.PiOver2);
                //    newWorld *= Matrix.CreateTranslation(new Vector3(0.7f, 1.5f, -0.3f));
                //    newWorld *= Matrix.CreateRotationZ((RenderingDevice.Camera as CharacterCamera).Yaw);
                //    newWorld *= Matrix.CreateTranslation(RenderingDevice.Camera.Position);
                //    sword.Transform = newWorld;
                //}
                if (Vector3.Distance(sword.Ent.Position, PhysicsObject.Position) > 6)
                {
                    sword.Ent.Position = swordgrabber.GoalPosition;
                }
                swordgrabber.GoalPosition    = RenderingDevice.Camera.Position + RenderingDevice.Camera.World.Forward * 2 - Vector3.UnitZ;
                swordgrabber.GoalOrientation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, -MathHelper.PiOver2) *
                                               Quaternion.CreateFromYawPitchRoll(-(RenderingDevice.Camera as CharacterCamera).Yaw, 0, 0) *
                                               Quaternion.CreateFromYawPitchRoll(0, -((RenderingDevice.Camera as CharacterCamera).Pitch + MathHelper.PiOver2), 0) * swingQuat;

#if DEBUG
                if (Input.CheckKeyboardJustPressed(Keys.Q))
                {
                    GameManager.State = GameState.Ending;
                }
#endif
            }
        }
        public override void Update(GameTime gameTime)
        {
            // Restore/hide mouse if user alt+tabs out and back
            if (Game.IsActive && !lastGameActive)
            {
                Game.IsMouseVisible = false;
                lastGameActive      = Game.IsActive;
            }
            else if (!Game.IsActive && lastGameActive)
            {
                Game.IsMouseVisible = true;
                lastGameActive      = Game.IsActive;
                return;
            }
            else if (!Game.IsActive && !lastGameActive)
            {
                return;
            }
            else
            {
                lastGameActive = Game.IsActive;
            }

            if (playerInput != null)
            {
                playerInput.Update(
                    gameTime.ElapsedGameTime.Seconds,
                    core.Input.PreviousKeyboardState,
                    core.Input.KeyboardState,
                    core.Input.PreviousGamePadState,
                    core.Input.GamePadState);
            }

            // Mouse look
            mouseState = core.Input.MouseState;
            MouseState lastMouseState = core.Input.PreviousMouseState;

            if (mouseState != startMouseState)
            {
                mouseState = core.Input.MouseState;
                int mouseChangeX = mouseState.X - startMouseState.X;
                int mouseChangeY = mouseState.Y - startMouseState.Y;

                float yawDegrees   = (-MathHelper.ToDegrees(mouseChangeX) * mouseLookScale) * mouseLookSpeed;
                float pitchDegrees = (-MathHelper.ToDegrees(mouseChangeY) * mouseLookScale) * mouseLookSpeed;

                if (core.Input.InvertMouseLook)
                {
                    pitchDegrees = -pitchDegrees;
                }

                scene.Camera.Transform(yawDegrees, pitchDegrees, Vector3.Zero);

                Mouse.SetPosition(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2);
            }

            KeyboardState keyState     = core.Input.KeyboardState;
            KeyboardState lastKeyState = core.Input.PreviousKeyboardState;

            if ((keyState.IsKeyDown(Keys.F) || mouseState.LeftButton == ButtonState.Pressed) &&
                core.Stopwatch.ElapsedMilliseconds > nextObjectTime)
            {
                FireCurrentObject();
                nextObjectTime = core.Stopwatch.ElapsedMilliseconds + minObjectTime;
            }

            // Next physics object
            if ((keyState.IsKeyDown(Keys.Down) && !lastKeyState.IsKeyDown(Keys.Down)) ||
                (mouseState.ScrollWheelValue < lastMouseState.ScrollWheelValue))
            {
                physicsObjectIndex++;
                if (physicsObjectIndex >= physicsObjects.Count)
                {
                    physicsObjectIndex = 0;
                }
                UpdatePhysicsObjectText();
            }

            // Previous physics object
            if ((keyState.IsKeyDown(Keys.Up) && !lastKeyState.IsKeyDown(Keys.Up)) ||
                (mouseState.ScrollWheelValue > lastMouseState.ScrollWheelValue))
            {
                physicsObjectIndex--;
                if (physicsObjectIndex < 0)
                {
                    physicsObjectIndex = physicsObjects.Count - 1;
                }
                UpdatePhysicsObjectText();
            }

            // Update gui components
            physicsTextItem.Text = physicsObjectText;
            gui.Update(gameTime.ElapsedGameTime);

            // Update player light
            playerLight.Position = scene.Camera.Position;
        }