public static void newLevel(int posX, int posY, int CWidth, int CHeight, Texture2D image, int lineS, GraphicsDeviceManager g, String mapFile) { currentStage = new Grid(posX, posY, CWidth, CHeight, image, lineS, g, mapFile); }
public static void newLevel(int size, int type,GraphicsDeviceManager g, String mapFile) { currentStage = new Grid(0, 0, size, size, textures.ElementAt(type), 3, g, mapFile); }
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; }
public static int checkUp(Vector2 pos, Grid level) { if (pos.Y == 0 || level.getGrid()[(int)pos.X, (int)pos.Y - 1] == 2) return -1; for (int i = (int)pos.Y; i >= 0; i--) if (level.getGrid()[(int)pos.X, i] == 2) return ++i; else if (i == 0) return 0; return -1; }
public static int checkRight(Vector2 pos, Grid level) { if (pos.X == level.getCellsHorizontal() - 1 || level.getGrid()[(int)pos.X + 1, (int)pos.Y] == 2) return -1; for (int i = (int)pos.X; i < level.getCellsHorizontal(); i++) if (level.getGrid()[i, (int)pos.Y] == 2) return --i; else if (i == level.getCellsHorizontal() - 1) return i; return -1; }
public static int checkLeft(Vector2 pos, Grid level) { if (pos.X == 0 || level.getGrid()[(int)pos.X - 1, (int)pos.Y] == 2) return -1; for (int i = (int)pos.X; i >= 0; i--) if (level.getGrid()[i, (int)pos.Y] == 2) return ++i; else if (i == 0) return 0; return -1; }
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; }