Randomly generated map
So this is my code for randomy generated map , basicly its only function right now is to check if the last generated map overlap with other existing maps, if it does it is supposed to repeat until he makes a map that wont overlap with others. But somehow he just ignores that, i tried debugging and evreything stuck for 6 hours with this problem. Any help or hint would be appreciated.
public void generateRooms(){
roomList.clear();
roomList.add(new Room(new Vector2f(0,0),map));
for(int i=1; i < 10; i++){
boolean col = false;
Random randN = new Random();
roomList.add(new Room(new Vector2f((randN.nextInt(80)-40)*50 ,(randN.nextInt(80)-40)*50),map));
col = checkColision(roomList.get(i).hitbox);
while(col == true){
roomList.remove(i);
Random randNew = new Random();
roomList.add(new Room(new Vector2f((randNew.nextInt(80)-40)*50 ,(randNew.nextInt(80)-40)*50),map));
col = checkColision(roomList.get(i).hitbox);
}
}
}
public boolean checkColision(Box hitbox){
for(int i=0; i < roomList.size()-2; i++){
if(roomList.get(i).hitbox.collide(hitbox)){
System.out.println("It colided");
return true;
}
}
return false;
}
So this is my code for randomy generated map , basicly its only function right now is to check if the last generated map overlap with other existing maps, if it does it is supposed to repeat until he makes a map that wont overlap with others. But somehow he just ignores that, i tried debugging and evreything stuck for 6 hours with this problem. Any help or hint would be appreciated.
public void generateRooms(){
roomList.clear();
roomList.add(new Room(new Vector2f(0,0),map));
for(int i=1; i < 10; i++){
boolean col = false;
Random randN = new Random();
roomList.add(new Room(new Vector2f((randN.nextInt(80)-40)*50 ,(randN.nextInt(80)-40)*50),map));
col = checkColision(roomList.get(i).hitbox);
while(col == true){
roomList.remove(i);
Random randNew = new Random();
roomList.add(new Room(new Vector2f((randNew.nextInt(80)-40)*50 ,(randNew.nextInt(80)-40)*50),map));
col = checkColision(roomList.get(i).hitbox);
}
}
}
public boolean checkColision(Box hitbox){
for(int i=0; i < roomList.size()-2; i++){
if(roomList.get(i).hitbox.collide(hitbox)){
System.out.println("It colided");
return true;
}
}
return false;
}
No comments:
Post a Comment