Esempio n. 1
0
        public override void MousePressed(MouseState mouseState, Vector2 offset)
        {
            PlatformerEditor actualGame = (PlatformerEditor)UIManager.Game;

            if (mouseState.MiddlePressed())
            {
                PanIsPressed = true;
            }
            else if (mouseState.LeftPressed())
            {
                Vector2 mousePos = new Vector2(mouseState.X, mouseState.Y) - offset - Position - SoftOffset;
                if (actualGame.CurrentWorldLayer != null)
                {
                    WorldItem item = new WorldItem(UIManager, actualGame.CurrentWorldItemType, SnapPosition(mousePos), actualGame.CurrentWorldLayer.DrawLayer);
                    actualGame.CurrentWorldLayer.WorldItems.Add(item);
                }
            }
            else if (mouseState.RightPressed())
            {
                if (actualGame.CurrentWorldLayer != null)
                {
                    Vector2 mousePos = GetMousePosition(offset);
                    for (int i = 0; i < actualGame.CurrentWorldLayer.WorldItems.Count; i++)
                    {
                        WorldItem item = actualGame.CurrentWorldLayer.WorldItems[i];
                        if (PlatformerMath.PointInRectangle(new Rectangle(item.Position.ToPoint(), item.Size.ToPoint()), mousePos))
                        {
                            actualGame.CurrentWorldLayer.WorldItems.RemoveAt(i);
                            break;
                        }
                    }
                }
            }
            base.MousePressed(mouseState, offset);
        }
Esempio n. 2
0
 public override void MousePressed(MouseState mouseState, Vector2 offset)
 {
     if (mouseState.LeftPressed())
     {
         Click?.Invoke();
         FadeAlpha = OnClickFadeReset;
     }
 }
Esempio n. 3
0
        public override void MouseReleased(MouseState mouseState, Vector2 offset)
        {
            PlatformerEditor actualGame = (PlatformerEditor)UIManager.Game;

            if (!mouseState.MiddlePressed())
            {
                PanIsPressed = false;
            }
            else if (!mouseState.LeftPressed())
            {
                if (!(actualGame.CurrentWorldLayer != null && actualGame.CurrentWorldItemType != null))
                {
                    PanIsPressed = false;
                }
            }
            base.MouseReleased(mouseState, offset);
        }
Esempio n. 4
0
        /// <summary>
        /// updates the for input and updates the ui elements
        /// </summary>
        public void Update()
        {
            MouseState    = Mouse.GetState();
            KeyboardState = Keyboard.GetState();
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || KeyboardState.IsKeyDown(Keys.Escape))
            {
                Game.Exit();
            }
            TopUINode.Update();
            //mouse clicks
            Vector2 mousePos = new Vector2(MouseState.X, MouseState.Y);

            if ((MouseState.LeftPressed() && !PreviousMouseState.LeftPressed()) || (MouseState.RightPressed() && !PreviousMouseState.RightPressed()) || (MouseState.MiddlePressed() && !PreviousMouseState.MiddlePressed()))
            {
                CurrentInput = null;
                TopUINode.MousePressed(MouseState, new Vector2(0, 0));
            }
            if ((!MouseState.LeftPressed() && PreviousMouseState.LeftPressed()) || (!MouseState.RightPressed() && PreviousMouseState.RightPressed()) || (!MouseState.MiddlePressed() && PreviousMouseState.MiddlePressed()))
            {
                TopUINode.MouseReleased(MouseState, new Vector2(0, 0));
            }
            //scrolling
            int   scrollAmount = MouseState.ScrollWheelValue;
            float scrollValue  = Math.Sign(lastScrollAmount - scrollAmount) * ScrollMultiplier;

            if (scrollValue != 0)
            {
                TopUINode.Scroll(MouseState, scrollValue);
            }
            //text input
            Keys[]      pressedKeys  = KeyboardState.GetPressedKeys();
            List <Keys> newKeys      = FindChanges(pressedKeys, lastPressedKeys);
            List <Keys> releasedKeys = FindChanges(lastPressedKeys, pressedKeys);

            if (newKeys.Contains(Keys.LeftShift) || newKeys.Contains(Keys.RightShift))
            {
                InputShifted = true;
            }
            else if (!releasedKeys.Contains(Keys.LeftShift) && !releasedKeys.Contains(Keys.RightShift))
            {
                InputShifted = false;
            }
            lastPressedKeys = pressedKeys;
            if (CurrentInput != null)
            {
                for (int i = 0; i < newKeys.Count; i++)
                {
                    Keys   key       = newKeys[i];
                    char   keyChar   = KeyToChar(key, InputShifted);
                    char[] validKeys = CurrentInput.ValidKeys;
                    bool   isValid   = false;
                    for (int j = 0; j < validKeys.Length; j++)
                    {
                        if (validKeys[j].Equals(keyChar))
                        {
                            isValid = true;
                            break;
                        }
                    }
                    if (isValid)
                    {
                        CurrentInput.Text = CurrentInput.Text + keyChar;
                    }
                    else
                    {
                        if (key.Equals(Keys.Back))
                        {
                            if (CurrentInput.Text.Length > 0)
                            {
                                CurrentInput.Text = CurrentInput.Text.Substring(0, CurrentInput.Text.Length - 1);
                            }
                        }
                    }
                }
            }

            PreviousMouseState    = MouseState;
            PreviousKeyboardState = KeyboardState;
            lastScrollAmount      = scrollAmount;
        }
