Esempio n. 1
0
        private void gridPanel_Click(object sender, MouseEventArgs e)
        {
            if (shiftPressed && ctrlPressed)
            {
                endX = (e.X + (int)paintOffsetX - initDrawOffsetX) / rectSize;
                endY = (e.Y + (int)paintOffsetY - initDrawOffsetY) / rectSize;
                endLabel.Text = "Level end position (" + endX + "," + endY + ")";

                InvalidateAndUpdate(gridPanel);
            }
            else if (shiftPressed)
            {
                playerX = (e.X + (int)paintOffsetX - initDrawOffsetX) / rectSize;
                playerY = (e.Y + (int)paintOffsetY - initDrawOffsetY) / rectSize;
                playerPosLabel.Text = "Player start position (" + playerX + "," + playerY + ")";

                InvalidateAndUpdate(gridPanel);
            }
            else
            {
                if (isPointWithinBounds(e.X,e.Y))
                {
                    int x = (e.X + (int)paintOffsetX - initDrawOffsetX) / rectSize;
                    int y = (e.Y + (int)paintOffsetY - initDrawOffsetY) / rectSize;
                    Point tempPoint = new Point(rectSize * x - (int)paintOffsetX + initDrawOffsetX, rectSize * y - (int)paintOffsetY + initDrawOffsetY);

                    ICommand com = new DrawTileCommand(this, x, y, tiles[x, y].Image, currentImage);
                    ExecuteAndQueueCommand(com);
                }
            }
        }
Esempio n. 2
0
        private void DrawTileLine(int oldMouseX, int oldMouseY, int newX, int newY)
        {
            int x = newX;
                int y = newY;
                if (oldMouseX >= 0 && oldMouseY >= 0)
                {
                    int distanceX = x - oldMouseX;
                    int distanceY = y - oldMouseY;

                    int dx = -1;
                    int dy = -1;

                    if (distanceX < 0) dx = 1;
                    if (distanceY < 0) dy = 1;

                    distanceX = Math.Abs(distanceX);
                    distanceY = Math.Abs(distanceY);

                    int counter = 0;
                    List<DrawTileCommand> tilesToDraw = new List<DrawTileCommand>();
                    while (distanceX > 0 || distanceY > 0)
                    {

                        if (x + dx < tiles.GetLength(0) && x + dx >= 0 && y + dy < tiles.GetLength(1) && y + dy >= 0)
                        {

                            DrawTileCommand com = new DrawTileCommand(this, x, y, tiles[x, y].Image, currentImage);
                            tilesToDraw.Add(com);
                            //tiles[x, y].Image = currentImage;
                            counter++;
                            if (distanceX > 0) distanceX--;
                            if (distanceY > 0) distanceY--;
                            if (distanceX == 0) dx = 0;
                            if (distanceY == 0) dy = 0;
                            x += dx;
                            y += dy;
                        }

                        else
                        {
                            break;
                        }
                    }

                    ICommand dlc = new DrawLineCommand(this, tilesToDraw);
                    DrawLineList.Add(dlc as DrawLineCommand);
                    dlc.Execute();
                    redoCommandQueue.Clear();

            }
        }