v0.3.3: added a random maze generator, currently used in the tengu boss fight
This commit is contained in:
parent
30668278c2
commit
dd3f866205
|
@ -31,6 +31,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Tengu;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
|
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.keys.IronKey;
|
import com.shatteredpixel.shatteredpixeldungeon.items.keys.IronKey;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.levels.painters.MazePainter;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.SpearTrap;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.SpearTrap;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||||
|
@ -286,6 +287,15 @@ public class PrisonBossLevel extends Level {
|
||||||
HealthIndicator.instance.target(null);
|
HealthIndicator.instance.target(null);
|
||||||
tengu.sprite.kill();
|
tengu.sprite.kill();
|
||||||
|
|
||||||
|
Room maze = new Room();
|
||||||
|
maze.set(10, 1, 31, 29);
|
||||||
|
maze.connected.put(null, new Room.Door(10, 2));
|
||||||
|
maze.connected.put(maze, new Room.Door(20, 29));
|
||||||
|
MazePainter.paint(this, maze);
|
||||||
|
GameScene.resetMap();
|
||||||
|
buildFlagMaps();
|
||||||
|
cleanWalls();
|
||||||
|
|
||||||
GameScene.flash(0xFFFFFF);
|
GameScene.flash(0xFFFFFF);
|
||||||
Sample.INSTANCE.play(Assets.SND_BLAST);
|
Sample.INSTANCE.play(Assets.SND_BLAST);
|
||||||
|
|
||||||
|
@ -397,39 +407,38 @@ public class PrisonBossLevel extends Level {
|
||||||
W, W, W, T, T, T, T, T, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W,
|
W, W, W, T, T, T, T, T, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W,
|
||||||
W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W};
|
W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W};
|
||||||
|
|
||||||
//TODO: while this hardcoded maze is nice, it would be better to have it random each time.
|
|
||||||
private static final int[] MAP_MAZE =
|
private static final int[] MAP_MAZE =
|
||||||
{ W, W, W, W, W, M, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W,
|
{ W, W, W, W, W, M, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W,
|
||||||
W, W, W, W, _, _, _, W, W, W, W, W, W, M, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W,
|
W, W, W, W, _, _, _, W, W, M, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W,
|
||||||
_, _, _, D, _, _, _, D, _, _, _, _, _, _, W, _, _, _, W, _, _, _, _, _, _, _, _, _, W, _, W, W,
|
_, _, _, D, _, _, _, D, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, W, W, W, _, _, _, W, W, W, W, W, W, _, W, _, W, W, W, W, W, W, W, W, W, W, W, _, W, _, W, W,
|
W, W, W, W, _, _, _, W, W, M, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, W, W, W, W, M, W, W, W, W, W, _, _, _, W, _, W, _, _, _, _, _, W, _, _, _, _, _, W, _, W, W,
|
W, W, W, W, W, M, W, W, W, W, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, W, W, W, W, D, W, W, W, W, W, W, W, _, W, _, W, _, W, W, W, W, W, W, W, W, W, _, W, _, W, W,
|
W, W, W, W, W, D, W, W, W, W, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, W, W, W, W, _, W, W, W, W, W, _, _, _, _, _, W, _, _, _, W, _, W, _, _, _, _, _, W, _, W, W,
|
W, W, W, W, W, _, W, W, W, W, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, W, M, W, W, _, W, W, M, W, W, W, W, _, W, W, W, _, W, W, W, _, W, W, W, W, W, _, W, _, W, W,
|
W, W, M, W, W, _, W, W, M, W, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, _, _, _, W, _, W, _, _, _, W, _, _, _, _, _, _, _, W, _, _, _, _, _, _, _, W, _, _, _, W, W,
|
W, _, _, _, W, _, W, _, _, _, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, _, _, _, D, _, D, _, _, _, W, _, W, W, W, W, W, W, W, W, W, _, W, _, W, W, W, W, W, _, W, W,
|
W, _, _, _, D, _, D, _, _, _, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, _, _, _, W, _, W, _, _, _, W, _, W, _, W, _, W, _, W, _, W, _, W, _, W, _, _, _, _, _, W, W,
|
W, _, _, _, W, _, W, _, _, _, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, W, M, W, W, _, W, W, M, W, W, _, W, _, W, _, W, _, W, _, W, _, W, W, W, W, W, W, W, _, W, W,
|
W, W, M, W, W, _, W, W, M, W, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, _, _, _, W, _, W, _, _, _, W, _, W, _, _, _, W, _, _, _, _, _, W, _, W, _, W, _, W, _, W, W,
|
W, _, _, _, W, _, W, _, _, _, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, _, _, _, D, _, D, _, _, _, W, _, W, _, W, W, W, W, W, W, W, _, W, _, W, _, W, _, W, _, W, W,
|
W, _, _, _, D, _, D, _, _, _, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, _, _, _, W, _, W, _, _, _, W, _, _, _, W, _, W, _, _, _, _, _, W, _, _, _, _, _, _, _, W, W,
|
W, _, _, _, W, _, W, _, _, _, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, W, M, W, W, _, W, W, M, W, W, W, W, _, W, _, W, W, W, W, W, _, W, _, W, W, W, W, W, W, W, W,
|
W, W, M, W, W, _, W, W, M, W, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, _, _, _, W, _, W, _, _, _, W, _, _, _, W, _, W, _, W, _, W, _, _, _, W, _, W, _, _, _, W, W,
|
W, _, _, _, W, _, W, _, _, _, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, _, _, _, D, _, D, _, _, _, W, W, W, _, W, _, W, _, W, _, W, _, W, W, W, _, W, W, W, _, W, W,
|
W, _, _, _, D, _, D, _, _, _, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, _, _, _, W, _, W, _, _, _, W, _, _, _, _, _, _, _, _, _, W, _, _, _, _, _, W, _, _, _, W, W,
|
W, _, _, _, W, _, W, _, _, _, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, W, M, W, W, _, W, W, M, W, W, W, W, _, W, W, W, _, W, W, W, _, W, _, W, W, W, _, W, W, W, W,
|
W, W, M, W, W, _, W, W, M, W, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, _, _, _, W, _, W, _, _, _, W, _, W, _, W, _, W, _, W, _, _, _, W, _, W, _, _, _, _, _, W, W,
|
W, _, _, _, W, _, W, _, _, _, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, _, _, _, D, _, D, _, _, _, W, _, W, _, W, _, W, W, W, W, W, _, W, W, W, _, W, W, W, W, W, W,
|
W, _, _, _, D, _, D, _, _, _, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, _, _, _, W, _, W, _, _, _, W, _, W, _, _, _, W, _, W, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
W, _, _, _, W, _, W, _, _, _, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, W, M, W, W, _, W, W, M, _, W, _, W, _, W, W, W, _, W, _, W, W, W, W, W, W, W, _, W, W, W, W,
|
W, W, M, W, W, _, W, W, M, _, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, W, W, W, W, _, W, W, W, _, W, _, _, _, W, _, W, _, W, _, _, _, _, _, _, _, W, _, W, _, W, W,
|
W, W, W, W, W, _, W, W, W, _, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, W, W, M, W, D, W, M, W, _, W, W, W, _, W, _, W, _, W, _, W, W, W, W, W, W, W, W, W, _, W, W,
|
W, W, W, M, W, D, W, M, W, _, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, W, W, T, T, T, T, T, W, _, W, _, _, _, _, _, _, _, _, _, _, _, _, _, W, _, _, _, _, _, W, W,
|
W, W, W, T, T, T, T, T, W, _, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, W, W, T, T, T, T, T, W, _, W, W, W, _, W, W, W, _, W, W, W, _, W, _, W, _, W, W, W, W, W, W,
|
W, W, W, T, T, T, T, T, W, _, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, W, W, T, T, T, T, T, W, _, W, _, W, _, _, _, W, _, W, _, _, _, W, _, _, _, _, _, _, _, W, W,
|
W, W, W, T, T, T, T, T, W, _, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, W, W,
|
||||||
W, W, W, T, T, T, T, T, W, _, W, _, W, _, W, W, W, _, W, W, W, W, W, _, W, W, W, W, W, _, W, W,
|
W, W, W, T, T, T, T, T, W, _, W, W, W, W, W, W, W, W, W, W, _, W, W, W, W, W, W, W, W, W, W, W,
|
||||||
W, W, W, T, T, T, T, T, W, _, _, _, _, _, _, _, W, _, _, _, _, _, W, _, _, _, _, _, W, _, W, W,
|
W, W, W, T, T, T, T, T, W, _, _, _, _, _, _, _, _, _, _, _, _, W, W, W, W, W, W, W, W, W, W, W,
|
||||||
W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W};
|
W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W};
|
||||||
|
|
||||||
private static final int[] MAP_ARENA =
|
private static final int[] MAP_ARENA =
|
||||||
|
|
|
@ -0,0 +1,123 @@
|
||||||
|
package com.shatteredpixel.shatteredpixeldungeon.levels.painters;
|
||||||
|
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.levels.Room;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
|
||||||
|
import com.watabou.utils.Random;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Evan on 24/11/2015.
|
||||||
|
*/
|
||||||
|
public class MazePainter extends Painter {
|
||||||
|
|
||||||
|
public static void paint( Level level, Room room ) {
|
||||||
|
fill(level, room, 1, Terrain.EMPTY);
|
||||||
|
|
||||||
|
//true = space, false = wall
|
||||||
|
boolean[][] maze = new boolean[room.width() + 1][room.height() + 1];
|
||||||
|
|
||||||
|
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) {
|
||||||
|
|
||||||
|
//set spaces where there are doors
|
||||||
|
for (Room.Door d : room.connected.values()) {
|
||||||
|
if (d.x == x + room.left && d.y == y + room.top) {
|
||||||
|
maze[x][y] = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
maze[x][y] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int fails = 0;
|
||||||
|
while (fails < 10000) {
|
||||||
|
|
||||||
|
//find a random wall point
|
||||||
|
int x, y;
|
||||||
|
do {
|
||||||
|
x = Random.Int(maze.length);
|
||||||
|
y = Random.Int(maze[0].length);
|
||||||
|
} while (maze[x][y]);
|
||||||
|
|
||||||
|
//decide on how we're going to move
|
||||||
|
int[] mov = decideDirection(maze, x, y);
|
||||||
|
if (mov == null) {
|
||||||
|
fails++;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
fails = 0;
|
||||||
|
int moves = 0;
|
||||||
|
do {
|
||||||
|
x += mov[0];
|
||||||
|
y += mov[1];
|
||||||
|
maze[x][y] = false;
|
||||||
|
moves++;
|
||||||
|
} while (Random.Int(moves+1) == 0 && checkValidMove(maze, x, y, mov));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fill(level, room, 1, Terrain.EMPTY);
|
||||||
|
for (int x = 0; x < maze.length; x++)
|
||||||
|
for (int y = 0; y < maze[0].length; y++) {
|
||||||
|
if (!maze[x][y]) {
|
||||||
|
fill(level, x + room.left, y + room.top, 1, 1, Terrain.WALL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user