Merge branch 'master' of https://git.ngb.schule/Tim/Zoelda
This commit is contained in:
@@ -14,6 +14,7 @@ public class DoorTile extends Tile implements Ticker {
|
|||||||
private int side;
|
private int side;
|
||||||
private DoorTile connected;
|
private DoorTile connected;
|
||||||
private ImageMap map;
|
private ImageMap map;
|
||||||
|
private boolean waitForLeave;
|
||||||
|
|
||||||
public DoorTile(float x, float y, ImageMap map) {
|
public DoorTile(float x, float y, ImageMap map) {
|
||||||
super(Tile.DOOR, x, y);
|
super(Tile.DOOR, x, y);
|
||||||
@@ -28,7 +29,12 @@ public class DoorTile extends Tile implements Ticker {
|
|||||||
Player player = Main.instance.getWorld().getPlayer();
|
Player player = Main.instance.getWorld().getPlayer();
|
||||||
float dist = player.dist(posX + 0.5f, posY + 0.5f);
|
float dist = player.dist(posX + 0.5f, posY + 0.5f);
|
||||||
if (dist < 0.5f) {
|
if (dist < 0.5f) {
|
||||||
|
if (!waitForLeave) {
|
||||||
Main.instance.getWorld().changeMap(this);
|
Main.instance.getWorld().changeMap(this);
|
||||||
|
waitForLeave = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
waitForLeave = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,7 +51,15 @@ public class DoorTile extends Tile implements Ticker {
|
|||||||
connected = door;
|
connected = door;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DoorTile getConnectedDoor() {
|
||||||
|
return connected;
|
||||||
|
}
|
||||||
|
|
||||||
public ImageMap getMap() {
|
public ImageMap getMap() {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void waitForLeave() {
|
||||||
|
waitForLeave = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,10 +37,7 @@ public class Tile extends Knoten {
|
|||||||
posX = x;
|
posX = x;
|
||||||
posY = y;
|
posY = y;
|
||||||
|
|
||||||
if (id == VOID) {
|
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 {
|
|
||||||
// Das Bild laden
|
// Das Bild laden
|
||||||
try {
|
try {
|
||||||
BufferedImage buff = ImageIO.read(Tile.class.getResourceAsStream(getPathFromId(id)));
|
BufferedImage buff = ImageIO.read(Tile.class.getResourceAsStream(getPathFromId(id)));
|
||||||
@@ -60,11 +57,12 @@ public class Tile extends Knoten {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Bild zu EA hinzufügen.
|
// Bild zu EA hinzufügen.
|
||||||
add(img);
|
add(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return den Pfad der zu der Id gehört.
|
* @return den Pfad der zu der Id gehört.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -24,11 +24,11 @@ public class World extends Knoten {
|
|||||||
|
|
||||||
dungeon = new ArrayList<>(50);
|
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);
|
dungeon.add(start);
|
||||||
currentMap = start;
|
currentMap = start;
|
||||||
|
|
||||||
start.generate(dungeon);
|
start.generate(dungeon, DoorTile.BOTTOM);
|
||||||
|
|
||||||
|
|
||||||
player = new Player();
|
player = new Player();
|
||||||
@@ -49,10 +49,13 @@ public class World extends Knoten {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void changeMap(DoorTile door) {
|
public void changeMap(DoorTile door) {
|
||||||
|
currentMap.entfernen(player.actionFigur);
|
||||||
entfernen(currentMap);
|
entfernen(currentMap);
|
||||||
currentMap = door.getMap();
|
System.out.println(door);
|
||||||
|
currentMap = door.getConnectedDoor().getMap();
|
||||||
currentMap.add(player.actionFigur);
|
currentMap.add(player.actionFigur);
|
||||||
add(currentMap);
|
add(currentMap);
|
||||||
player.setPos(7, 5);
|
door.getConnectedDoor().waitForLeave();
|
||||||
|
player.setPos(door.getConnectedDoor().posX + 0.5f, door.getConnectedDoor().posY + 0.5f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,10 @@ import main.Tile;
|
|||||||
|
|
||||||
public class ImageMap extends Map {
|
public class ImageMap extends Map {
|
||||||
|
|
||||||
private static PixelTile[] pixels = { new PixelTile(Tile.STONE_WALL, new Color(100, 100, 100)),
|
private static PixelTile[] pixels = {
|
||||||
new PixelTile(Tile.STONE_FLOOR, new Color(127, 127, 127)), new PixelTile(Tile.VOID, new Color(0, 0, 0)),
|
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)) };
|
new PixelTile(Tile.DOOR, new Color(255, 0, 0)) };
|
||||||
|
|
||||||
public DoorTile topDoor;
|
public DoorTile topDoor;
|
||||||
@@ -81,39 +83,48 @@ public class ImageMap extends Map {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generate(ArrayList<ImageMap> dungeon) {
|
public void generate(ArrayList<ImageMap> dungeon, int fromSide) {
|
||||||
if (topDoor != null) {
|
if (topDoor != null && fromSide != DoorTile.TOP) {
|
||||||
ImageMap map;
|
ImageMap map;
|
||||||
do {
|
do {
|
||||||
map = nextMap();
|
map = nextMap();
|
||||||
} while (!connectDoors(topDoor, map));
|
} while (!connectDoors(topDoor, map));
|
||||||
dungeon.add(map);
|
dungeon.add(map);
|
||||||
|
System.out.println("TOP");
|
||||||
|
map.generate(dungeon, DoorTile.BOTTOM);
|
||||||
}
|
}
|
||||||
if (bottomDoor != null) {
|
if (bottomDoor != null && fromSide != DoorTile.BOTTOM) {
|
||||||
ImageMap map;
|
ImageMap map;
|
||||||
do {
|
do {
|
||||||
map = nextMap();
|
map = nextMap();
|
||||||
} while (!connectDoors(bottomDoor, map));
|
} while (!connectDoors(bottomDoor, map));
|
||||||
dungeon.add(map);
|
dungeon.add(map);
|
||||||
|
System.out.println("BOTTOM");
|
||||||
|
map.generate(dungeon, DoorTile.TOP);
|
||||||
}
|
}
|
||||||
if (leftDoor != null) {
|
if (leftDoor != null && fromSide != DoorTile.LEFT) {
|
||||||
ImageMap map;
|
ImageMap map;
|
||||||
do {
|
do {
|
||||||
map = nextMap();
|
map = nextMap();
|
||||||
} while (!connectDoors(leftDoor, map));
|
} while (!connectDoors(leftDoor, map));
|
||||||
dungeon.add(map);
|
dungeon.add(map);
|
||||||
|
System.out.println("LEFT");
|
||||||
|
map.generate(dungeon, DoorTile.RIGHT);
|
||||||
}
|
}
|
||||||
if (rightDoor != null) {
|
if (rightDoor != null && fromSide != DoorTile.RIGHT) {
|
||||||
ImageMap map;
|
ImageMap map;
|
||||||
do {
|
do {
|
||||||
map = nextMap();
|
map = nextMap();
|
||||||
} while (!connectDoors(rightDoor, map));
|
} while (!connectDoors(rightDoor, map));
|
||||||
dungeon.add(map);
|
dungeon.add(map);
|
||||||
|
System.out.println("RIGHT");
|
||||||
|
map.generate(dungeon, DoorTile.LEFT);
|
||||||
}
|
}
|
||||||
|
System.out.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImageMap nextMap() {
|
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) {
|
private boolean connectDoors(DoorTile door, ImageMap otherMap) {
|
||||||
@@ -124,6 +135,8 @@ public class ImageMap extends Map {
|
|||||||
}
|
}
|
||||||
door.setConnectedDoor(otherMap.bottomDoor);
|
door.setConnectedDoor(otherMap.bottomDoor);
|
||||||
otherMap.bottomDoor.setConnectedDoor(door);
|
otherMap.bottomDoor.setConnectedDoor(door);
|
||||||
|
System.out.println(door.getConnectedDoor());
|
||||||
|
System.out.println(otherMap.bottomDoor.getConnectedDoor());
|
||||||
return true;
|
return true;
|
||||||
case DoorTile.BOTTOM:
|
case DoorTile.BOTTOM:
|
||||||
if (otherMap.topDoor == null) {
|
if (otherMap.topDoor == null) {
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 302 B After Width: | Height: | Size: 227 B |
Reference in New Issue
Block a user