Пример #1
0
        public static void Update()
        {
            if (mouse.LeftClick())
            {
                if (spriteSheetRectangle.Contains(mouse.clickRectangle))
                {
                    ChangeSelectedTile();
                }
            }
            if (mouse.LeftHeld())
            {
                if (spriteSheetRectangle.Contains(mouse.clickRectangle))
                {
                    dragging = true;
                }
            }
            if (dragging)
            {
                if (MouseIsInWorkingArea())
                {
                    dragging = false;
                }
                int x = ((int)mouse.Position.X - (int)currTileSetPosition.X) / TileSet.tileWidth;
                int y = ((int)mouse.Position.Y - (int)currTileSetPosition.Y) / TileSet.tileHeight;

                markerRect.Width  = TileSet.tileWidth * (x - currentTileX + 1);
                markerRect.Height = TileSet.tileHeight * (y - currentTileY + 1);
                if (markerRect.Width > defaultRect.Width || markerRect.Height > defaultRect.Height)
                {
                    multipleSelected = true;
                    multipleTileX    = x - currentTileX;
                    multipleTileY    = y - currentTileY;
                }
                if (mouse.LeftReleased())
                {
                    dragging = false;
                }
            }
            #region Check For Input
            if (keyboard.IsHeld(Keys.LeftControl))
            {
                if (keyboard.JustPressed(Keys.S))
                {
                    Save();
                }
            }

            if (!blocksMode)
            {
                if (Scripts.KeyIsPressed(Keys.Space))
                {
                    if (mouse.LeftHeld() || mouse.LeftClick())
                    {
                        if (MouseIsInWorkingArea())
                        {
                            ChangeTile();
                        }
                    }
                    if (mouse.RightHeld() || mouse.RightClick())
                    {
                        if (MouseIsInWorkingArea())
                        {
                            RemoveTile();
                        }
                    }
                }
                else
                {
                    if (mouse.LeftClick())
                    {
                        if (MouseIsInWorkingArea())
                        {
                            ChangeTile();
                        }
                    }
                    if (mouse.RightClick())
                    {
                        if (MouseIsInWorkingArea())
                        {
                            RemoveTile();
                        }
                    }
                }
                if (keyboard.IsHeld(Keys.LeftControl))
                {
                    if (keyboard.JustPressed(Keys.C))
                    {
                        Main.tilemap.ClearTileMap();
                    }
                }
            }
            else
            {
                foreach (Rectangle rect in rectsToRemove)
                {
                    Main.blockRects.Remove(rect);
                }

                if (keyboard.IsHeld(Keys.LeftControl))
                {
                    if (keyboard.JustPressed(Keys.C))
                    {
                        Main.blockRects.Clear();
                    }
                }
                if (MouseIsInWorkingArea())
                {
                    #region AddRects
                    if (mouse.LeftClick())
                    {
                        rectToBeAdded  = new Rectangle((int)mouse.RealPosition.X, (int)mouse.RealPosition.Y, 0, 0);
                        isDraggingRect = true;
                        if (keyboard.IsHeld(Keys.LeftShift))
                        {
                            Vector2 snappedPosition = GetSnappedMousePosition();
                            rectToBeAdded = MathAid.UpdateRectViaVector(rectToBeAdded, snappedPosition);
                        }
                    }
                    if (isDraggingRect)
                    {
                        if (keyboard.IsHeld(Keys.LeftShift))
                        {
                            Vector2 snappedPosition = GetSnappedMousePosition();
                            rectToBeAdded.Width  = (int)snappedPosition.X - rectToBeAdded.X + TileSet.tileWidth;
                            rectToBeAdded.Height = (int)snappedPosition.Y - rectToBeAdded.Y + TileSet.tileHeight;
                        }
                        else
                        {
                            rectToBeAdded.Width  = (int)mouse.RealPosition.X - rectToBeAdded.X;
                            rectToBeAdded.Height = (int)mouse.RealPosition.Y - rectToBeAdded.Y;
                        }
                        if (mouse.LeftReleased())
                        {
                            AddRect();
                        }
                    }
                    #endregion

                    #region RemoveRects
                    if (Scripts.KeyIsPressed(Keys.Space))
                    {
                        if (mouse.RightClick() || mouse.RightHeld())
                        {
                            RemoveRects();
                        }
                    }
                    else
                    {
                        if (mouse.RightClick())
                        {
                            RemoveRects();
                        }
                    }
                    #endregion
                }
                else
                {
                    if (isDraggingRect)
                    {
                        isDraggingRect = false;
                    }
                }
            }
            if (keyboard.JustPressed(Keys.B))
            {
                blocksMode = !blocksMode;
            }
            #endregion
        }
Пример #2
0
 protected void UpdateRect()
 {
     walkingRect = MathAid.UpdateRectViaVector(walkingRect, position - walkingOrigin);
     rect        = MathAid.UpdateRectViaVector(rect, position - origin);
 }