Commit acbf2482 authored by Lucas Delcros's avatar Lucas Delcros

added torches

parent 0689a9a6
......@@ -31,7 +31,7 @@ public class TileSpriteLinker
spriteMap.put(TileType.EMPTY, new GroundTileSprite(SpriteLoader.getSpriteFromPath("/assets/Top_wall.png").getSpriteImage()));
spriteMap.put(TileType.STAIRS , new GroundTileSprite(SpriteLoader.getSpriteFromPath("/assets/dungeon_set_1/stairs/stairs2.bmp").getSpriteImage()));
spriteMap.put(TileType.WATER , new GroundTileSprite(SpriteLoader.getSpriteFromPath("/assets/Lava.png").getSpriteImage()));
//spriteMap.put(TileType.TORCH , new GroundTileSprite(SpriteLoader.getSpriteFromPath("/assets/Torch.png").getSpriteImage()));
spriteMap.put(TileType.TORCH , new GroundTileSprite(SpriteLoader.getSpriteFromPath("/assets/Torch.png").getSpriteImage()));
}
public Displayable[][] getSpriteOfTile(TileType type, TileSprite.TileAbstractType[][] mask)
......
......@@ -93,10 +93,10 @@ public final class MapBuilder implements Serializable{
TileBuilder[][] map = SurfacesMapGeneration.emptyTiles(height, width);
for (RoomBuilder room : rooms) {
room.getSurface().surroundWithWalls(map);
room.getSurface().surroundWith(map, TileType.WALL);
}
for (Surface surface: corridors) {
surface.surroundWithWalls(map);
surface.surroundWith(map, TileType.WALL);
}
for (RoomBuilder room : rooms) {
room.build(map, this);
......
......@@ -7,7 +7,7 @@ import map_generation.tiles.TileType;
public final class RoomBuilder {
public static enum RoomType{START, END, NORMAL, TORCHES, LAVA};
public static enum RoomType{START, END, NORMAL, TORCHES, FULL_LAVA, LAVA_ISLAND};
private Surface surface;
private RoomType type;
......@@ -25,7 +25,7 @@ public final class RoomBuilder {
return surface;
}
private void addLava(TileBuilder[][] map){
private void addFullLava(TileBuilder[][] map){
Random r = new Random();
int dw = r.nextInt((surface.width-2)/2)+1, dh = r.nextInt((surface.height-2)/2)+1;
Surface s = new Surface(surface.i1+dh, surface.j1+dw, surface.i2-dh, surface.j2-dw);
......@@ -39,10 +39,18 @@ public final class RoomBuilder {
map[posY][posX].setType(TileType.STAIRS);
mapB.setStairPosition(new MapPoint(posY, posX));
}
private void addTorches(TileBuilder[][] map){
map[surface.j1 + 2][surface.i1 + 2].setType(TileType.TORCH);
map[surface.j2 - 2][surface.i1 + 2].setType(TileType.TORCH);
map[surface.j1 + 2][surface.i2 - 2].setType(TileType.TORCH);
map[surface.j2 - 2][surface.i2 - 2].setType(TileType.TORCH);
}
public void setRandomlySpecial(double p){
Random r = new Random();
if(type == RoomType.NORMAL && r.nextDouble() <= p){
if(r.nextDouble() <= 0.5) setType(RoomType.LAVA);
double pp = r.nextDouble();
if( pp <= 0.5 )setType(RoomType.FULL_LAVA);
else setType(RoomType.TORCHES);
}
}
......@@ -50,14 +58,17 @@ public final class RoomBuilder {
public void build(TileBuilder[][] map, MapBuilder mapB){
surface.fillSurfaceWith(map, TileType.GROUND);
switch (type){
case LAVA :
addLava(map);
case FULL_LAVA :
addFullLava(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 TORCHES:
addTorches(map);
break;
case END:
addStairs(map, mapB);
break;
......
......@@ -36,14 +36,14 @@ public class Surface implements Serializable{
* @param xb
* @param yb
*/
private static void linkNodes(TileBuilder[][] tilebs, int xa, int ya, int xb, int yb){
private static void linkNodes(TileBuilder[][] tilebs, TileType type, int xa, int ya, int xb, int yb){
int d = 0;
int dy = Math.abs(yb - ya), dx = Math.abs(xb - xa), dy2 = (dy << 1), dx2 = (dx << 1);
int ix = xa < xb ? 1 : -1, iy = ya < yb ? 1 : -1;
if (dy <= dx) {
for (;;) {
tilebs[xa][ya].setType(TileType.WALL);
tilebs[xa][ya].setType(type);
if (xa == xb)
break;
xa += ix;
......@@ -55,7 +55,7 @@ public class Surface implements Serializable{
}
} else {
for (;;) {
tilebs[xa][ya].setType(TileType.WALL);
tilebs[xa][ya].setType(type);
if (ya == yb)
break;
ya += iy;
......@@ -72,14 +72,14 @@ public class Surface implements Serializable{
* @param map
* @param surface
*/
public void surroundWithWalls(TileBuilder[][] map){
public void surroundWith(TileBuilder[][] map, TileType type){
final int x1 = i1 - 1, x2 = i2 +1;
final int y1 = j1 - 1, y2 = j2 +1;
linkNodes(map, y1, x1, y2, x1);
linkNodes(map, y2, x1, y2, x2);
linkNodes(map, y2, x2, y1, x2);
linkNodes(map, y1, x2, y1, x1);
linkNodes(map, type, y1, x1, y2, x1);
linkNodes(map, type, y2, x1, y2, x2);
linkNodes(map, type, y2, x2, y1, x2);
linkNodes(map, type, y1, x2, y1, x1);
}
......
......@@ -8,7 +8,7 @@ import map_generation.tiles.TilePropertyVector.TileProperty;
*
*/
public enum TileType{
EMPTY, GROUND, WALL, STAIRS, WATER;
EMPTY, GROUND, WALL, STAIRS, WATER, TORCH;
private TilePropertyVector tpv;
private String shortName;
......@@ -24,6 +24,8 @@ public enum TileType{
STAIRS.shortName="S";
WATER.tpv=new TilePropertyVector().addProperty(TileProperty.LIQUID);
WATER.shortName="W";
TORCH.tpv=new TilePropertyVector().addProperty(TileProperty.IMPASSABLE);
TORCH.shortName="T";
}
public TilePropertyVector getTilePropertyVector(){
......
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