WIP: doors
This commit is contained in:
parent
83120aef20
commit
e19165c6c8
|
@ -14,6 +14,7 @@ public class DoorTile extends Tile implements Ticker {
|
|||
private int side;
|
||||
private DoorTile connected;
|
||||
private ImageMap map;
|
||||
private boolean waitForLeave;
|
||||
|
||||
public DoorTile(float x, float y, ImageMap map) {
|
||||
super(Tile.DOOR, x, y);
|
||||
|
@ -28,7 +29,12 @@ public class DoorTile extends Tile implements Ticker {
|
|||
Player player = Main.instance.getWorld().getPlayer();
|
||||
float dist = player.dist(posX + 0.5f, posY + 0.5f);
|
||||
if (dist < 0.5f) {
|
||||
Main.instance.getWorld().changeMap(this);
|
||||
if (!waitForLeave) {
|
||||
Main.instance.getWorld().changeMap(this);
|
||||
waitForLeave = true;
|
||||
}
|
||||
} else {
|
||||
waitForLeave = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,8 +50,16 @@ public class DoorTile extends Tile implements Ticker {
|
|||
public void setConnectedDoor(DoorTile door) {
|
||||
connected = door;
|
||||
}
|
||||
|
||||
public DoorTile getConnectedDoor() {
|
||||
return connected;
|
||||
}
|
||||
|
||||
public ImageMap getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public void waitForLeave() {
|
||||
waitForLeave = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,10 +37,7 @@ public class Tile extends Knoten {
|
|||
posX = x;
|
||||
posY = y;
|
||||
|
||||
if (id == VOID) {
|
||||
BufferedImage buff = new BufferedImage(World.SCALE, World.SCALE, BufferedImage.TYPE_INT_RGB);
|
||||
img = new Bild(x * World.SCALE, y * World.SCALE, buff);
|
||||
} else {
|
||||
if (id != VOID) {
|
||||
// Das Bild laden
|
||||
try {
|
||||
BufferedImage buff = ImageIO.read(Tile.class.getResourceAsStream(getPathFromId(id)));
|
||||
|
@ -59,10 +56,11 @@ public class Tile extends Knoten {
|
|||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// Bild zu EA hinzufügen.
|
||||
add(img);
|
||||
}
|
||||
// Bild zu EA hinzufügen.
|
||||
add(img);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,11 +24,11 @@ public class World extends Knoten {
|
|||
|
||||
dungeon = new ArrayList<>(50);
|
||||
|
||||
ImageMap start = new ImageMap("/res/images/maps/map1.png");
|
||||
ImageMap start = new ImageMap("/res/images/maps/map2.png");
|
||||
dungeon.add(start);
|
||||
currentMap = start;
|
||||
|
||||
start.generate(dungeon);
|
||||
start.generate(dungeon, DoorTile.BOTTOM);
|
||||
|
||||
|
||||
player = new Player();
|
||||
|
@ -49,10 +49,13 @@ public class World extends Knoten {
|
|||
}
|
||||
|
||||
public void changeMap(DoorTile door) {
|
||||
currentMap.entfernen(player.actionFigur);
|
||||
entfernen(currentMap);
|
||||
currentMap = door.getMap();
|
||||
System.out.println(door);
|
||||
currentMap = door.getConnectedDoor().getMap();
|
||||
currentMap.add(player.actionFigur);
|
||||
add(currentMap);
|
||||
player.setPos(7, 5);
|
||||
door.getConnectedDoor().waitForLeave();
|
||||
player.setPos(door.getConnectedDoor().posX + 0.5f, door.getConnectedDoor().posY + 0.5f);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public class Spider extends LivingEntity {
|
|||
}
|
||||
|
||||
protected void update() {
|
||||
Player player = Main.instance.getWorld().getCurrentMap().getPlayer();
|
||||
Player player = Main.instance.getWorld().getPlayer();
|
||||
if (!actionFigur.aktuellesVerhalten().equals(getDamageAnimationName())) {
|
||||
if (lineOfSightClear(player)) {
|
||||
if (dist(player) < 1f) {
|
||||
|
|
|
@ -12,8 +12,10 @@ import main.Tile;
|
|||
|
||||
public class ImageMap extends Map {
|
||||
|
||||
private static PixelTile[] pixels = { new PixelTile(Tile.STONE_WALL, new Color(100, 100, 100)),
|
||||
new PixelTile(Tile.STONE_FLOOR, new Color(127, 127, 127)), new PixelTile(Tile.VOID, new Color(0, 0, 0)),
|
||||
private static PixelTile[] pixels = {
|
||||
new PixelTile(Tile.STONE_WALL, new Color(100, 100, 100)),
|
||||
new PixelTile(Tile.STONE_FLOOR, new Color(127, 127, 127)),
|
||||
new PixelTile(Tile.VOID, new Color(0, 0, 0)),
|
||||
new PixelTile(Tile.DOOR, new Color(255, 0, 0)) };
|
||||
|
||||
public DoorTile topDoor;
|
||||
|
@ -81,39 +83,48 @@ public class ImageMap extends Map {
|
|||
}
|
||||
}
|
||||
|
||||
public void generate(ArrayList<ImageMap> dungeon) {
|
||||
if (topDoor != null) {
|
||||
public void generate(ArrayList<ImageMap> dungeon, int fromSide) {
|
||||
if (topDoor != null && fromSide != DoorTile.TOP) {
|
||||
ImageMap map;
|
||||
do {
|
||||
map = nextMap();
|
||||
} while (!connectDoors(topDoor, map));
|
||||
dungeon.add(map);
|
||||
System.out.println("TOP");
|
||||
map.generate(dungeon, DoorTile.BOTTOM);
|
||||
}
|
||||
if (bottomDoor != null) {
|
||||
if (bottomDoor != null && fromSide != DoorTile.BOTTOM) {
|
||||
ImageMap map;
|
||||
do {
|
||||
map = nextMap();
|
||||
} while (!connectDoors(bottomDoor, map));
|
||||
dungeon.add(map);
|
||||
System.out.println("BOTTOM");
|
||||
map.generate(dungeon, DoorTile.TOP);
|
||||
}
|
||||
if (leftDoor != null) {
|
||||
if (leftDoor != null && fromSide != DoorTile.LEFT) {
|
||||
ImageMap map;
|
||||
do {
|
||||
map = nextMap();
|
||||
} while (!connectDoors(leftDoor, map));
|
||||
dungeon.add(map);
|
||||
System.out.println("LEFT");
|
||||
map.generate(dungeon, DoorTile.RIGHT);
|
||||
}
|
||||
if (rightDoor != null) {
|
||||
if (rightDoor != null && fromSide != DoorTile.RIGHT) {
|
||||
ImageMap map;
|
||||
do {
|
||||
map = nextMap();
|
||||
} while (!connectDoors(rightDoor, map));
|
||||
dungeon.add(map);
|
||||
System.out.println("RIGHT");
|
||||
map.generate(dungeon, DoorTile.LEFT);
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
private ImageMap nextMap() {
|
||||
return new ImageMap("/res/images/maps/map" + ((int) (Math.random() * 7) + 1) + ".png");
|
||||
return new ImageMap("/res/images/maps/map" + ((int) (Math.random() * 4) + 5) + ".png");
|
||||
}
|
||||
|
||||
private boolean connectDoors(DoorTile door, ImageMap otherMap) {
|
||||
|
@ -124,6 +135,8 @@ public class ImageMap extends Map {
|
|||
}
|
||||
door.setConnectedDoor(otherMap.bottomDoor);
|
||||
otherMap.bottomDoor.setConnectedDoor(door);
|
||||
System.out.println(door.getConnectedDoor());
|
||||
System.out.println(otherMap.bottomDoor.getConnectedDoor());
|
||||
return true;
|
||||
case DoorTile.BOTTOM:
|
||||
if (otherMap.topDoor == null) {
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 302 B After Width: | Height: | Size: 227 B |
Loading…
Reference in New Issue