Ejemplo n.º 1
0
        public override void Update(GameTime gameTime)
        {
            if (!ServiceHelper.Game.IsActive)
            {
                return;
            }
            this.Reset();
            if (this.keyboard)
            {
                this.KeyboardState.Update(Keyboard.GetState(), gameTime);
                this.Movement      = new Vector2(FezButtonStateExtensions.IsDown(this.KeyboardState.Right) ? 1f : (FezButtonStateExtensions.IsDown(this.KeyboardState.Left) ? -1f : 0.0f), FezButtonStateExtensions.IsDown(this.KeyboardState.Up) ? 1f : (FezButtonStateExtensions.IsDown(this.KeyboardState.Down) ? -1f : 0.0f));
                this.FreeLook      = new Vector2(FezButtonStateExtensions.IsDown(this.KeyboardState.LookRight) ? 1f : (FezButtonStateExtensions.IsDown(this.KeyboardState.LookLeft) ? -1f : 0.0f), FezButtonStateExtensions.IsDown(this.KeyboardState.LookUp) ? 1f : (FezButtonStateExtensions.IsDown(this.KeyboardState.LookDown) ? -1f : 0.0f));
                this.Back          = this.KeyboardState.OpenMap;
                this.Start         = this.KeyboardState.Pause;
                this.Jump          = this.KeyboardState.Jump;
                this.GrabThrow     = this.KeyboardState.GrabThrow;
                this.CancelTalk    = this.KeyboardState.CancelTalk;
                this.Down          = this.KeyboardState.Down;
                this.ExactUp       = this.Up = this.KeyboardState.Up;
                this.Left          = this.KeyboardState.Left;
                this.Right         = this.KeyboardState.Right;
                this.OpenInventory = this.KeyboardState.OpenInventory;
                this.RotateLeft    = this.KeyboardState.RotateLeft;
                this.RotateRight   = this.KeyboardState.RotateRight;
                this.MapZoomIn     = this.KeyboardState.MapZoomIn;
                this.MapZoomOut    = this.KeyboardState.MapZoomOut;
                this.FpsToggle     = this.KeyboardState.FpViewToggle;
                this.ClampLook     = this.KeyboardState.ClampLook;
            }
            if (this.gamepad)
            {
                PlayerIndex[] players = ControllerIndexExtensions.GetPlayers(ControllerIndex.Any);
                for (int index = 0; index < players.Length; ++index)
                {
                    GamepadState gamepadState = this.GamepadsManager[players[index]];
                    if (!gamepadState.Connected)
                    {
                        if (gamepadState.NewlyDisconnected && this.ActiveControllerDisconnected != null)
                        {
                            this.ActiveControllerDisconnected(players[index]);
                        }
                    }
                    else
                    {
                        this.ClampLook = FezMath.Coalesce <FezButtonState>(this.ClampLook, gamepadState.RightStick.Clicked.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.FpsToggle = FezMath.Coalesce <FezButtonState>(this.FpsToggle, gamepadState.LeftStick.Clicked.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        Vector2 second1 = Vector2.Clamp(ThumbstickState.CircleToSquare(gamepadState.LeftStick.Position), -Vector2.One, Vector2.One);
                        Vector2 second2 = Vector2.Clamp(ThumbstickState.CircleToSquare(gamepadState.RightStick.Position), -Vector2.One, Vector2.One);
                        this.Movement      = FezMath.Coalesce <Vector2>(this.Movement, second1, gamepadState.DPad.Direction);
                        this.FreeLook      = FezMath.Coalesce <Vector2>(this.FreeLook, second2);
                        this.Back          = FezMath.Coalesce <FezButtonState>(this.Back, gamepadState.Back, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.Start         = FezMath.Coalesce <FezButtonState>(this.Start, gamepadState.Start, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.Jump          = FezMath.Coalesce <FezButtonState>(this.Jump, gamepadState.A.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.GrabThrow     = FezMath.Coalesce <FezButtonState>(this.GrabThrow, gamepadState.X.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.CancelTalk    = FezMath.Coalesce <FezButtonState>(this.CancelTalk, gamepadState.B.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.OpenInventory = FezMath.Coalesce <FezButtonState>(this.OpenInventory, gamepadState.Y.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.Up            = FezMath.Coalesce <FezButtonState>(this.Up, gamepadState.DPad.Up.State, gamepadState.LeftStick.Up.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.Down          = FezMath.Coalesce <FezButtonState>(this.Down, gamepadState.DPad.Down.State, gamepadState.LeftStick.Down.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.Left          = FezMath.Coalesce <FezButtonState>(this.Left, gamepadState.DPad.Left.State, gamepadState.LeftStick.Left.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.Right         = FezMath.Coalesce <FezButtonState>(this.Right, gamepadState.DPad.Right.State, gamepadState.LeftStick.Right.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.ExactUp       = FezMath.Coalesce <FezButtonState>(this.ExactUp, gamepadState.ExactUp, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.MapZoomIn     = FezMath.Coalesce <FezButtonState>(this.MapZoomIn, gamepadState.RightShoulder.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.MapZoomOut    = FezMath.Coalesce <FezButtonState>(this.MapZoomOut, gamepadState.LeftShoulder.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        if (this.StrictRotation)
                        {
                            this.RotateLeft  = FezMath.Coalesce <FezButtonState>(this.RotateLeft, gamepadState.LeftTrigger.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                            this.RotateRight = FezMath.Coalesce <FezButtonState>(this.RotateRight, gamepadState.RightTrigger.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        }
                        else
                        {
                            this.RotateLeft  = FezMath.Coalesce <FezButtonState>(this.RotateLeft, gamepadState.LeftShoulder.State, gamepadState.LeftTrigger.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                            this.RotateRight = FezMath.Coalesce <FezButtonState>(this.RotateRight, gamepadState.RightShoulder.State, gamepadState.RightTrigger.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        }
                    }
                }
            }
            if (!this.mouse)
            {
                return;
            }
            this.MouseState.Update(gameTime);
            Vector2 second = Vector2.Zero;

            switch (this.MouseState.LeftButton.State)
            {
            case MouseButtonStates.DragStarted:
                this.lastMouseCenter = new Vector2((float)this.MouseState.LeftButton.DragState.Movement.X, (float)-this.MouseState.LeftButton.DragState.Movement.Y);
                break;

            case MouseButtonStates.Dragging:
                Vector2 vector2 = new Vector2((float)this.MouseState.LeftButton.DragState.Movement.X, (float)-this.MouseState.LeftButton.DragState.Movement.Y);
                second = (this.lastMouseCenter - vector2) / 32f;
                this.lastMouseCenter = vector2;
                break;
            }
            this.FreeLook   = FezMath.Coalesce <Vector2>(this.FreeLook, second);
            this.MapZoomIn  = FezMath.Coalesce <FezButtonState>(this.MapZoomIn, this.MouseState.WheelTurnedUp, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
            this.MapZoomOut = FezMath.Coalesce <FezButtonState>(this.MapZoomOut, this.MouseState.WheelTurnedDown, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
        }