예제 #1
0
 public bool CanBePlaced(Raster RasterGrid, int Xcenter, int Ycenter)
 {
     int[][] temporaryGrid = new int[2 * SideLength][];
     for (int i = 0; i < temporaryGrid.Length; i++)
     {
         temporaryGrid[i] = new int[2 * SideLength];
     }
     DrawRaster(temporaryGrid, SideLength, SideLength);
     for (int i = 0; i < temporaryGrid.Length; i++)
     {
         for (int j = 0; j < temporaryGrid[0].Length; j++)
         {
             if (Ycenter + (i - SideLength) >= RasterGrid.GetHeight() || Xcenter + (j - SideLength) >= RasterGrid.GetHeight() || Ycenter + (i - SideLength) < 0 || Xcenter + (j - SideLength) < 0)
             {
                 return(false);
             }
             if (RasterGrid.getGrid()[Ycenter + (i - SideLength)][Xcenter + (j - SideLength)] != Const.EMPTY && temporaryGrid[i][j] == ID)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
예제 #2
0
        public static void DrawLine(int x0, int y0, int x1, int y1, Raster Grid, int ID)
        {
            int dx, dy;
            int stepX, stepY;

            dx = (x1 - x0);
            dy = (y1 - y0);

            if (dy < 0)
            {
                dy    = -dy;
                stepY = -1;
            }
            else
            {
                stepY = 1;
            }
            if (dx < 0)
            {
                dx    = -dx;
                stepX = -1;
            }
            else
            {
                stepX = 1;
            }

            //Im not totaly sure WHY ??????
            dx <<= 1;
            dy <<= 1;

            //Check if point is inside of the raster and plot first pixel
            if ((0 <= x0) && (x0 < Grid.GetWidth()) && (0 <= y0) && (y0 < Grid.GetHeight()))
            {
                Grid.SetTileID(ID, x0, y0);
            }
            if (dx > dy)
            {
                int fraction = dy - (dx >> 1);
                while (x0 != x1)
                {
                    x0 += stepX;
                    if (fraction >= 0)
                    {
                        y0       += stepY;
                        fraction -= dx;
                    }
                    fraction += dy;
                    if ((0 <= x0) && (x0 < Grid.GetWidth()) && (0 <= y0) && (y0 < Grid.GetHeight()))
                    {
                        Grid.SetTileID(ID, x0, y0);
                    }
                }
            }
            else
            {
                int fraction = dx - (dy >> 1);
                while (y0 != y1)
                {
                    if (fraction >= 0)
                    {
                        x0       += stepX;
                        fraction -= dy;
                    }
                    fraction += dx;
                    y0       += stepY;
                    if ((0 <= x0) && (x0 < Grid.GetWidth()) && (0 <= y0) && (y0 < Grid.GetHeight()))
                    {
                        Grid.SetTileID(ID, x0, y0);
                    }
                }
            }
        }
예제 #3
0
        public static void DrawLineAngle(int xCoordinate, int yCoordinate, int angleInDegrees, int length, Raster grid, int ID)
        {
            //grid.SetTileID(100, 100, 100);
            //Console.WriteLine("WhatTheFuck?");
            //SecondPoint coordinates
            int x2Coordinate;
            int y2Coordinate;

            double yShift = Math.Round(Math.Sin(DegreesToRadians(angleInDegrees)) * length, MidpointRounding.AwayFromZero);
            double xShift = Math.Round(Math.Cos(DegreesToRadians(angleInDegrees)) * length, MidpointRounding.AwayFromZero);

            y2Coordinate = (int)(yCoordinate - yShift);
            x2Coordinate = (int)(xCoordinate - xShift);

            //Console.WriteLine("Angle : {4}   -----  Xshift : {0}, Yshift : {1}  ---- Final X2 : {2},  Final Y2 : {3}", xShift, yShift, x2Coordinate, y2Coordinate, angleInDegrees);

            DrawLine(xCoordinate, yCoordinate, x2Coordinate, y2Coordinate, grid, ID);
        }