Commit 8414b73e authored by Lucas Delcros's avatar Lucas Delcros

entities spawn on water bug solved

parent 6f424fa3
......@@ -7,11 +7,9 @@ import java.util.List;
import java.util.NoSuchElementException;
import java.util.Random;
import core.gamestate.Entity;
import core.gamestate.SpeciesArray;
import core.zone.Point;
import map_generation.tiles.Tile;
import map_generation.tiles.TileType;
import core.gamestate.Entity;
......
......@@ -24,7 +24,7 @@ public final class MapBuilder implements Serializable{
private ArrayList<Surface> rooms;
private ArrayList<Surface> corridors;
private ArrayList<Surface> doors;
private Entity[] entities;
private ArrayList<Entity> entities;
private MapPoint positionPlayerAtStart;
private MapPoint stairsPosition;
private int height = 0, width = 0;
......@@ -33,6 +33,7 @@ public final class MapBuilder implements Serializable{
rooms = new ArrayList<>();
corridors = new ArrayList<>();
doors = new ArrayList<>();
entities = new ArrayList<Entity>();
}
public void addRoom(Surface room){
......@@ -146,9 +147,10 @@ public final class MapBuilder implements Serializable{
int dw = r.nextInt((room.width-2)/2)+1, dh = r.nextInt((room.height-2)/2)+1;
Surface s = new Surface(room.i1+dh, room.j1+dw, room.i2-dh, room.j2-dw);
if(!s.isOnSurface(positionPlayerAtStart) && !s.isOnSurface(stairsPosition))fillSurfaceWith(map, s, TileType.WATER);
else System.out.println("EMP");
}
}
private void generateEntities(TileBuilder[][] tb) {
private void generateEntities(TileBuilder[][] tb) {
MapPatterns.read();
int nbRooms=rooms.size();
Random r=new Random();
......@@ -156,14 +158,13 @@ public final class MapBuilder implements Serializable{
while(nbEntities<nbRooms/2 || nbEntities>3*nbRooms) {
nbEntities=(int) (nbRooms*(1+r.nextGaussian()));
}
entities=new Entity[nbEntities];
for(int i=0;i<nbEntities;i++) {
int room=r.nextInt(nbRooms);
int ii=rooms.get(room).i1+r.nextInt(rooms.get(room).height);
int jj=rooms.get(room).j1+r.nextInt(rooms.get(room).width);
int posY=ii*Point.TileScale;
int posX=jj*Point.TileScale;
if(tb[ii][jj].getType() != TileType.WATER) entities[i]= SpeciesArray.create(posX,posY,100,"Ronflex","Monster "+i);
if(tb[jj][ii].getType() != TileType.WATER) entities.add(SpeciesArray.create(posX,posY,100,"Ronflex","Monster "+i));
}
}
......@@ -179,7 +180,7 @@ public final class MapBuilder implements Serializable{
for (Surface room : rooms) {
fillSurfaceWith(map, room, TileType.GROUND);
addWaterRandomly(map, room, 0.2);
addWaterRandomly(map, room, 1);
}
for (Surface corridor : corridors) {
......@@ -192,7 +193,7 @@ public final class MapBuilder implements Serializable{
//Surface[] doors = this.doors.toArray(new Surface[this.doors.size()]);
Surface[] rooms = this.rooms.toArray(new Surface[this.rooms.size()]);
Surface[] corridors = this.corridors.toArray(new Surface[this.corridors.size()]);
Entity[] entities = this.entities.toArray(new Entity[this.entities.size()]);
return new Map(TileBuilder.buildTiles(map), rooms, corridors/*, doors*/, entities, positionPlayerAtStart, stairsPosition);
}
}
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