v0.6.1: completely reimplemented tunnel rooms
This commit is contained in:
parent
673ad28c5d
commit
7705f24c14
|
@ -23,8 +23,11 @@ package com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection;
|
|||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.levels.painters.Painter;
|
||||
import com.watabou.utils.GameMath;
|
||||
import com.watabou.utils.Point;
|
||||
import com.watabou.utils.PointF;
|
||||
import com.watabou.utils.Random;
|
||||
import com.watabou.utils.Rect;
|
||||
|
||||
//tunnels along the rooms center, with straight lines
|
||||
public class TunnelRoom extends ConnectionRoom {
|
||||
|
@ -33,93 +36,74 @@ public class TunnelRoom extends ConnectionRoom {
|
|||
|
||||
int floor = level.tunnelTile();
|
||||
|
||||
Point c = center();
|
||||
Rect c = getConnectionSpace();
|
||||
|
||||
if (width() > height() || (width() == height() && Random.Int( 2 ) == 0)) {
|
||||
for (Door door : connected.values()) {
|
||||
|
||||
int from = right - 1;
|
||||
int to = left + 1;
|
||||
Point start;
|
||||
Point mid;
|
||||
Point end;
|
||||
|
||||
for (Door door : connected.values()) {
|
||||
start = new Point(door);
|
||||
if (start.x == left) start.x++;
|
||||
else if (start.y == top) start.y++;
|
||||
else if (start.x == right) start.x--;
|
||||
else if (start.y == bottom) start.y--;
|
||||
|
||||
int step = door.y < c.y ? +1 : -1;
|
||||
int rightShift;
|
||||
int downShift;
|
||||
|
||||
if (door.x == left) {
|
||||
if (start.x < c.left) rightShift = c.left - start.x;
|
||||
else if (start.x > c.right) rightShift = c.right - start.x;
|
||||
else rightShift = 0;
|
||||
|
||||
from = left + 1;
|
||||
for (int i=door.y; i != c.y; i += step) {
|
||||
Painter.set( level, from, i, floor );
|
||||
}
|
||||
if (start.y < c.top) downShift = c.top - start.y;
|
||||
else if (start.y > c.bottom) downShift = c.bottom - start.y;
|
||||
else downShift = 0;
|
||||
|
||||
} else if (door.x == right) {
|
||||
//always goes inward first
|
||||
if (door.x == left || door.x == right){
|
||||
mid = new Point(start.x + rightShift, start.y);
|
||||
end = new Point(mid.x, mid.y + downShift);
|
||||
|
||||
to = right - 1;
|
||||
for (int i=door.y; i != c.y; i += step) {
|
||||
Painter.set( level, to, i, floor );
|
||||
}
|
||||
} else {
|
||||
mid = new Point(start.x, start.y + downShift);
|
||||
end = new Point(mid.x + rightShift, mid.y);
|
||||
|
||||
} else {
|
||||
if (door.x < from) {
|
||||
from = door.x;
|
||||
}
|
||||
if (door.x > to) {
|
||||
to = door.x;
|
||||
}
|
||||
|
||||
for (int i=door.y+step; i != c.y; i += step) {
|
||||
Painter.set( level, door.x, i, floor );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=from; i <= to; i++) {
|
||||
Painter.set( level, i, c.y, floor );
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
int from = bottom - 1;
|
||||
int to = top + 1;
|
||||
|
||||
for (Door door : connected.values()) {
|
||||
|
||||
int step = door.x < c.x ? +1 : -1;
|
||||
|
||||
if (door.y == top) {
|
||||
|
||||
from = top + 1;
|
||||
for (int i=door.x; i != c.x; i += step) {
|
||||
Painter.set( level, i, from, floor );
|
||||
}
|
||||
|
||||
} else if (door.y == bottom) {
|
||||
|
||||
to = bottom - 1;
|
||||
for (int i=door.x; i != c.x; i += step) {
|
||||
Painter.set( level, i, to, floor );
|
||||
}
|
||||
|
||||
} else {
|
||||
if (door.y < from) {
|
||||
from = door.y;
|
||||
}
|
||||
if (door.y > to) {
|
||||
to = door.y;
|
||||
}
|
||||
|
||||
for (int i=door.x+step; i != c.x; i += step) {
|
||||
Painter.set( level, i, door.y, floor );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=from; i <= to; i++) {
|
||||
Painter.set( level, c.x, i, floor );
|
||||
}
|
||||
Painter.drawLine( level, start, mid, floor );
|
||||
Painter.drawLine( level, mid, end, floor );
|
||||
}
|
||||
|
||||
for (Door door : connected.values()) {
|
||||
door.set( Door.Type.TUNNEL );
|
||||
}
|
||||
}
|
||||
|
||||
//returns the space which all doors must connect to (usually 1 cell, but can be more)
|
||||
//Note that, like rooms, this space is inclusive to its right and bottom sides
|
||||
protected Rect getConnectionSpace(){
|
||||
Point c = getDoorCenter();
|
||||
|
||||
return new Rect(c.x, c.y, c.x, c.y);
|
||||
}
|
||||
|
||||
//returns a point equidistant from all doors this room has
|
||||
protected final Point getDoorCenter(){
|
||||
PointF doorCenter = new PointF(0, 0);
|
||||
|
||||
for (Door door : connected.values()) {
|
||||
doorCenter.x += door.x;
|
||||
doorCenter.y += door.y;
|
||||
}
|
||||
|
||||
Point c = new Point((int)doorCenter.x / connected.size(), (int)doorCenter.y / connected.size());
|
||||
if (Random.Float() < doorCenter.x % 1) c.x++;
|
||||
if (Random.Float() < doorCenter.y % 1) c.y++;
|
||||
c.x = (int)GameMath.gate(left+1, c.x, right-1);
|
||||
c.y = (int)GameMath.gate(top+1, c.y, bottom-1);
|
||||
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user