Commit e390b892 authored by Lucas Delcros's avatar Lucas Delcros
Browse files

continue cleaning

parent 1af1a659
......@@ -36,73 +36,6 @@ public class SurfacesMapGeneration implements Serializable{
return rooms[idRoom];
private static void defineStairsPosition(MapBuilder map,int height,int width,RoomBuilder[] rooms, RoomBuilder startingRoom) {
// This method chooses, once the structure of the map is done and the start position of the player is choosed, where the stairs should be
// First I do a BFS (Breadth First Search) starting at the start position of the player that I put in distanceToStart
MapPoint startPosition = new MapPoint(startingRoom.getSurface().j1, startingRoom.getSurface().i1);
int[][] distanceToStart=new int[height][width];
for(int i=0;i<height;i++) {
for(int j=0;j<width;j++) {
distanceToStart[i][j]=-2; // -2 everywhere
for(int k=0;k<rooms.length;k++) {
for(int i=rooms[k].getSurface().j1;i<=rooms[k].getSurface().j2;i++) {
for(int j=rooms[k].getSurface().i1;j<=rooms[k].getSurface().i2;j++) {
List<Surface> corridors=map.getCorridors();
for(int k=0;k<corridors.size();k++) {
for(int i=corridors.get(k).j1;i<=corridors.get(k).j2;i++) {
for(int j=corridors.get(k).i1;j<=corridors.get(k).i2;j++) {
distanceToStart[i][j]=-1; // But -1 where the player may go (floors and corridors)
distanceToStart[startPosition.getI()][startPosition.getJ()]=0; // And 0 at the start position to initialize the BFS
List<MapPoint> list=new ArrayList<>();
list.add(new MapPoint(startPosition.getI(),startPosition.getJ()));
int max_dist=-1;
while(list.size()>0) { // Loop for the BFS
List<MapPoint> newList=new ArrayList<>();
for(int k=0;k<list.size();k++) {
int ii=list.get(k).getI();
int jj=list.get(k).getJ();
for(int a=-1;a<=1;a++) {
for(int b=-1;b<=1;b++) {
if(0<=ii+a && ii+a<height && 0<=jj+b && jj+b<width && distanceToStart[ii+a][jj+b]==-1) {
newList.add(new MapPoint(ii+a,jj+b));
for(int k=0;k<newList.size();k++) {
// Now it's time to find the position of the stairs
Random r = new Random();
boolean bb=true;
int idRoom=0;
int posY=0;
int posX=0;
while (bb) { // I choose a random spot for the stairs
posX = rooms[idRoom].getSurface().i1;
posY = rooms[idRoom].getSurface().j1;
if (3*distanceToStart[posY][posX]>2*max_dist){
bb=false; // If the distance from the start position to the stairs position is large enough I choose it (compared to the farest point the player can reach)
public static int distanceBetweenTwoSurface(Surface surface1,Surface surface2) {
// Method that computes the distance between two rooms
int dY=Math.max(surface1.j1-surface2.j2+2,0)+Math.max(surface2.j1-surface1.j2+2,0);
......@@ -243,7 +176,6 @@ public class SurfacesMapGeneration implements Serializable{
RoomBuilder startRoom=defineStartPosition(rooms);
map.addRooms(rooms, startRoom);
addCorridorsByMST(rooms, map);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment