Ejemplo n.º 1
0
 public override bool Down()
 {
     return(Key.Down() || Button.Down());
 }
Ejemplo n.º 2
0
        public override void Update(GameTime gt)
        {
            if (AutoSwitchInputs) //Switch the inputs
            {
                if (Input != MovementInput.Analog && AnalogStickMoved())
                {
                    Input = MovementInput.Analog;
                    EntityGame.Log.Write("Input switched to Analog", this, Alert.Info);
                }
                else if (Input != MovementInput.Buttons && ButtonPressed())
                {
                    Input = MovementInput.Buttons;
                    EntityGame.Log.Write("Input switched to Buttons", this, Alert.Info);
                }
            }



            switch (Input)
            {
            case MovementInput.Analog:
                if (!HasFocus && (AnalogStickMoved() || SelectKey.Down()))
                {
                    GetFocus(this);
                }
                if (HasFocus)
                {
                    //TODO: Use normalized positition for this.
                    Position = new Vector2(Position.X + AnalogStick.Position.X * MovementSpeed.X,
                                           Position.Y - AnalogStick.Position.Y * MovementSpeed.Y);

                    //Move it with the camera.
                    //Position += EntityGame.Camera.Delta;

                    //Keep it from leaving the bounds of the window.
                    if (Body.Position.X < EntityGame.ActiveCamera.ScreenSpace.Left)
                    {
                        Body.Position.X = EntityGame.ActiveCamera.ScreenSpace.Left;
                    }
                    else if (Body.BoundingRect.Right > EntityGame.ActiveCamera.ScreenSpace.Right)
                    {
                        Body.Position.X = EntityGame.ActiveCamera.ScreenSpace.Right - Body.Bounds.X;
                    }

                    if (Body.Position.Y < EntityGame.ActiveCamera.ScreenSpace.Top)
                    {
                        Body.Position.Y = EntityGame.ActiveCamera.ScreenSpace.Top;
                    }
                    else if (Body.BoundingRect.Bottom > EntityGame.ActiveCamera.ScreenSpace.Bottom)
                    {
                        Body.Position.Y = EntityGame.ActiveCamera.ScreenSpace.Bottom - Body.Bounds.Y;
                    }
                }
                break;

            case MovementInput.Buttons:
                if (!HasFocus && ButtonPressed() || SelectKey.Down())
                {
                    GetFocus(this);
                }
                if (HasFocus)
                {
                    Position = new Vector2(
                        Position.X + ((LeftKey.Down()) ? -MovementSpeed.X : 0) + ((RightKey.Down()) ? MovementSpeed.X : 0),
                        Position.Y + ((UpKey.Down()) ? -MovementSpeed.Y : 0) + ((DownKey.Down()) ? MovementSpeed.Y : 0)
                        );

                    //Move it with the camera.
                    Position += EntityGame.ActiveCamera.Delta;

                    //Keep it from leaving the bounds of the window.
                    if (Body.Position.X < EntityGame.ActiveCamera.ScreenSpace.Left)
                    {
                        Body.Position.X = EntityGame.ActiveCamera.ScreenSpace.Left;
                    }
                    else if (Body.BoundingRect.Right > EntityGame.ActiveCamera.ScreenSpace.Right)
                    {
                        Body.Position.X = EntityGame.ActiveCamera.ScreenSpace.Right - Body.Bounds.X;
                    }

                    if (Body.Position.Y < EntityGame.ActiveCamera.ScreenSpace.Top)
                    {
                        Body.Position.Y = EntityGame.ActiveCamera.ScreenSpace.Top;
                    }
                    else if (Body.BoundingRect.Bottom > EntityGame.ActiveCamera.ScreenSpace.Bottom)
                    {
                        Body.Position.Y = EntityGame.ActiveCamera.ScreenSpace.Bottom - Body.Bounds.Y;
                    }
                }
                break;
            }
            base.Update(gt);
        }