Beispiel #1
0
        public void HandleInput()
        {
            CurrentKeyState = Keyboard.GetState();

            if (!(CurrentKeyState.IsKeyDown(Keys.Right)) && !(CurrentKeyState.IsKeyDown(Keys.Left)))
            {
                //dir = 0;
                IsLeftPressed  = false;
                IsRightPressed = false;
                if (PlayerState != PLAYER_STATE.IDLE && PlayerState != PLAYER_STATE.JUMP && PlayerState != PLAYER_STATE.FALLING)
                {
                    PlayerState = PLAYER_STATE.IDLE;
                }
            }

            if (CurrentKeyState.IsKeyDown(Keys.Right))
            {
                dir            = 1;
                IsLeftPressed  = false;
                IsRightPressed = true;
                if (Skeleton.FlipX == true)
                {
                    Skeleton.FlipX = false;
                }
                if (PlayerState != PLAYER_STATE.R_RUN && PlayerState != PLAYER_STATE.JUMP && PlayerState != PLAYER_STATE.FALLING)
                {
                    PlayerState = PLAYER_STATE.R_RUN;
                }
            }
            else if (CurrentKeyState.IsKeyDown(Keys.Left))
            {
                dir            = -1;
                IsLeftPressed  = true;
                IsRightPressed = false;
                if (Skeleton.FlipX == false)
                {
                    Skeleton.FlipX = true;
                }
                if (PlayerState != PLAYER_STATE.L_RUN && PlayerState != PLAYER_STATE.JUMP && PlayerState != PLAYER_STATE.FALLING)
                {
                    PlayerState = PLAYER_STATE.L_RUN;
                }
            }

            if (PlayerState != PLAYER_STATE.JUMP && PlayerState != PLAYER_STATE.FALLING &&
                CurrentKeyState.IsKeyDown(Keys.Z) && PrevKeyState.IsKeyUp(Keys.Z))
            {
                IsGrounded    = false;
                PlayerState   = PLAYER_STATE.JUMP;
                IsJumpPressed = true;
            }

            if (/*PlayerState == PLAYER_STATE.JUMP && PlayerState != PLAYER_STATE.FALLING
                 * && */CurrentKeyState.IsKeyUp(Keys.Z) && PrevKeyState.IsKeyDown(Keys.Z))
            {
                IsJumpPressed = false;
            }

            PrevKeyState = CurrentKeyState;
        }
