V0.2.1 : Overhauled Goo's arena, now much more positioning possible.
This commit is contained in:
parent
e6b8732f90
commit
dd2ddf6f81
|
@ -60,76 +60,104 @@ public class SewerBossLevel extends RegularLevel {
|
||||||
initRooms();
|
initRooms();
|
||||||
|
|
||||||
int distance;
|
int distance;
|
||||||
|
//if we ever need to try 20 or more times to find a room, better to give up and try again.
|
||||||
int retry = 0;
|
int retry = 0;
|
||||||
int minDistance = (int)Math.sqrt( rooms.size() );
|
|
||||||
do {
|
//start with finding an entrance room (will also contain exit)
|
||||||
int innerRetry = 0;
|
//the room must be at least 4x4 and be at the top of the map(so that nothing can connect with the top)
|
||||||
do {
|
do {
|
||||||
if (innerRetry++ > 10) {
|
if (retry++ > 20) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
roomEntrance = Random.element( rooms );
|
roomEntrance = Random.element( rooms );
|
||||||
} while (roomEntrance.width() < 4 || roomEntrance.height() < 4);
|
} while (roomEntrance.width() < 4 || roomEntrance.height() < 4 || roomEntrance.top != 0);
|
||||||
|
|
||||||
innerRetry = 0;
|
roomEntrance.type = Type.ENTRANCE;
|
||||||
do {
|
roomExit = roomEntrance;
|
||||||
if (innerRetry++ > 10) {
|
|
||||||
return false;
|
|
||||||
}
|
//now find the rest of the rooms for this boss mini-maze
|
||||||
roomExit = Random.element( rooms );
|
Room curRoom = null;
|
||||||
} while (roomExit == roomEntrance || roomExit.width() < 6 || roomExit.height() < 6 || roomExit.top == 0);
|
Room lastRoom = roomEntrance;
|
||||||
|
//we make 4 rooms, last iteration is tieing the final toom to the start
|
||||||
Graph.buildDistanceMap( rooms, roomExit );
|
for(int i = 0; i <= 4; i++){
|
||||||
distance = roomEntrance.distance();
|
retry = 0;
|
||||||
|
//find a suitable room the first four times
|
||||||
if (retry++ > 10) {
|
//sutiable room should be empty and have a distance of 2 from the current room
|
||||||
return false;
|
if (i < 4) {
|
||||||
}
|
do {
|
||||||
|
if (retry++ > 20) {
|
||||||
} while (distance < minDistance);
|
return false;
|
||||||
|
}
|
||||||
roomEntrance.type = Type.ENTRANCE;
|
curRoom = Random.element(rooms);
|
||||||
roomExit.type = Type.BOSS_EXIT;
|
Graph.buildDistanceMap(rooms, curRoom);
|
||||||
|
distance = lastRoom.distance();
|
||||||
Graph.buildDistanceMap( rooms, roomExit );
|
} while (curRoom.type != Type.NULL || distance != 2);
|
||||||
List<Room> path = Graph.buildPath( rooms, roomEntrance, roomExit );
|
|
||||||
|
curRoom.type = Type.STANDARD;
|
||||||
Graph.setPrice( path, roomEntrance.distance );
|
|
||||||
|
//otherwise, we're on the last iteration.
|
||||||
Graph.buildDistanceMap( rooms, roomExit );
|
} else {
|
||||||
path = Graph.buildPath( rooms, roomEntrance, roomExit );
|
//set the current room to the entrance, so we can build a connection to it.
|
||||||
|
curRoom = roomEntrance;
|
||||||
Room room = roomEntrance;
|
}
|
||||||
for (Room next : path) {
|
|
||||||
room.connect( next );
|
//now build a connection between the current room and the last one.
|
||||||
room = next;
|
Graph.buildDistanceMap( rooms, curRoom );
|
||||||
}
|
List<Room> path = Graph.buildPath( rooms, lastRoom, curRoom );
|
||||||
|
|
||||||
room = (Room)roomExit.connected.keySet().toArray()[0];
|
Graph.setPrice( path, lastRoom.distance );
|
||||||
if (roomExit.top == room.bottom) {
|
|
||||||
return false;
|
path = Graph.buildPath( rooms, lastRoom, curRoom );
|
||||||
}
|
|
||||||
|
Room room = lastRoom;
|
||||||
|
for (Room next : path) {
|
||||||
|
room.connect( next );
|
||||||
|
room = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == 4) {
|
||||||
|
|
||||||
|
//we must find a room for his royal highness!
|
||||||
|
//look at rooms adjacent to the final found room (likely to be furthest from start)
|
||||||
|
ArrayList<Room> candidates = new ArrayList<Room>();
|
||||||
|
for (Room r : lastRoom.neigbours) {
|
||||||
|
if (r.type == Type.NULL && r.connected.size() == 0) {
|
||||||
|
candidates.add(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//if we have candidates, pick a room and put the king there
|
||||||
|
if (candidates.size() > 0) {
|
||||||
|
Room kingsRoom = Random.element(candidates);
|
||||||
|
kingsRoom.connect(lastRoom);
|
||||||
|
kingsRoom.type = Room.Type.RAT_KING;
|
||||||
|
|
||||||
|
//unacceptable! make a new level...
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastRoom = curRoom;
|
||||||
|
}
|
||||||
|
|
||||||
|
//the connection structure ensures that (most of the time) there is a nice loop for the player to kite the
|
||||||
|
//boss around. What's nice is that there is enough chaos such that the loop is rarely straightforward
|
||||||
|
//and boring.
|
||||||
|
|
||||||
|
//fills our connection rooms in with tunnel
|
||||||
for (Room r : rooms) {
|
for (Room r : rooms) {
|
||||||
if (r.type == Type.NULL && r.connected.size() > 0) {
|
if (r.type == Type.NULL && r.connected.size() > 0) {
|
||||||
r.type = Type.TUNNEL;
|
r.type = Type.TUNNEL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<Room> candidates = new ArrayList<Room>();
|
|
||||||
for (Room r : roomExit.neigbours) {
|
|
||||||
if (!roomExit.connected.containsKey( r ) &&
|
|
||||||
(roomExit.left == r.right || roomExit.right == r.left || roomExit.bottom == r.top)) {
|
|
||||||
candidates.add( r );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (candidates.size() > 0) {
|
|
||||||
Room kingsRoom = Random.element( candidates );
|
|
||||||
kingsRoom.connect( roomExit );
|
|
||||||
kingsRoom.type = Room.Type.RAT_KING;
|
|
||||||
}
|
|
||||||
|
|
||||||
paint();
|
paint();
|
||||||
|
|
||||||
|
//TODO: not handling this through a painter is kinda iffy, separate into a painter if you use it again.
|
||||||
|
//sticks the exit in the room entrance.
|
||||||
|
exit = roomEntrance.top * Level.WIDTH + (roomEntrance.left + roomEntrance.right) / 2;
|
||||||
|
map[exit] = Terrain.LOCKED_EXIT;
|
||||||
|
|
||||||
paintWater();
|
paintWater();
|
||||||
paintGrass();
|
paintGrass();
|
||||||
|
@ -178,7 +206,11 @@ public class SewerBossLevel extends RegularLevel {
|
||||||
@Override
|
@Override
|
||||||
protected void createMobs() {
|
protected void createMobs() {
|
||||||
Mob mob = Bestiary.mob( Dungeon.depth );
|
Mob mob = Bestiary.mob( Dungeon.depth );
|
||||||
mob.pos = roomExit.random();
|
Room room;
|
||||||
|
do {
|
||||||
|
room = Random.element(rooms);
|
||||||
|
} while (room.type != Type.STANDARD);
|
||||||
|
mob.pos = room.random();
|
||||||
mobs.add( mob );
|
mobs.add( mob );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user