changed tile array to three-dimensional array (i0=map; i1=col; i2=row)
This commit is contained in:
@@ -3,6 +3,7 @@ package de.miaurizius.jgame2d.tile;
|
||||
import de.miaurizius.jgame2d.core.Boot;
|
||||
import de.miaurizius.jgame2d.core.GamePanel;
|
||||
import de.miaurizius.jgame2d.core.Utility;
|
||||
import de.miaurizius.jgame2d.core.enums.Map;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
@@ -13,14 +14,14 @@ public class TileManager {
|
||||
|
||||
GamePanel panel;
|
||||
public Tile[] tile;
|
||||
public int[][] mapTileNum;
|
||||
public int[][][] mapTileNum;
|
||||
|
||||
public TileManager(GamePanel panel) {
|
||||
this.panel = panel;
|
||||
tile = new Tile[50];
|
||||
mapTileNum = new int[panel.maxWorldCol][panel.maxWorldRow];
|
||||
mapTileNum = new int[Map.values().length][panel.maxWorldCol][panel.maxWorldRow];
|
||||
getTileImage();
|
||||
loadMap(panel.currentMap);
|
||||
for(Map m : Map.values()) loadMap(m);
|
||||
}
|
||||
|
||||
public void initializeTile(int i, String name, boolean col) {
|
||||
@@ -85,15 +86,20 @@ public class TileManager {
|
||||
initializeTile(40, "wall", true);
|
||||
initializeTile(41, "tree", true);
|
||||
|
||||
//
|
||||
initializeTile(42, "hut", false);
|
||||
initializeTile(43, "floor01", false);
|
||||
initializeTile(44, "table01", true);
|
||||
|
||||
for (Tile tile : tile) {
|
||||
if(tile == null) continue;
|
||||
tile.image = Utility.scaleImage(tile.image, panel.tileSize, panel.tileSize);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadMap(String map) {
|
||||
public void loadMap(Map map) {
|
||||
try {
|
||||
InputStream stream = new FileInputStream("assets/maps/"+map+".map");
|
||||
InputStream stream = new FileInputStream("assets/maps/"+map.getName()+".map");
|
||||
BufferedReader bReader = new BufferedReader(new InputStreamReader(stream));
|
||||
int col = 0;
|
||||
int row = 0;
|
||||
@@ -102,7 +108,7 @@ public class TileManager {
|
||||
while(col < panel.maxWorldCol) {
|
||||
String[] numbers = line.split(" ");
|
||||
int num = Integer.parseInt(numbers[col]);
|
||||
mapTileNum[col][row] = num;
|
||||
mapTileNum[map.getIndex()][col][row] = num;
|
||||
col++;
|
||||
}
|
||||
if(col == panel.maxWorldCol) {
|
||||
@@ -121,7 +127,7 @@ public class TileManager {
|
||||
int worldRow = 0;
|
||||
|
||||
while(worldCol < panel.maxWorldCol && worldRow < panel.maxWorldRow) {
|
||||
int tileNum = mapTileNum[worldCol][worldRow];
|
||||
int tileNum = mapTileNum[panel.currentMap.getIndex()][worldCol][worldRow];
|
||||
|
||||
int worldX = worldCol * panel.tileSize;
|
||||
int worldY = worldRow * panel.tileSize;
|
||||
|
||||
Reference in New Issue
Block a user