Beispiel #2
0
        public void Update()
        {
            KeyState = Keyboard.GetState();

            // Directional controls
            // Horizontal
            if (KeyState.IsKeyDown(Keys.Left))
            {
                Left  = true;
                Right = false;
            }
            else if (KeyState.IsKeyDown(Keys.Right))
            {
                Left  = false;
                Right = true;
            }

            if (KeyState.IsKeyUp(Keys.Left))
            {
                Left = false;
            }

            if (KeyState.IsKeyUp(Keys.Right))
            {
                Right = false;
            }

            // Vertical
            if (KeyState.IsKeyDown(Keys.Up))
            {
                Up   = true;
                Down = false;
            }
            else if (KeyState.IsKeyDown(Keys.Down))
            {
                Up   = false;
                Down = true;
            }

            if (KeyState.IsKeyUp(Keys.Up))
            {
                Up = false;
            }

            if (KeyState.IsKeyUp(Keys.Down))
            {
                Down = false;
            }

            // Panning
            // Vertical
            if (KeyState.IsKeyDown(Keys.NumPad8))
            {
                PanU = true;
                PanD = false;
            }
            else if (KeyState.IsKeyDown(Keys.NumPad2))
            {
                PanU = false;
                PanD = true;
            }

            if (KeyState.IsKeyUp(Keys.NumPad8))
            {
                PanU = false;
            }

            if (KeyState.IsKeyUp(Keys.NumPad2))
            {
                PanD = false;
            }

            // Horizontal

            if (KeyState.IsKeyDown(Keys.NumPad4))
            {
                PanL = true;
                PanR = false;
            }
            else if (KeyState.IsKeyDown(Keys.NumPad6))
            {
                PanL = false;
                PanR = true;
            }

            if (KeyState.IsKeyUp(Keys.NumPad4))
            {
                PanL = false;
            }

            if (KeyState.IsKeyUp(Keys.NumPad6))
            {
                PanR = false;
            }

            // Control game states
            if (KeyState.IsKeyDown(Keys.F1) && PrevKeyState.IsKeyUp(Keys.F1))
            {
                State = InputState.Play;
            }
            else if (KeyState.IsKeyDown(Keys.F5) && PrevKeyState.IsKeyUp(Keys.F5))
            {
                State = InputState.Playtest;
            }
            else if (KeyState.IsKeyDown(Keys.F8) && PrevKeyState.IsKeyUp(Keys.F8))
            {
                State = InputState.RunLog;
            }
            else if (KeyState.IsKeyDown(Keys.F12) && PrevKeyState.IsKeyUp(Keys.F12))
            {
                State = InputState.Edit;
            }

            PrevKeyState = KeyState;
            PrevState    = State;
        }
        public void Update(Cursor cursor, AnimationGroup animGroup, Camera2D camera)
        {
            KeyState         = Keyboard.GetState();
            this.cursor      = cursor;
            AnimGroup        = animGroup;
            Camera           = camera;
            currentAnimation = animGroup.CurrentAnimation;

            if (cursor.State != CursorState.TextEdit)
            {
                if (KeyState.IsKeyDown(Keys.NumPad4))
                {
                    //camera.Position += new Vector2(-4, 0);
                    foreach (Frame frame in currentAnimation.Frames)
                    {
                        foreach (Part part in frame.Parts)
                        {
                            part.Position += new Vector2(-4, 0);
                        }
                    }
                }
                else if (KeyState.IsKeyDown(Keys.NumPad6))
                {
                    //camera.Position += new Vector2(4, 0);
                    foreach (Frame frame in currentAnimation.Frames)
                    {
                        foreach (Part part in frame.Parts)
                        {
                            part.Position += new Vector2(4, 0);
                        }
                    }
                }

                if (KeyState.IsKeyDown(Keys.NumPad8))
                {
                    //camera.Position += new Vector2(0, -4);
                    foreach (Frame frame in currentAnimation.Frames)
                    {
                        foreach (Part part in frame.Parts)
                        {
                            part.Position += new Vector2(0, -4);
                        }
                    }
                }
                else if (KeyState.IsKeyDown(Keys.NumPad2))
                {
                    //camera.Position += new Vector2(0, 4);
                    foreach (Frame frame in currentAnimation.Frames)
                    {
                        foreach (Part part in frame.Parts)
                        {
                            part.Position += new Vector2(0, 4);
                        }
                    }
                }
                if (KeyState.IsKeyDown(Keys.OemPlus) && PrevKeyState.IsKeyUp(Keys.OemPlus))
                {
                    camera.Zoom += 0.25f;
                }
                if (KeyState.IsKeyDown(Keys.OemMinus) && PrevKeyState.IsKeyUp(Keys.OemMinus))
                {
                    camera.Zoom -= 0.25f;
                }
                if (KeyState.IsKeyDown(Keys.Q) && PrevKeyState.IsKeyUp(Keys.Q))
                {
                    animGroup.CurrentAnimation.DrawBounds = !animGroup.CurrentAnimation.DrawBounds;
                }
                if (KeyState.IsKeyDown(Keys.W) && PrevKeyState.IsKeyUp(Keys.W))
                {
                    animGroup.DuplicateAnimation();
                }
            }

            if (KeyState != null)
            {
                PrevKeyState = KeyState;
            }
        }
