private static int[] decideDirection(boolean[][] maze, int x, int y){ //attempts to move up if (Random.Int(4) == 0 && //1 in 4 chance checkValidMove(maze, x, y, new int[]{0, -1})){ return new int[]{0, -1}; } //attempts to move right if (Random.Int(3) == 0 && //1 in 3 chance checkValidMove(maze, x, y, new int[]{1, 0})){ return new int[]{1, 0}; } //attempts to move down if (Random.Int(2) == 0 && //1 in 2 chance checkValidMove(maze, x, y, new int[]{0, 1})){ return new int[]{0, 1}; } //attempts to move left if ( checkValidMove(maze, x, y, new int[]{-1, 0})){ return new int[]{-1, 0}; } return null; }
public static boolean[][] generate(int width, int height){ return generate(new boolean[width][height]); }
mov = decideDirection(maze, x, y); if (mov == null) { fails++; maze[x][y] = FILLED; moves++; } while (Random.Int(moves) == 0 && checkValidMove(maze, x, y, mov));
mov = decideDirection(maze, x, y); if (mov == null) { fails++; maze[x][y] = FILLED; moves++; } while (Random.Int(moves) == 0 && checkValidMove(maze, x, y, mov));
public static boolean[][] generate(int width, int height){ return generate(new boolean[width][height]); }
private static int[] decideDirection(boolean[][] maze, int x, int y){ //attempts to move up if (Random.Int(4) == 0 && //1 in 4 chance checkValidMove(maze, x, y, new int[]{0, -1})){ return new int[]{0, -1}; } //attempts to move right if (Random.Int(3) == 0 && //1 in 3 chance checkValidMove(maze, x, y, new int[]{1, 0})){ return new int[]{1, 0}; } //attempts to move down if (Random.Int(2) == 0 && //1 in 2 chance checkValidMove(maze, x, y, new int[]{0, 1})){ return new int[]{0, 1}; } //attempts to move left if ( checkValidMove(maze, x, y, new int[]{-1, 0})){ return new int[]{-1, 0}; } return null; }
public static boolean[][] generate(Room r){ 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 (x == 0 || x == maze.length - 1 || y == 0 || y == maze[0].length - 1) { maze[x][y] = FILLED; } } } //set spaces where there are doors for (Room.Door d : r.connected.values()) { maze[d.x - r.left][d.y - r.top] = EMPTY; } return generate(maze); }
public static boolean[][] generate(Rect r){ return generate(r.width()+1, r.height()+1); }
public static boolean[][] generate(Room r){ 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 (x == 0 || x == maze.length - 1 || y == 0 || y == maze[0].length - 1) { maze[x][y] = FILLED; } } } //set spaces where there are doors for (Room.Door d : r.connected.values()) { maze[d.x - r.left][d.y - r.top] = EMPTY; } return generate(maze); }
public static boolean[][] generate(Rect r){ return generate(r.width()+1, r.height()+1); }
public void paint( Level level ) { Painter.fill(level, this, 1, Terrain.EMPTY); //true = space, false = wall boolean[][] maze = Maze.generate(this); Painter.fill(level, this, 1, Terrain.EMPTY); for (int x = 0; x < maze.length; x++) for (int y = 0; y < maze[0].length; y++) { if (maze[x][y] == Maze.FILLED) { Painter.fill(level, x + left, y + top, 1, 1, Terrain.WALL); } } }
public void paint( Level level ) { Painter.fill(level, this, 1, Terrain.EMPTY); //true = space, false = wall boolean[][] maze = Maze.generate(this); Painter.fill(level, this, 1, Terrain.EMPTY); for (int x = 0; x < maze.length; x++) for (int y = 0; y < maze[0].length; y++) { if (maze[x][y] == Maze.FILLED) { Painter.fill(level, x + left, y + top, 1, 1, Terrain.WALL); } } }
@Override public void paint(Level level) { super.paint(level); Painter.fill(level, this, 1, Terrain.EMPTY); //true = space, false = wall boolean[][] maze = Maze.generate(this); Painter.fill(level, this, 1, Terrain.EMPTY); for (int x = 0; x < maze.length; x++) for (int y = 0; y < maze[0].length; y++) { if (maze[x][y] == Maze.FILLED) { Painter.fill(level, x + left, y + top, 1, 1, Terrain.WALL); } } for (Door door : connected.values()) { door.set( Door.Type.HIDDEN ); } }
@Override public void paint(Level level) { super.paint(level); Painter.fill(level, this, 1, Terrain.EMPTY); //true = space, false = wall boolean[][] maze = Maze.generate(this); Painter.fill(level, this, 1, Terrain.EMPTY); for (int x = 0; x < maze.length; x++) for (int y = 0; y < maze[0].length; y++) { if (maze[x][y] == Maze.FILLED) { Painter.fill(level, x + left, y + top, 1, 1, Terrain.WALL); } } for (Door door : connected.values()) { door.set( Door.Type.HIDDEN ); } }
boolean[][] maze = Maze.generate(this); boolean[] passable = new boolean[width()*height()];
boolean[][] maze = Maze.generate(this); boolean[] passable = new boolean[width()*height()];