new map structure
|
@ -2,7 +2,7 @@ package main;
|
|||
|
||||
import ea.Ticker;
|
||||
import main.entities.player.Player;
|
||||
import main.maps.ImageMap;
|
||||
import main.maps.Map;
|
||||
|
||||
public class DoorTile extends Tile implements Ticker {
|
||||
|
||||
|
@ -13,11 +13,11 @@ public class DoorTile extends Tile implements Ticker {
|
|||
|
||||
private int side;
|
||||
private DoorTile connected;
|
||||
private ImageMap map;
|
||||
private Map map;
|
||||
private boolean waitForLeave;
|
||||
|
||||
public DoorTile(float x, float y, ImageMap map) {
|
||||
super(Tile.DOOR, x, y);
|
||||
public DoorTile(int id, float x, float y, Map map) {
|
||||
super(id, x, y);
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ public class DoorTile extends Tile implements Ticker {
|
|||
return connected;
|
||||
}
|
||||
|
||||
public ImageMap getMap() {
|
||||
public Map getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
|
@ -62,14 +62,14 @@ public class DoorTile extends Tile implements Ticker {
|
|||
|
||||
@Override
|
||||
public DoorTile clone() {
|
||||
DoorTile t = new DoorTile(posX, posY, map);
|
||||
DoorTile t = new DoorTile(getID(), posX, posY, map);
|
||||
t.setConnectedDoor(connected);
|
||||
t.side = side;
|
||||
t.map = map;
|
||||
return t;
|
||||
}
|
||||
|
||||
public void setMap(ImageMap map) {
|
||||
public void setMap(Map map) {
|
||||
this.map = map;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import java.io.IOException;
|
|||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import ea.BoundingRechteck;
|
||||
import ea.Knoten;
|
||||
import ea.Ticker;
|
||||
|
||||
|
|
|
@ -2,7 +2,8 @@ package main;
|
|||
|
||||
import ea.Game;
|
||||
import main.HUD.HUD;
|
||||
import main.HUD.Herzen;
|
||||
import main.worlds.TestWorld;
|
||||
import main.worlds.World;
|
||||
|
||||
/**
|
||||
* Von hier wird alles initialisiert. Das ist die höchste Klasse.
|
||||
|
@ -19,7 +20,9 @@ public class Main extends Game {
|
|||
instance = this;
|
||||
|
||||
// Welt initialisieren und Spieler hinzufügen und die Welt zu EA hinzufügen
|
||||
world = new World();
|
||||
world = new TestWorld();
|
||||
manager.anmelden(world.getPlayer(), 20);
|
||||
world.start();
|
||||
wurzel.add(world);
|
||||
hud = new HUD();
|
||||
wurzel.add(hud);
|
||||
|
|
|
@ -7,6 +7,7 @@ import javax.imageio.ImageIO;
|
|||
|
||||
import ea.Bild;
|
||||
import ea.Knoten;
|
||||
import main.worlds.World;
|
||||
|
||||
/**
|
||||
* Ein feld auf der Map
|
||||
|
@ -21,10 +22,9 @@ public class Tile extends Knoten {
|
|||
public static final int STONE_WALL = 3;
|
||||
public static final int STONE_WALL_BOTTOM = 4;
|
||||
public static final int STONE_FLOOR = 5;
|
||||
public static final int DOOR = 6;
|
||||
public static final int STONE_FLOOR_SHADOW_LEFT = 7;
|
||||
public static final int DOOR_LEFT_BOTTOM = 8;
|
||||
public static final int DOOR_LEFT_TOP = 9;
|
||||
public static final int STONE_FLOOR_SHADOW_LEFT = 6;
|
||||
public static final int DOOR_LEFT_BOTTOM = 7;
|
||||
public static final int DOOR_LEFT_TOP = 8;
|
||||
|
||||
private Bild img; // Bild, das gerendert wird
|
||||
private int id; // Die id dises Tiles//
|
||||
|
@ -56,7 +56,7 @@ public class Tile extends Knoten {
|
|||
}
|
||||
|
||||
private static void loadImages() {
|
||||
images = new Bild[10];
|
||||
images = new Bild[9];
|
||||
for (int i = 0; i < images.length; i++) {
|
||||
try {
|
||||
BufferedImage buff = ImageIO.read(Tile.class.getResourceAsStream(getPathFromId(i)));
|
||||
|
@ -92,8 +92,6 @@ public class Tile extends Knoten {
|
|||
return "/res/images/tiles/stone_wall_bottom.png";
|
||||
case STONE_FLOOR:
|
||||
return "/res/images/tiles/TestTest.png";
|
||||
case DOOR:
|
||||
return "/res/images/tiles/door_left_bottom.png";
|
||||
case STONE_FLOOR_SHADOW_LEFT:
|
||||
return "/res/images/tiles/stone_floor_shadow_left.png";
|
||||
case DOOR_LEFT_BOTTOM:
|
||||
|
@ -152,6 +150,14 @@ public class Tile extends Knoten {
|
|||
return id;
|
||||
}
|
||||
|
||||
public float getPosX() {
|
||||
return posX;
|
||||
}
|
||||
|
||||
public float getPosY() {
|
||||
return posY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tile clone() {
|
||||
return new Tile(id, posX, posY);
|
||||
|
|
|
@ -2,7 +2,7 @@ package main.entities;
|
|||
|
||||
import ea.ActionFigur;
|
||||
import ea.Figur;
|
||||
import main.World;
|
||||
import main.worlds.World;
|
||||
|
||||
/*
|
||||
* Alles was zustände hat und sich Bewegen kann, ist ein LivingEntity.
|
||||
|
|
|
@ -32,7 +32,12 @@ public class Corridor extends Map {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
registerEntities();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map clone() {
|
||||
Corridor c = new Corridor();
|
||||
c.cloneTiles(this);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,38 +3,22 @@ package main.maps;
|
|||
import java.awt.Color;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import main.DoorTile;
|
||||
import main.Main;
|
||||
import main.Tile;
|
||||
|
||||
public class ImageMap extends Map {
|
||||
|
||||
//Erstellung der abzulesenden Tiles (einem Tile wird eine farbe zugewiesen)
|
||||
|
||||
// Erstellung der abzulesenden Tiles (einem Tile wird eine farbe zugewiesen)
|
||||
|
||||
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)), new PixelTile(Tile.DOOR_LEFT_TOP, new Color(255, 150, 0)) ,
|
||||
new PixelTile(Tile.DOOR_LEFT_BOTTOM, new Color(69, 150, 0)), new PixelTile(Tile.STONE_WALL_BOTTOM, new Color(145, 145, 145)),
|
||||
new PixelTile(Tile.STONE_FLOOR_SHADOW_LEFT, new Color(251, 251, 129))};
|
||||
|
||||
public DoorTile topDoor;
|
||||
public DoorTile leftDoor;
|
||||
public DoorTile rightDoor;
|
||||
public DoorTile bottomDoor;
|
||||
|
||||
private static ImageMap[] maps;
|
||||
|
||||
static {
|
||||
maps = new ImageMap[8];
|
||||
for (int i = 0; i < maps.length; i++) {
|
||||
System.out.println("/res/images/maps/map" + (i + 1) + "a.png");
|
||||
maps[i] = new ImageMap("/res/images/maps/map" + (i + 1) + "a.png");
|
||||
}
|
||||
}
|
||||
new PixelTile(Tile.DOOR_LEFT_TOP, new Color(255, 150, 0)),
|
||||
new PixelTile(Tile.DOOR_LEFT_BOTTOM, new Color(69, 150, 0)),
|
||||
new PixelTile(Tile.STONE_WALL_BOTTOM, new Color(145, 145, 145)),
|
||||
new PixelTile(Tile.STONE_FLOOR_SHADOW_LEFT, new Color(251, 251, 129)) };
|
||||
|
||||
public ImageMap(String path) {
|
||||
super(15, 11);
|
||||
|
@ -55,36 +39,15 @@ public class ImageMap extends Map {
|
|||
}
|
||||
}
|
||||
if (id == Tile.DOOR_LEFT_BOTTOM) {
|
||||
DoorTile door = new DoorTile(x, y, this);
|
||||
tiles[x][y] = door;
|
||||
DoorTile door = new DoorTile(id, x, y, this);
|
||||
leftDoor = door;
|
||||
door.setSide(DoorTile.LEFT);
|
||||
tiles[x][y] = door;
|
||||
add(tiles[x][y]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (id == Tile.DOOR ) {
|
||||
DoorTile door = new DoorTile(x, y, this);
|
||||
tiles[x][y] = door;
|
||||
if (x == 7) {
|
||||
if (y < 5) {
|
||||
topDoor = door;
|
||||
door.setSide(DoorTile.TOP);
|
||||
} else {
|
||||
bottomDoor = door;
|
||||
door.setSide(DoorTile.BOTTOM);
|
||||
}
|
||||
}
|
||||
if (y == 5) {
|
||||
if (x < 7) {
|
||||
leftDoor = door;
|
||||
door.setSide(DoorTile.LEFT);
|
||||
} else {
|
||||
rightDoor = door;
|
||||
door.setSide(DoorTile.RIGHT);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tiles[x][y] = new Tile(id, x, y);
|
||||
}
|
||||
tiles[x][y] = new Tile(id, x, y);
|
||||
add(tiles[x][y]);
|
||||
}
|
||||
}
|
||||
|
@ -95,31 +58,7 @@ public class ImageMap extends Map {
|
|||
|
||||
public ImageMap(ImageMap map) {
|
||||
super(map.getWidth(), map.getHeight());
|
||||
for (int x = 0; x < map.getWidth(); x++) {
|
||||
for (int y = 0; y < map.getHeight(); y++) {
|
||||
tiles[x][y] = map.getTile(x, y).clone();
|
||||
if (tiles[x][y] instanceof DoorTile) {
|
||||
DoorTile dt = (DoorTile) tiles[x][y];
|
||||
if (dt.getSide() == DoorTile.TOP) {
|
||||
topDoor = dt;
|
||||
topDoor.setMap(this);
|
||||
}
|
||||
if (dt.getSide() == DoorTile.BOTTOM) {
|
||||
bottomDoor = dt;
|
||||
bottomDoor.setMap(this);
|
||||
}
|
||||
if (dt.getSide() == DoorTile.LEFT) {
|
||||
leftDoor = dt;
|
||||
leftDoor.setMap(this);
|
||||
}
|
||||
if (dt.getSide() == DoorTile.RIGHT) {
|
||||
rightDoor = dt;
|
||||
rightDoor.setMap(this);
|
||||
}
|
||||
}
|
||||
add(tiles[x][y]);
|
||||
}
|
||||
}
|
||||
cloneTiles(map);
|
||||
}
|
||||
|
||||
private static class PixelTile {
|
||||
|
@ -132,107 +71,8 @@ public class ImageMap extends Map {
|
|||
}
|
||||
}
|
||||
|
||||
public void generate(ArrayList<ImageMap> dungeon, int fromSide) {
|
||||
if (topDoor != null && fromSide != DoorTile.TOP) {
|
||||
ImageMap map = nextMap(DoorTile.BOTTOM);
|
||||
connectDoors(topDoor, map.bottomDoor);
|
||||
dungeon.add(map);
|
||||
map.generate(dungeon, DoorTile.BOTTOM);
|
||||
}
|
||||
if (bottomDoor != null && fromSide != DoorTile.BOTTOM) {
|
||||
ImageMap map = nextMap(DoorTile.TOP);
|
||||
connectDoors(bottomDoor, map.topDoor);
|
||||
dungeon.add(map);
|
||||
map.generate(dungeon, DoorTile.TOP);
|
||||
}
|
||||
if (leftDoor != null && fromSide != DoorTile.LEFT) {
|
||||
ImageMap map = nextMap(DoorTile.RIGHT);
|
||||
connectDoors(leftDoor, map.rightDoor);
|
||||
dungeon.add(map);
|
||||
map.generate(dungeon, DoorTile.RIGHT);
|
||||
}
|
||||
if (rightDoor != null && fromSide != DoorTile.RIGHT) {
|
||||
ImageMap map = nextMap(DoorTile.LEFT);
|
||||
connectDoors(rightDoor, map.leftDoor);
|
||||
dungeon.add(map);
|
||||
map.generate(dungeon, DoorTile.LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
private ImageMap nextMap(int entrySide) {
|
||||
float r = 1f;
|
||||
if (r < 0.1f) {
|
||||
return maps[0].clone();
|
||||
}
|
||||
if (r < 0.2f) {
|
||||
return maps[1].clone();
|
||||
}
|
||||
if (r < 0.6f) {
|
||||
ImageMap map;
|
||||
do {
|
||||
map = maps[(int) (Math.random() * 2) + 2];
|
||||
} while (!map.hasEntry(entrySide));
|
||||
return map.clone();
|
||||
} else {
|
||||
ImageMap map;
|
||||
do {
|
||||
map = maps[(int) (Math.random() * 4) + 4];
|
||||
} while (!map.hasEntry(entrySide));
|
||||
return map.clone();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasEntry(int entrySide) {
|
||||
switch (entrySide) {
|
||||
case DoorTile.TOP:
|
||||
return topDoor != null;
|
||||
case DoorTile.BOTTOM:
|
||||
return bottomDoor != null;
|
||||
case DoorTile.LEFT:
|
||||
return leftDoor != null;
|
||||
case DoorTile.RIGHT:
|
||||
return rightDoor != null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void connectDoors(DoorTile door, DoorTile door2) {
|
||||
door.setConnectedDoor(door2);
|
||||
door2.setConnectedDoor(door);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
if (topDoor != null) {
|
||||
Main.instance.manager.anmelden(topDoor, 50);
|
||||
}
|
||||
if (bottomDoor != null) {
|
||||
Main.instance.manager.anmelden(bottomDoor, 50);
|
||||
}
|
||||
if (leftDoor != null) {
|
||||
Main.instance.manager.anmelden(leftDoor, 50);
|
||||
}
|
||||
if (rightDoor != null) {
|
||||
Main.instance.manager.anmelden(rightDoor, 50);
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (topDoor != null) {
|
||||
Main.instance.manager.abmelden(topDoor);
|
||||
}
|
||||
if (bottomDoor != null) {
|
||||
Main.instance.manager.abmelden(bottomDoor);
|
||||
}
|
||||
if (leftDoor != null) {
|
||||
Main.instance.manager.abmelden(leftDoor);
|
||||
}
|
||||
if (rightDoor != null) {
|
||||
Main.instance.manager.abmelden(rightDoor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ImageMap clone() {
|
||||
public ImageMap clone() {
|
||||
return new ImageMap(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,12 @@ import java.util.ArrayList;
|
|||
|
||||
import ea.Knoten;
|
||||
import ea.Ticker;
|
||||
import main.DoorTile;
|
||||
import main.Main;
|
||||
import main.Tile;
|
||||
import main.entities.Entity;
|
||||
import main.entities.LivingEntity;
|
||||
import main.entities.player.Player;
|
||||
|
||||
/**
|
||||
* Auf der Map sind alle Entities, sowie die Tiles gespiechert.
|
||||
|
@ -16,7 +18,11 @@ public abstract class Map extends Knoten implements Ticker {
|
|||
|
||||
protected Tile[][] tiles; // Die Tiles der map in einem 2D Array.
|
||||
private ArrayList<Entity> entities;
|
||||
|
||||
|
||||
public DoorTile topDoor;
|
||||
public DoorTile leftDoor;
|
||||
public DoorTile rightDoor;
|
||||
public DoorTile bottomDoor;
|
||||
|
||||
public Map(int width, int height) {
|
||||
tiles = new Tile[width][height];
|
||||
|
@ -63,9 +69,83 @@ public abstract class Map extends Knoten implements Ticker {
|
|||
return entities;
|
||||
}
|
||||
|
||||
public void registerEntities() {
|
||||
for (Entity e : getEntities()) {
|
||||
Main.instance.manager.anmelden(e, 20);
|
||||
public void addLivingEntity(LivingEntity e) {
|
||||
entities.add(e);
|
||||
add(e.actionFigur);
|
||||
}
|
||||
|
||||
public abstract Map clone();
|
||||
|
||||
public void cloneTiles(Map map) {
|
||||
for (int x = 0; x < map.getWidth(); x++) {
|
||||
for (int y = 0; y < map.getHeight(); y++) {
|
||||
tiles[x][y] = map.getTile(x, y).clone();
|
||||
if (tiles[x][y] instanceof DoorTile) {
|
||||
DoorTile dt = (DoorTile) tiles[x][y];
|
||||
if (dt.getSide() == DoorTile.TOP) {
|
||||
topDoor = dt;
|
||||
topDoor.setMap(this);
|
||||
}
|
||||
if (dt.getSide() == DoorTile.BOTTOM) {
|
||||
bottomDoor = dt;
|
||||
bottomDoor.setMap(this);
|
||||
}
|
||||
if (dt.getSide() == DoorTile.LEFT) {
|
||||
leftDoor = dt;
|
||||
leftDoor.setMap(this);
|
||||
}
|
||||
if (dt.getSide() == DoorTile.RIGHT) {
|
||||
rightDoor = dt;
|
||||
rightDoor.setMap(this);
|
||||
}
|
||||
}
|
||||
add(tiles[x][y]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
if (topDoor != null) {
|
||||
Main.instance.manager.anmelden(topDoor, 50);
|
||||
}
|
||||
if (bottomDoor != null) {
|
||||
Main.instance.manager.anmelden(bottomDoor, 50);
|
||||
}
|
||||
if (leftDoor != null) {
|
||||
Main.instance.manager.anmelden(leftDoor, 50);
|
||||
}
|
||||
if (rightDoor != null) {
|
||||
Main.instance.manager.anmelden(rightDoor, 50);
|
||||
}
|
||||
for (Entity e : entities) {
|
||||
if (!(e instanceof Player)) {
|
||||
Main.instance.manager.anmelden(e, 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (topDoor != null) {
|
||||
Main.instance.manager.abmelden(topDoor);
|
||||
}
|
||||
if (bottomDoor != null) {
|
||||
Main.instance.manager.abmelden(bottomDoor);
|
||||
}
|
||||
if (leftDoor != null) {
|
||||
Main.instance.manager.abmelden(leftDoor);
|
||||
}
|
||||
if (rightDoor != null) {
|
||||
Main.instance.manager.abmelden(rightDoor);
|
||||
}
|
||||
for (Entity e : entities) {
|
||||
if (!(e instanceof Player)) {
|
||||
Main.instance.manager.abmelden(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void connectDoors(DoorTile door, DoorTile door2) {
|
||||
door.setConnectedDoor(door2);
|
||||
door2.setConnectedDoor(door);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
package main.maps;
|
||||
|
||||
import main.Tile;
|
||||
|
||||
public class Map01 extends Map {
|
||||
|
||||
public Map01 () {
|
||||
super (15,11);
|
||||
for (int x = 0; x < tiles.length; x++) {
|
||||
for (int y = 0; y < tiles[0].length; y++) {
|
||||
//Wand
|
||||
if((x == 4 || y == 9 || x == 10) && x > 3 && y > 0 && x < 11 && y < 10 && x != 7 ) {
|
||||
tiles[x][y] = new Tile(3, x, y);
|
||||
add(tiles[x][y]);
|
||||
}
|
||||
//Boden
|
||||
else if(x > 3 && y > 0 && x < 11 && y < 10) {
|
||||
tiles[x][y] = new Tile(5, x, y);
|
||||
add(tiles[x][y]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package main.maps;
|
||||
|
||||
import main.Tile;
|
||||
|
||||
public class Map02 extends Map {
|
||||
|
||||
public Map02() {
|
||||
super(15, 11);
|
||||
|
||||
for (int x = 0; x < tiles.length; x++) {
|
||||
for (int y = 0; y < tiles[0].length; y++) {
|
||||
// Wand
|
||||
if (y == 0 || x == 0 || y == 10 || x == 14) {
|
||||
// Übergang, Tür
|
||||
if (y == 10) {
|
||||
if (x > 4 && x < 10) {
|
||||
tiles[x][y] = new Tile(5, x, y);
|
||||
add(tiles[x][y]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
tiles[x][y] = new Tile(3, x, y);
|
||||
add(tiles[x][y]);
|
||||
}
|
||||
// 3D-Wand
|
||||
else if(y == 1 ) {
|
||||
tiles[x][y] = new Tile(4, x, y);
|
||||
add(tiles[x][y]);
|
||||
}
|
||||
// Steinboden
|
||||
else {
|
||||
tiles[x][y] = new Tile(5, x, y);
|
||||
add(tiles[x][y]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package main.maps;
|
||||
|
||||
import main.Tile;
|
||||
|
||||
public class TestMap extends Map {
|
||||
|
||||
public TestMap() {
|
||||
super(15, 11);
|
||||
|
||||
for (int x = 0; x < tiles.length; x++) {
|
||||
for (int y = 0; y < tiles[0].length; y++) {
|
||||
tiles[x][y] = new Tile(Math.random() * 5 < 1 ? 1 : 0, x, y);
|
||||
add(tiles[x][y]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,17 +28,14 @@ public class TutorialMap extends Map {
|
|||
}
|
||||
}
|
||||
|
||||
// und Spinnen auch
|
||||
Spider spider = new Spider();
|
||||
add(spider.actionFigur);
|
||||
getEntities().add(spider);
|
||||
|
||||
//und
|
||||
Snake snake = new Snake();
|
||||
add(snake.actionFigur);
|
||||
getEntities().add(snake);
|
||||
|
||||
// Alle Entities als ticker registrieren (triggert dann die update methoden)
|
||||
registerEntities();
|
||||
addLivingEntity(new Spider());
|
||||
addLivingEntity(new Snake());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map clone() {
|
||||
TutorialMap c = new TutorialMap();
|
||||
c.cloneTiles(this);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package main.worlds;
|
||||
|
||||
import main.entities.Snake;
|
||||
import main.maps.Map;
|
||||
|
||||
public class TestWorld extends World {
|
||||
|
||||
public TestWorld() {
|
||||
super(5);
|
||||
|
||||
Map m2 = maps[7].clone();
|
||||
getCurrentMap().connectDoors(getCurrentMap().leftDoor, m2.leftDoor);
|
||||
|
||||
getCurrentMap().addLivingEntity(new Snake());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,58 +1,53 @@
|
|||
package main;
|
||||
package main.worlds;
|
||||
|
||||
import ea.Knoten;
|
||||
import main.entities.Snake;
|
||||
import main.DoorTile;
|
||||
import main.entities.player.Player;
|
||||
import main.maps.ImageMap;
|
||||
import main.maps.Map;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Hier werden alle Maps gespeichert.
|
||||
*/
|
||||
public class World extends Knoten {
|
||||
public abstract class World extends Knoten {
|
||||
|
||||
public static final int SCALE_FACTOR = 4; // Der Basis Zoomfaktor
|
||||
public static final int SCALE = SCALE_FACTOR * 16; // Eine Gameunit ist so viele pixel lang
|
||||
|
||||
private ImageMap currentMap; // Die Map die aktuell angezeigt werden soll.
|
||||
private ArrayList<ImageMap> dungeon;
|
||||
|
||||
private Map currentMap; // Die Map die aktuell angezeigt werden soll.
|
||||
|
||||
private Player player;
|
||||
|
||||
public World() {
|
||||
protected static Map[] maps;
|
||||
|
||||
dungeon = new ArrayList<>(50);
|
||||
|
||||
ImageMap start = new ImageMap("/res/images/maps/map2a.png");
|
||||
dungeon.add(start);
|
||||
currentMap = start;
|
||||
start.generate(dungeon, DoorTile.BOTTOM);
|
||||
System.out.println("generated!");
|
||||
currentMap.start();
|
||||
|
||||
player = new Player();
|
||||
currentMap.getEntities().add(player);
|
||||
currentMap.add(player.actionFigur);
|
||||
|
||||
Snake s = new Snake();
|
||||
currentMap.getEntities().add(s);
|
||||
currentMap.add(s.actionFigur);
|
||||
currentMap.registerEntities();
|
||||
|
||||
add(currentMap);
|
||||
|
||||
public World(int startMap) {
|
||||
if (maps == null) {
|
||||
maps = new ImageMap[8];
|
||||
for (int i = 0; i < maps.length; i++) {
|
||||
maps[i] = new ImageMap("/res/images/maps/map" + i + "a.png");
|
||||
}
|
||||
}
|
||||
init(maps[startMap]);
|
||||
}
|
||||
|
||||
|
||||
public World(Map startMap) {
|
||||
init(startMap);
|
||||
}
|
||||
|
||||
private void init(Map startMap) {
|
||||
currentMap = startMap;
|
||||
player = new Player();
|
||||
add(currentMap);
|
||||
}
|
||||
|
||||
public Map getCurrentMap() {
|
||||
return currentMap;
|
||||
}
|
||||
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
|
||||
public void changeMap(DoorTile door) {
|
||||
currentMap.stop();
|
||||
currentMap.entfernen(player.actionFigur);
|
||||
|
@ -61,7 +56,12 @@ public class World extends Knoten {
|
|||
add(currentMap);
|
||||
currentMap.add(player.actionFigur);
|
||||
currentMap.start();
|
||||
player.setPos(door.getConnectedDoor().posX + 0.5f, door.getConnectedDoor().posY + 0.5f);
|
||||
player.setPos(door.getConnectedDoor().getPosX() + 0.5f, door.getConnectedDoor().getPosY() + 0.5f);
|
||||
door.getConnectedDoor().waitForLeave();
|
||||
}
|
||||
|
||||
public void start() {
|
||||
currentMap.addLivingEntity(player);
|
||||
currentMap.start();
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 168 B |
After Width: | Height: | Size: 201 B |
Before Width: | Height: | Size: 168 B After Width: | Height: | Size: 169 B |
Before Width: | Height: | Size: 223 B After Width: | Height: | Size: 213 B |
Before Width: | Height: | Size: 232 B After Width: | Height: | Size: 232 B |
Before Width: | Height: | Size: 169 B After Width: | Height: | Size: 181 B |
Before Width: | Height: | Size: 234 B After Width: | Height: | Size: 194 B |
Before Width: | Height: | Size: 181 B After Width: | Height: | Size: 171 B |
Before Width: | Height: | Size: 217 B After Width: | Height: | Size: 248 B |
Before Width: | Height: | Size: 171 B After Width: | Height: | Size: 162 B |
Before Width: | Height: | Size: 208 B After Width: | Height: | Size: 174 B |
Before Width: | Height: | Size: 162 B After Width: | Height: | Size: 166 B |
Before Width: | Height: | Size: 190 B After Width: | Height: | Size: 181 B |
Before Width: | Height: | Size: 166 B After Width: | Height: | Size: 164 B |
Before Width: | Height: | Size: 193 B After Width: | Height: | Size: 186 B |
Before Width: | Height: | Size: 164 B After Width: | Height: | Size: 160 B |
Before Width: | Height: | Size: 203 B After Width: | Height: | Size: 173 B |
Before Width: | Height: | Size: 160 B |
Before Width: | Height: | Size: 190 B |