Beispiel #4
0
        public void Update(Matrix transform)
        {
            //if (KeyState != null) { PrevKeyState = KeyState; }
            if (MouseState != null)
            {
                PrevMouseState = MouseState;
            }
            if (boundsX != 0)
            {
                prevBoundsX = boundsX;
            }
            if (boundsY != 0)
            {
                prevBoundsY = boundsY;
            }

            MouseState = Mouse.GetState();
            KeyState   = Keyboard.GetState();
            //Position = new Vector2(MouseState.X, MouseState.Y);

            Position = Vector2.Transform(new Vector2(MouseState.X, MouseState.Y), transform);

            DestRect = new Rectangle((int)Position.X, (int)Position.Y, 1, 1);

            Tip.Update(new Vector2(MouseState.X + SourceRectangles[(int)State].SourceRect.Width, MouseState.Y + SourceRectangles[(int)State].SourceRect.Height));

            if (Frame != null)
            {
                if (Frame.SelectedPart != null)
                {
                    SelectedPart = Frame.SelectedPart;
                }
                else
                {
                    SelectedPart = null;
                }
            }

            if (MouseState.Y > graphics.GraphicsDevice.Viewport.Height - 64)
            {
                State         = CursorState.Arrow;
                IsOutOfBounds = true;
            }
            else
            {
                if (IsOutOfBounds)
                {
                    State         = PrevState;
                    IsOutOfBounds = false;
                }
                if (State != CursorState.TextEdit)
                {
                    if (KeyState.IsKeyDown(Keys.A) || MouseState.RightButton == ButtonState.Pressed)
                    {
                        State = CursorState.Arrow;
                    }
                    else if (KeyState.IsKeyDown(Keys.F))
                    {
                        State = CursorState.OpenHand;
                    }
                    else if (KeyState.IsKeyDown(Keys.D))
                    {
                        State = CursorState.Pencil;
                    }
                    else if (KeyState.IsKeyDown(Keys.E))
                    {
                        State = CursorState.Eraser;
                    }
                    else if (KeyState.IsKeyDown(Keys.R))
                    {
                        State = CursorState.Rotate;
                    }
                    else if (KeyState.IsKeyDown(Keys.B))
                    {
                        State = CursorState.AdjustBounds;
                    }
                }
            }

            if (KeyState.IsKeyDown(Keys.Up) && PrevKeyState.IsKeyUp(Keys.Up))
            {
                Frame.SwapPartOrder(true);
            }
            if (KeyState.IsKeyDown(Keys.Down) && PrevKeyState.IsKeyUp(Keys.Down))
            {
                Frame.SwapPartOrder(false);
            }

            if (KeyState.IsKeyDown(Keys.Right) && PrevKeyState.IsKeyUp(Keys.Right))
            {
                SelectedPart = Frame.NextPart();
            }
            if (KeyState.IsKeyDown(Keys.Left) && PrevKeyState.IsKeyUp(Keys.Left))
            {
                SelectedPart = Frame.PreviousPart();
            }

            if (MouseState.ScrollWheelValue < PrevMouseState.ScrollWheelValue)
            {
                SelectedPart = Frame.NextPart();
            }
            if (MouseState.ScrollWheelValue > PrevMouseState.ScrollWheelValue)
            {
                SelectedPart = Frame.PreviousPart();
            }

            if (KeyState.IsKeyDown(Keys.X) && PrevKeyState.IsKeyUp(Keys.X))
            {
                SelectedPart.IsFlipped = !SelectedPart.IsFlipped;
            }

            switch (State)
            {
            case CursorState.Arrow:
                break;

            case CursorState.OpenHand:
                PrevState = CursorState.OpenHand;
                if (MouseState.LeftButton == ButtonState.Pressed)
                {
                    State = CursorState.ClosedHand;
                }
                break;

            case CursorState.ClosedHand:
                PrevState = CursorState.ClosedHand;
                if (MouseState.LeftButton != ButtonState.Pressed)
                {
                    State = CursorState.OpenHand;
                }
                if (SelectedPart != null)
                {
                    if (DestRect.Intersects(SelectedPart.DestRect))
                    {
                        SelectedPart.Position    = new Vector2(MouseState.X, MouseState.Y);
                        SelectedPart.DestRect    = new Rectangle((int)SelectedPart.Position.X - SelectedPart.SourceRect.Width / 2, (int)SelectedPart.Position.Y - SelectedPart.SourceRect.Height / 2, SelectedPart.SourceRect.Width, SelectedPart.SourceRect.Width);
                        SelectedPart.Origin      = new Vector2(SelectedPart.DestRect.Width / 2, SelectedPart.DestRect.Height / 2);
                        SelectedPart.WorldOrigin = new Vector2((int)SelectedPart.Position.X, (int)SelectedPart.Position.Y);
                    }
                }
                break;

            case CursorState.AdjustBounds:
                PrevState = CursorState.AdjustBounds;
                if (PrevMouseState.LeftButton == ButtonState.Released && MouseState.LeftButton == ButtonState.Pressed)
                {
                    startBoundsX = MouseState.X;
                    startBoundsY = MouseState.Y;
                }
                else if (PrevMouseState.LeftButton == ButtonState.Pressed && MouseState.LeftButton == ButtonState.Pressed)
                {
                    boundsX      = MouseState.X;
                    boundsY      = MouseState.Y;
                    boundsWidth  = Math.Abs(boundsX - startBoundsX);
                    boundsHeight = Math.Abs(boundsY - startBoundsY);
                    BoundsRect   = new Rectangle(startBoundsX, startBoundsY, boundsWidth, boundsHeight);
                }
                break;

            case CursorState.Pencil:
                PrevState = CursorState.Pencil;
                if (MouseState.LeftButton == ButtonState.Pressed)
                {
                    if (StandbyPart != null)
                    {
                        partAdded               = false;
                        StandbyPart.ID          = IDCount;
                        StandbyPart.Position    = new Vector2(MouseState.X, MouseState.Y);
                        StandbyPart.DestRect    = new Rectangle((int)StandbyPart.Position.X - StandbyPart.SourceRect.Width / 2, (int)StandbyPart.Position.Y - StandbyPart.SourceRect.Height / 2, StandbyPart.SourceRect.Width, StandbyPart.SourceRect.Width);
                        StandbyPart.Origin      = new Vector2(StandbyPart.DestRect.Width / 2, StandbyPart.DestRect.Height / 2);
                        StandbyPart.WorldOrigin = new Vector2((int)StandbyPart.Position.X, (int)StandbyPart.Position.Y);
                        StandbyPart.State       = PartState.Selected;
                    }
                }

                if (!partAdded)
                {
                    if (MouseState.LeftButton == ButtonState.Released)
                    {
                        if (Frame.Parts.Length < 1)
                        {
                            Frame.AddPart(StandbyPart);
                        }
                        else
                        {
                            Frame.InsertPart(StandbyPart);
                        }
                        IDCount++;
                        partAdded   = true;
                        StandbyPart = new Part(StandbyPart.Texture, StandbyPart.SourceRect, StandbyPart.DestRect);
                    }
                }

                break;

            case CursorState.Translate:
                PrevState = CursorState.Translate;
                break;

            case CursorState.Eraser:
                PrevState = CursorState.Eraser;
                if (SelectedPart != null)
                {
                    if (DestRect.Intersects(SelectedPart.DestRect))
                    {
                        if (MouseState.LeftButton == ButtonState.Pressed && PrevMouseState.LeftButton == ButtonState.Released)
                        {
                            Frame.RemovePart(SelectedPart);
                        }
                    }
                }
                break;

            case CursorState.Rotate:
                PrevState = CursorState.Rotate;
                if (SelectedPart != null)
                {
                    if (MouseState.LeftButton == ButtonState.Pressed)
                    {
                        if (MouseState.X < SelectedPart.WorldOrigin.X)
                        {
                            SelectedPart.Rotation -= .001f * (Math.Abs(MouseState.X - SelectedPart.WorldOrigin.X));
                        }
                        else if (MouseState.X > SelectedPart.WorldOrigin.X)
                        {
                            SelectedPart.Rotation += .001f * (Math.Abs(MouseState.X - SelectedPart.WorldOrigin.X));
                        }
                    }
                }
                break;

            case CursorState.TextEdit:
                Keys[] currentKeys = KeyState.GetPressedKeys();
                Keys[] prevKeys    = PrevKeyState.GetPressedKeys();
                bool   found       = false;
                for (int i = 0; i < currentKeys.Length; i++)
                {
                    found = false;
                    for (int j = 0; j < prevKeys.Length; j++)
                    {
                        if (currentKeys[i] == prevKeys[j])
                        {
                            // The two Keys arrays match so we don't need to add to the current string.
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        // The two Keys arrays don't match so we need to add a new letter to the current string.
                        PressKey(currentKeys[i]);
                    }
                }
                break;
            }
            if (KeyState != null)
            {
                PrevKeyState = KeyState;
            }
        }