Map is now extendable
This commit is contained in:
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -21,7 +21,12 @@ public class Tile extends Knoten {
|
|||||||
private Bild img; // Bild, das gerendert wird
|
private Bild img; // Bild, das gerendert wird
|
||||||
private int id; // Die id dises Tiles
|
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;
|
this.id = id;
|
||||||
|
|
||||||
// Das Bild laden
|
// Das Bild laden
|
||||||
@@ -35,7 +40,7 @@ public class Tile extends Knoten {
|
|||||||
// Skalieren
|
// Skalieren
|
||||||
BufferedImage scaled = new BufferedImage(World.SCALE, World.SCALE, BufferedImage.TYPE_INT_RGB);
|
BufferedImage scaled = new BufferedImage(World.SCALE, World.SCALE, BufferedImage.TYPE_INT_RGB);
|
||||||
scaled.getGraphics().drawImage(buff, 0, 0, World.SCALE, World.SCALE, null);
|
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) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -2,13 +2,15 @@ package main;
|
|||||||
|
|
||||||
import ea.Knoten;
|
import ea.Knoten;
|
||||||
import main.entities.Player;
|
import main.entities.Player;
|
||||||
|
import main.maps.Map;
|
||||||
|
import main.maps.TestMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hier werden alle Maps gespeichert.
|
* Hier werden alle Maps gespeichert.
|
||||||
*/
|
*/
|
||||||
public class World extends Knoten {
|
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
|
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.
|
private Map currentMap; // Die Map die aktuell angezeigt werden soll.
|
||||||
@@ -16,7 +18,7 @@ public class World extends Knoten {
|
|||||||
public World(Player player) {
|
public World(Player player) {
|
||||||
|
|
||||||
// Map initialisieren
|
// Map initialisieren
|
||||||
currentMap = new Map();
|
currentMap = new TestMap();
|
||||||
// Map zu EA hinzufügen
|
// Map zu EA hinzufügen
|
||||||
add(currentMap);
|
add(currentMap);
|
||||||
// und Spieler auch
|
// und Spieler auch
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package main.entities;
|
package main.entities;
|
||||||
|
|
||||||
import ea.Ticker;
|
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.
|
* Alles was sich bewegen kann oder nicht an das grid der map gebunden ist, ist ein Entity.
|
||||||
|
|||||||
34
Zoelda/src/main/maps/Map.java
Normal file
34
Zoelda/src/main/maps/Map.java
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
17
Zoelda/src/main/maps/TestMap.java
Normal file
17
Zoelda/src/main/maps/TestMap.java
Normal file
@@ -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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user