Commit 1d399e89 authored by Lucas Delcros's avatar Lucas Delcros

Restructuration systeme spawn personnage et spawn escalier

Porobleme de spawn sur lave definitivement resolu
parent 97fc3b7e
......@@ -2,14 +2,13 @@ package map_generation.map;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import map_generation.tiles.TileBuilder;
import map_generation.tiles.TileType;
import core.gamestate.Entity;
import core.gamestate.SpeciesArray;
import core.zone.Point;
import map_generation.tiles.TileBuilder;
import map_generation.tiles.TileType;
/**
* Builder for the class Map
......@@ -100,17 +99,13 @@ public final class MapBuilder implements Serializable{
surface.surroundWithWalls(map);
}
for (RoomBuilder room : rooms) {
room.build(map);
room.build(map, this);
}
for (Surface corridor : corridors) {
corridor.fillSurfaceWith(map, TileType.GROUND);
}
generateEntities(map);
map[stairsPosition.getI()][stairsPosition.getJ()].setType(TileType.STAIRS);
//TODO uses doors
//Surface[] doors = this.doors.toArray(new Surface[this.doors.size()]);
Surface[] rooms = new Surface[this.rooms.size()];
for (int i = 0; i < rooms.length; i++) {
rooms[i] = this.rooms.get(i).getSurface();
......
......@@ -32,20 +32,36 @@ public final class RoomBuilder {
s.fillSurfaceWith(map, TileType.WATER);
}
private void addStairs(TileBuilder[][] map, MapBuilder mapB){
Random r = new Random();
int posY=r.nextInt(surface.j2-surface.j1+1)+surface.j1;
int posX=r.nextInt(surface.i2-surface.i1+1)+surface.i1;
map[posY][posX].setType(TileType.STAIRS);
mapB.setStairPosition(new MapPoint(posY, posX));
}
public void setRandomlySpecial(double p){
Random r = new Random();
if(r.nextDouble() <= p){
if(type == RoomType.NORMAL && r.nextDouble() <= p){
if(r.nextDouble() <= 0.5) setType(RoomType.LAVA);
else setType(RoomType.TORCHES);
}
}
public void build(TileBuilder[][] map){
public void build(TileBuilder[][] map, MapBuilder mapB){
surface.fillSurfaceWith(map, TileType.GROUND);
switch (type){
case LAVA :
addLava(map);
break;
case START :
int posY=(surface.j1+surface.j2)/2;
int posX=(surface.i1+surface.i2)/2;
mapB.setPositionPlayerAtStart(new MapPoint(posY, posX));
break;
case END:
addStairs(map, mapB);
break;
default :
}
......
......@@ -8,7 +8,6 @@ import java.util.Random;
import map_generation.map.RoomBuilder.RoomType;
import map_generation.tiles.TileBuilder;
import map_generation.tiles.TileType;
/**
*
* This class contains methods that generates simple map to help for tests
......@@ -30,22 +29,17 @@ public class SurfacesMapGeneration implements Serializable{
return tilebs;
}
private static MapPoint defineStartPosition(RoomBuilder[] rooms) {
private static RoomBuilder defineStartPosition(RoomBuilder[] rooms) {
Random r = new Random();
int idRoom=r.nextInt(rooms.length);
//int posY=(rooms[idRoom].j1+rooms[idRoom].j2)/2;
//int posX=(rooms[idRoom].i1+rooms[idRoom].i2)/2;
int posX = rooms[idRoom].getSurface().i1;
int posY = rooms[idRoom].getSurface().j1;
rooms[idRoom].setType(RoomType.START);
MapPoint startPosition=new MapPoint(posY, posX);
return startPosition;
return rooms[idRoom];
}
private static MapPoint defineStairsPosition(MapBuilder map,int height,int width,RoomBuilder[] rooms,MapPoint startPosition) {
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++) {
......@@ -100,8 +94,6 @@ public class SurfacesMapGeneration implements Serializable{
int posX=0;
while (bb) { // I choose a random spot for the stairs
idRoom=r.nextInt(rooms.length);
// posY=r.nextInt(rooms[idRoom].j2-rooms[idRoom].j1+1)+rooms[idRoom].j1;
// posX=r.nextInt(rooms[idRoom].i2-rooms[idRoom].i1+1)+rooms[idRoom].i1;
posX = rooms[idRoom].getSurface().i1;
posY = rooms[idRoom].getSurface().j1;
if (3*distanceToStart[posY][posX]>2*max_dist){
......@@ -109,8 +101,6 @@ public class SurfacesMapGeneration implements Serializable{
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)
}
}
MapPoint stairsPosition=new MapPoint(posY, posX);
return stairsPosition;
}
public static int distanceBetweenTwoSurface(Surface surface1,Surface surface2) {
......@@ -268,16 +258,14 @@ public class SurfacesMapGeneration implements Serializable{
map.addRoom(rooms[i]);
}
addCorridorsByMST(rooms, map); // Creation of the set of corridors
MapPoint startPosition=defineStartPosition(rooms);
MapPoint stairsPosition=defineStairsPosition(map,heightMap,widthMap,rooms,startPosition);
RoomBuilder startRoom=defineStartPosition(rooms);
defineStairsPosition(map,heightMap,widthMap,rooms,startRoom);
map.setHeight(heightMap);
map.setWidth(widthMap);
map.setStairPosition(stairsPosition);
map.setPositionPlayerAtStart(startPosition);
for (RoomBuilder room : rooms) {
room.setRandomlySpecial(0.4);
room.setRandomlySpecial(0.3);
}
return map.build();
......@@ -293,10 +281,8 @@ public class SurfacesMapGeneration implements Serializable{
RoomBuilder[] rooms=new RoomBuilder[1];
rooms[0]= new RoomBuilder(room, RoomType.NORMAL);
addCorridorsByMST(rooms, map);
MapPoint startPosition=defineStartPosition(rooms);
MapPoint stairsPosition=defineStairsPosition(map,size,size,rooms,startPosition);
map.setStairPosition(stairsPosition);
map.setPositionPlayerAtStart(startPosition);
RoomBuilder startRoom=defineStartPosition(rooms);
defineStairsPosition(map,size,size,rooms,startRoom);
return(map.build());
}
......
......@@ -27,6 +27,12 @@ public class MapTests {
}
}
@Test
public void testMapHasStartEnd(){
Map map = SurfacesMapGeneration.roomsRandomGeneration(20, 500);
assertFalse("The Map doesn't cointains any stairs !", map.getPositionStairs() == null && map.getPositionPlayerStart() == null);
}
@Test
public void testPlayerNotOnWater(){
Map map = SurfacesMapGeneration.roomsRandomGeneration(20, 500);
......
Markdown is supported
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