Esempio n. 5
0
        public override void Update()
        {
            MouseState = Mouse.GetState();
            float moveSpeed = AirSpeed;

            if (Room.FindCollision(new Rectangle((Position + Sprite.Offset + new Vector2(0, 1)).ToPoint(), Sprite.Size.ToPoint()), "obj_block") != null)
            {
                Grounded  = true;
                moveSpeed = GroundSpeed;
                if (Math.Abs(Velocity.X) > GroundFriction)
                {
                    Velocity.X -= Math.Sign(Velocity.X) * GroundFriction;
                }
                else
                {
                    Velocity.X = 0;
                }
                JumpsLeft = MaxJumpsLeft;
            }
            else
            {
                Grounded = false;
            }
            Input.Update();
            if (Light != null)
            {
                Light.Position = Position;
            }
            if (Jump.Pressed && JumpsLeft > 0 && JumpCooldown == 0)
            {
                if (Grounded)
                {
                    Room.Sounds.PlaySound(JumpSound);
                }
                else
                {
                    Room.Sounds.PlaySound(AirJumpSound);
                }
                Velocity.Y = JumpSpeed;
                JumpsLeft--;
                JumpCooldown = MaxJumpCooldown;
                if (JumpsLeft == 0)
                {
                    if (Left.Pressed && Velocity.X > -2)
                    {
                        Velocity.X = -2;
                    }
                    if (Right.Pressed && Velocity.X < 2)
                    {
                        Velocity.X = 2;
                    }
                }
                Grounded = false;
            }
            if (Left.Pressed && Velocity.X > -MaxVelocity.X)
            {
                Velocity.X -= moveSpeed;
            }
            if (Right.Pressed && Velocity.X < MaxVelocity.X)
            {
                Velocity.X += moveSpeed;
            }
            if (Velocity.X > MinDirectionChangeSpeed)
            {
                Sprite.SpriteEffect = SpriteEffects.None;
            }
            else if (Velocity.X < -MinDirectionChangeSpeed)
            {
                Sprite.SpriteEffect = SpriteEffects.FlipHorizontally;
            }
            if (Math.Abs(Velocity.X) >= MinRunAnimationSpeed)
            {
                Sprite.Change(RunImage);
            }
            else
            {
                Sprite.Change(IdleImage);
            }
            Item?.Update();
            if (MouseState.LeftPressed())
            {
                Item?.DoUse(this);
            }
            PlatformerGame game = (PlatformerGame)Room.Engine.Game;

            if (Position.X > Room.Width && Velocity.X > 0)
            {
                Position.X -= Room.Width;
                game.GoToRoom(game.CurrentRoomX + 1, game.CurrentRoomY);
                JumpsLeft = MaxJumpsLeft;
            }
            else if (Position.X < 0 && Velocity.X < 0)
            {
                Position.X += Room.Width;
                game.GoToRoom(game.CurrentRoomX - 1, game.CurrentRoomY);
                JumpsLeft = MaxJumpsLeft;
            }
            else if (Position.Y > Room.Height && Velocity.Y > 0)
            {
                Position.Y -= Room.Height;
                game.GoToRoom(game.CurrentRoomX, game.CurrentRoomY + 1);
                JumpsLeft = MaxJumpsLeft;
            }
            else if (Position.Y < 0 && Velocity.Y < 0)
            {
                Position.Y += Room.Height;
                game.GoToRoom(game.CurrentRoomX, game.CurrentRoomY - 1);
                JumpsLeft = MaxJumpsLeft;
            }
            Rectangle hitbox = GetHitbox();

            hitbox.Location += Position.ToPoint();
            GameObject itemObject = Room.FindCollision(hitbox, "obj_item");

            if (itemObject != null)
            {
                ItemObject itemContainer = (ItemObject)itemObject;
                Item = itemContainer.Item;
                UpgradeObject.Item = Item;
                Room.GameObjectList.Remove(itemObject);
            }
            else
            {
                itemObject = Room.FindCollision(hitbox, "obj_upgrade");
                if (itemObject != null)
                {
                    UpgradeObject upgradeObject = (UpgradeObject)itemObject;
                    upgradeObject.Upgrade();
                }
            }
            if (JumpCooldown > 0)
            {
                JumpCooldown--;
            }
            Velocity.Y += Gravity;
            base.Update();
            PrevMouseState = MouseState;
        }