Compare commits

...

2 Commits

Author SHA1 Message Date
Asecave
8b0285d3a8 Map is now extendable 2021-06-23 18:20:19 +02:00
Asecave
2a85c1d5a3 entity package 2021-06-23 17:57:55 +02:00
9 changed files with 71 additions and 62 deletions

View File

@@ -2,6 +2,7 @@ package main;
import ea.ActionFigur;
import ea.Figur;
import main.entities.Entity;
/*
* Alles was zustände hat und sich Bewegen kann, ist ein LivingEntity.

View File

@@ -2,6 +2,7 @@ package main;
import ea.Game;
import ea.Manager;
import main.entities.Player;
/**
* Von hier wird alles initialisiert. Das ist die höchste Klasse.

View File

@@ -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;
}
}

View File

@@ -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();

View File

@@ -1,13 +1,16 @@
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.
@@ -15,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

View File

@@ -1,6 +1,7 @@
package main;
package main.entities;
import ea.Ticker;
import main.maps.Map;
/*
* Alles was sich bewegen kann oder nicht an das grid der map gebunden ist, ist ein Entity.

View File

@@ -1,6 +1,9 @@
package main;
package main.entities;
import ea.Taste;
import main.LivingEntity;
import main.Malin;
import main.SheetLoader;
public class Player extends LivingEntity {

View 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;
}
}

View 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]);
}
}
}
}