Beispiel #1
0
 public static List<Path> createPath(Grid level)
 {
     pos = new Vector2(0, 0);
     char state = ' ';
     char lastState = ' ';
     List<Path> paths = new List<Path>();
     for (int i = 0; i < level.getCellsVertical(); i++)
         if (level.getGrid()[0, i] == 1)
         {
             posYStart = (int)(pos.Y = i);
             break;
         }
     Boolean done = false;
     do
     {
         int position;
         if ((position = checkRight(pos, level)) != -1 && lastState != 'r' && lastState != 'l')
         {
             position--;
             paths.Add(new Path(true, true, position * level.getCellWidth()));
             recs.Add(new Rectangle((int)pos.X * level.getCellWidth(),(int)pos.Y * level.getCellHeight(),position * level.getCellWidth(),30));
             pos.X = ++position;
             state = 'r';
         }
         else if ((position = checkLeft(pos, level)) != -1 && lastState != 'l' && lastState != 'r')
         {
             position++;
             paths.Add(new Path(true, false, position * level.getCellWidth()));
             recs.Add(new Rectangle((int)position * level.getCellWidth(),(int)pos.Y * level.getCellHeight(),(int)pos.X * level.getCellWidth(),30));
             pos.X = --position;
             state = 'l';
         }
         if ((position = checkDown(pos, level)) != -1 && lastState != 'd' && lastState != 'u')
         {
             position--;
             paths.Add(new Path(false, true, position * level.getCellHeight()));
             recs.Add(new Rectangle((int)pos.X * level.getCellWidth(), (int)pos.Y * level.getCellHeight(), 30, position * level.getCellHeight()));
             pos.Y = ++position;
             state = 'd';
         }
         else if ((position = checkUp(pos, level)) != -1 && lastState != 'u' && lastState != 'd')
         {
             position--;
             paths.Add(new Path(false, false, position * level.getCellHeight()));
             recs.Add(new Rectangle((int)pos.X * level.getCellWidth(), (int)position * level.getCellHeight(), 30, (int)pos.Y * level.getCellHeight()));
             pos.Y = ++position;
             state = 'u';
         }
         if (lastState == state)
             done = true;
         lastState = state;
     }
     while(!done);
     recs.Add(new Rectangle(0,0,0,0));
     return paths;
 }
Beispiel #2
0
 public static int checkDown(Vector2 pos, Grid level)
 {
     if (pos.Y == level.getCellsVertical() - 1 || level.getGrid()[(int)pos.X, (int)pos.Y + 1] == 2)
         return -1;
     for (int i = (int)pos.Y; i < level.getCellsVertical(); i++)
         if (level.getGrid()[(int)pos.X, i] == 2)
             return --i;
         else if (i == level.getCellsVertical() - 1)
             return i;
     return -1;
 }