diff --git a/Zoelda/src/main/Map.java b/Zoelda/src/main/Map.java deleted file mode 100644 index 5633da9..0000000 --- a/Zoelda/src/main/Map.java +++ /dev/null @@ -1,56 +0,0 @@ -package main; - -import ea.Knoten; - -/** - * Auf der Map sind alle Entities, sowie die Tiles gespiechert. - */ -public class Map extends Knoten { - - private Tile[][] map; // Die Tiles der map in einem 2D Array. - - public Map() { - // Größe der Map ist 15u breit und 11u hoch - map = new Tile[15][11]; - - // Tiles der map definieren - for (int x = 0; x < map.length; x++) { - for (int y = 0; y < map[0].length; y++) { - int id = 0; - - // Auf bestimmten koordinaten wird die id des Tiles geändert - if (y == 1 || (x == 7 && y == 7)) { - id = Tile.WALL_BOTTOM; - } - if (y == 0 || y == map[0].length - 1 || x == 0 || x == map.length - 1 || (x == 7 && y == 6)) { - id = Tile.WALL_TOP; - } - - // Tile wird erstellt - map[x][y] = new Tile(id); - // Tile wird an die passende Position gebracht - map[x][y].positionSetzen(x * World.SCALE, y * World.SCALE); - // Tile wird zur EA hinzugefügt (damit es auch gerendert wird) - add(map[x][y]); - } - } - } - - /** - * Gibt das Tile-Objekt an der gegebenen Koordinate zurück. (nur wenn es existiert) - */ - public Tile getTile(int x, int y) { - if (x >= 0 && x < map.length && y >= 0 && y < map[0].length) { - return map[x][y]; - } - return null; - } - - public int getWidth() { - return map.length; - } - - public int getHeight() { - return map[0].length; - } -} diff --git a/Zoelda/src/main/Tile.java b/Zoelda/src/main/Tile.java index ae68dee..4e5593f 100644 --- a/Zoelda/src/main/Tile.java +++ b/Zoelda/src/main/Tile.java @@ -21,7 +21,12 @@ public class Tile extends Knoten { private Bild img; // Bild, das gerendert wird private int id; // Die id dises Tiles - public Tile(int id) { + /** + * @param id + * @param x - X-Koordinate in units + * @param y - Y-Koordinate in units + */ + public Tile(int id, float x, float y) { this.id = id; // Das Bild laden @@ -35,7 +40,7 @@ public class Tile extends Knoten { // Skalieren BufferedImage scaled = new BufferedImage(World.SCALE, World.SCALE, BufferedImage.TYPE_INT_RGB); scaled.getGraphics().drawImage(buff, 0, 0, World.SCALE, World.SCALE, null); - img = new Bild(0, 0, scaled); + img = new Bild(x * World.SCALE, y * World.SCALE, scaled); } catch (IOException e) { e.printStackTrace(); diff --git a/Zoelda/src/main/World.java b/Zoelda/src/main/World.java index a654611..51fc559 100644 --- a/Zoelda/src/main/World.java +++ b/Zoelda/src/main/World.java @@ -2,13 +2,15 @@ package main; import ea.Knoten; import main.entities.Player; +import main.maps.Map; +import main.maps.TestMap; /** * Hier werden alle Maps gespeichert. */ public class World extends Knoten { - public static final int SCALE_FACTOR = 6; // Der Basis Zoomfaktor + public static final int SCALE_FACTOR = 4; // Der Basis Zoomfaktor public static final int SCALE = SCALE_FACTOR * Tile.getSize(); // Eine Gameunit ist so viele pixel lang private Map currentMap; // Die Map die aktuell angezeigt werden soll. @@ -16,7 +18,7 @@ public class World extends Knoten { public World(Player player) { // Map initialisieren - currentMap = new Map(); + currentMap = new TestMap(); // Map zu EA hinzufügen add(currentMap); // und Spieler auch diff --git a/Zoelda/src/main/entities/Entity.java b/Zoelda/src/main/entities/Entity.java index 8699dd7..50f50ef 100644 --- a/Zoelda/src/main/entities/Entity.java +++ b/Zoelda/src/main/entities/Entity.java @@ -1,7 +1,7 @@ package main.entities; import ea.Ticker; -import main.Map; +import main.maps.Map; /* * Alles was sich bewegen kann oder nicht an das grid der map gebunden ist, ist ein Entity. diff --git a/Zoelda/src/main/maps/Map.java b/Zoelda/src/main/maps/Map.java new file mode 100644 index 0000000..41ee131 --- /dev/null +++ b/Zoelda/src/main/maps/Map.java @@ -0,0 +1,34 @@ +package main.maps; + +import ea.Knoten; +import main.Tile; + +/** + * Auf der Map sind alle Entities, sowie die Tiles gespiechert. + */ +public abstract class Map extends Knoten { + + protected Tile[][] map; // Die Tiles der map in einem 2D Array. + + public Map(int width, int height) { + map = new Tile[width][height]; + } + + /** + * Gibt das Tile-Objekt an der gegebenen Koordinate zurück. (nur wenn es existiert) + */ + public Tile getTile(int x, int y) { + if (x >= 0 && x < map.length && y >= 0 && y < map[0].length) { + return map[x][y]; + } + return null; + } + + public int getWidth() { + return map.length; + } + + public int getHeight() { + return map[0].length; + } +} diff --git a/Zoelda/src/main/maps/TestMap.java b/Zoelda/src/main/maps/TestMap.java new file mode 100644 index 0000000..477634a --- /dev/null +++ b/Zoelda/src/main/maps/TestMap.java @@ -0,0 +1,17 @@ +package main.maps; + +import main.Tile; + +public class TestMap extends Map { + + public TestMap() { + super(20, 10); + + for (int x = 0; x < map.length; x++) { + for (int y = 0; y < map[0].length; y++) { + map[x][y] = new Tile(0, x, y); + add(map[x][y]); + } + } + } +}