v0.7.5: added new functionality to maze generation
This commit is contained in:
parent
71b406c84d
commit
de10df7866
|
@ -56,6 +56,19 @@ public class Maze {
|
|||
return generate(r.width()+1, r.height()+1);
|
||||
}
|
||||
|
||||
public static boolean[][] generate(Rect r, int[] terrain, int width, int filledTerrainType){
|
||||
boolean[][] maze = new boolean[r.width()][r.height()];
|
||||
for (int x = 0; x < maze.length; x++) {
|
||||
for (int y = 0; y < maze[0].length; y++) {
|
||||
if (terrain[x + r.left + (y + r.top)*width] == filledTerrainType){
|
||||
maze[x][y] = FILLED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return generate(maze);
|
||||
}
|
||||
|
||||
public static boolean[][] generate(int width, int height){
|
||||
return generate(new boolean[width][height]);
|
||||
}
|
||||
|
@ -123,22 +136,32 @@ public class Maze {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static boolean allowDiagonals = false;
|
||||
|
||||
private static boolean checkValidMove( boolean[][] maze, int x, int y, int[] mov){
|
||||
int sideX = 1 - Math.abs(mov[0]);
|
||||
int sideY = 1 - Math.abs(mov[1]);
|
||||
|
||||
//checking two tiles forward in the movement, and the tiles to their left/right
|
||||
for (int i = 0; i < 2; i ++) {
|
||||
x += mov[0];
|
||||
y += mov[1];
|
||||
//checks if tiles we're examining are valid and open
|
||||
if ( x > 0 && x < maze.length-1 && y > 0 && y < maze[0].length-1 &&
|
||||
!maze[x][y] && !maze[x + sideX][y+ sideY] && !maze[x - sideX][y - sideY]){
|
||||
continue;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
x += mov[0];
|
||||
y += mov[1];
|
||||
|
||||
if ( x <= 0 || x >= maze.length-1 || y <= 0 || y >= maze[0].length-1){
|
||||
return false;
|
||||
} else if (maze[x][y] || maze[x + sideX][y + sideY] || maze[x - sideX][y - sideY]){
|
||||
return false;
|
||||
}
|
||||
|
||||
x += mov[0];
|
||||
y += mov[1];
|
||||
|
||||
if ( x <= 0 || x >= maze.length-1 || y <= 0 || y >= maze[0].length-1){
|
||||
return false;
|
||||
} else if (maze[x][y]){
|
||||
return false;
|
||||
} else if (!allowDiagonals && (maze[x + sideX][y + sideY] || maze[x - sideX][y - sideY])){
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ public class MazeRoom extends Room {
|
|||
Painter.fill(level, this, 1, Terrain.EMPTY);
|
||||
|
||||
//true = space, false = wall
|
||||
Maze.allowDiagonals = false;
|
||||
boolean[][] maze = Maze.generate(this);
|
||||
|
||||
Painter.fill(level, this, 1, Terrain.EMPTY);
|
||||
|
|
|
@ -33,6 +33,7 @@ public class MazeConnectionRoom extends ConnectionRoom {
|
|||
Painter.fill(level, this, 1, Terrain.EMPTY);
|
||||
|
||||
//true = space, false = wall
|
||||
Maze.allowDiagonals = false;
|
||||
boolean[][] maze = Maze.generate(this);
|
||||
|
||||
Painter.fill(level, this, 1, Terrain.EMPTY);
|
||||
|
|
|
@ -62,6 +62,7 @@ public class SecretMazeRoom extends SecretRoom {
|
|||
Painter.fill(level, this, 1, Terrain.EMPTY);
|
||||
|
||||
//true = space, false = wall
|
||||
Maze.allowDiagonals = false;
|
||||
boolean[][] maze = Maze.generate(this);
|
||||
boolean[] passable = new boolean[width()*height()];
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user