Esempio n. 1
0
 public void UpdateVision()
 {
     SelfVision = new List <WorldObject>();
     int[] lightPosition = new int[] { Self.X, Self.Y };
     if (Self.Direction.Equals(ObjectDirection.UP))
     {
         int counter = 0;
         while (lightPosition[1] >= 0)
         {
             SelfVision.Add(new WorldObject(lightPosition[0], lightPosition[1], WorldState.IS_LIGHT));
             for (int sideLength = 0; sideLength < counter; sideLength++)
             {
                 int checkedLeft  = lightPosition[0] - sideLength;
                 int checkedRight = lightPosition[0] + sideLength;
                 if (checkedLeft >= 0)
                 {
                     SelfVision.Add(new WorldObject(checkedLeft, lightPosition[1], WorldState.IS_LIGHT));
                 }
                 if (checkedRight < WorldGrid.GetLength(0))
                 {
                     SelfVision.Add(new WorldObject(checkedRight, lightPosition[1], WorldState.IS_LIGHT));
                 }
             }
             lightPosition[1]--;
             counter++;
         }
     }
     else if (Self.Direction.Equals(ObjectDirection.DOWN))
     {
         int counter = 0;
         while (lightPosition[1] < WorldGrid.GetLength(1))
         {
             SelfVision.Add(new WorldObject(lightPosition[0], lightPosition[1], WorldState.IS_LIGHT));
             for (int sideLength = 0; sideLength < counter; sideLength++)
             {
                 int checkedLeft  = lightPosition[0] - sideLength;
                 int checkedRight = lightPosition[0] + sideLength;
                 if (checkedLeft >= 0)
                 {
                     SelfVision.Add(new WorldObject(checkedLeft, lightPosition[1], WorldState.IS_LIGHT));
                 }
                 if (checkedRight < WorldGrid.GetLength(0))
                 {
                     SelfVision.Add(new WorldObject(checkedRight, lightPosition[1], WorldState.IS_LIGHT));
                 }
             }
             lightPosition[1]++;
             counter++;
         }
     }
     else if (Self.Direction.Equals(ObjectDirection.LEFT))
     {
         int counter = 0;
         while (lightPosition[0] >= 0)
         {
             SelfVision.Add(new WorldObject(lightPosition[0], lightPosition[1], WorldState.IS_LIGHT));
             for (int sideLength = 0; sideLength < counter; sideLength++)
             {
                 int checkedUp = lightPosition[1] - sideLength;
                 int checkDown = lightPosition[1] + sideLength;
                 if (checkedUp >= 0)
                 {
                     SelfVision.Add(new WorldObject(checkedUp, lightPosition[1], WorldState.IS_LIGHT));
                 }
                 if (checkDown < WorldGrid.GetLength(1))
                 {
                     SelfVision.Add(new WorldObject(checkDown, lightPosition[1], WorldState.IS_LIGHT));
                 }
             }
             lightPosition[1]--;
             counter++;
         }
     }
     else
     {
         int counter = 0;
         while (lightPosition[1] < WorldGrid.GetLength(0))
         {
             SelfVision.Add(new WorldObject(lightPosition[0], lightPosition[1], WorldState.IS_LIGHT));
             for (int sideLength = 0; sideLength < counter; sideLength++)
             {
                 int checkedUp   = lightPosition[0] - sideLength;
                 int checkedDown = lightPosition[0] + sideLength;
                 if (checkedUp >= 0)
                 {
                     SelfVision.Add(new WorldObject(checkedUp, lightPosition[1], WorldState.IS_LIGHT));
                 }
                 if (checkedDown < WorldGrid.GetLength(1))
                 {
                     SelfVision.Add(new WorldObject(checkedDown, lightPosition[1], WorldState.IS_LIGHT));
                 }
             }
             lightPosition[1]--;
             counter++;
         }
     }
 }