109 lines
4.3 KiB
Java
109 lines
4.3 KiB
Java
import javax.sound.sampled.LineUnavailableException;
|
|
import javax.sound.sampled.UnsupportedAudioFileException;
|
|
import java.io.*;
|
|
import java.util.Arrays;
|
|
|
|
public class MapReader implements Serializable {
|
|
public static int x = 0;
|
|
public static int y = 0;
|
|
public static int TileX = 0;
|
|
public static int TileY = 0;
|
|
//Input game map
|
|
/*
|
|
1: Normal Grass
|
|
2: Left Grass:
|
|
3: Right Grass:
|
|
Grass Tiling:
|
|
qwe
|
|
asd
|
|
zxc
|
|
!: Slime
|
|
v= background
|
|
Grass:
|
|
*/
|
|
//o = steel
|
|
|
|
public static void inputMap(String filePath) throws IOException, SpriteException, UnsupportedAudioFileException, LineUnavailableException {
|
|
x = 0;
|
|
y = 0;
|
|
GameFrame.game.enemy.clear();
|
|
GameFrame.game.particleTiles.clear();
|
|
for(int i=0; i<GameFrame.game.map.length; i++){
|
|
Arrays.fill(GameFrame.game.map[i], null);
|
|
}
|
|
String file = FileManager.readFile(filePath);
|
|
for(int i=0; i<file.length(); i++){
|
|
if(file.charAt(i)=='\n'){
|
|
y+=1;
|
|
x=0;
|
|
}
|
|
TileX = x*Tile.length - (GamePanel.GAME_WIDTH/2);
|
|
if(y==0){
|
|
TileX += Tile.length;
|
|
}
|
|
TileY = y*Tile.length;
|
|
if(file.charAt(i)=='1'){
|
|
newTile("img/tiles/terrain/grass.png");
|
|
} else if(file.charAt(i)=='2'){
|
|
newTile("img/tiles/terrain/grassLeft.png");
|
|
} else if(file.charAt(i)=='3'){
|
|
newTile("img/tiles/terrain/grassRight.png");
|
|
} else if(file.charAt(i)=='q'){
|
|
newTile("img/tiles/terrain/grassTopLeft.png");
|
|
} else if(file.charAt(i)=='w'){
|
|
newTile("img/tiles/terrain/grassMid.png");
|
|
} else if(file.charAt(i)=='e'){
|
|
newTile("img/tiles/terrain/grassTopRight.png");
|
|
} else if(file.charAt(i)=='a'){
|
|
newTile("img/tiles/terrain/grassMiddleLeft.png");
|
|
} else if(file.charAt(i)=='s'){
|
|
newTile("img/tiles/terrain/grassCenter.png");
|
|
} else if(file.charAt(i)=='d'){
|
|
newTile("img/tiles/terrain/grassMiddleRight.png");
|
|
} else if(file.charAt(i)=='z'){
|
|
newTile("img/tiles/terrain/grassBottomLeft.png");
|
|
} else if(file.charAt(i)=='x'){
|
|
newTile("img/tiles/terrain/grassBottomMiddle.png");
|
|
} else if(file.charAt(i)=='c'){
|
|
newTile("img/tiles/terrain/grassBottomRight.png");
|
|
} else if(file.charAt(i)=='r'){
|
|
newTile("img/tiles/terrain/cornerTopLeft.png");
|
|
} else if(file.charAt(i)=='t'){
|
|
newTile("img/tiles/terrain/cornerTopRight.png");
|
|
} else if(file.charAt(i)=='f'){
|
|
newTile("img/tiles/terrain/cornerBottomLeft.png");
|
|
} else if(file.charAt(i)=='g'){
|
|
newTile("img/tiles/terrain/cornerBottomRight.png");
|
|
} else if(file.charAt(i)=='b'){
|
|
newTile("img/tiles/boxes/box.png");
|
|
GameFrame.game.map[x][y].breakable = true;
|
|
} else if(file.charAt(i)=='!'){
|
|
GameFrame.game.enemy.add(new NonPlayer(TileX, TileY, GameFrame.game.slimeSpriteArray, 50, 28, 100));
|
|
|
|
} else if(file.charAt(i)=='+') {
|
|
newTile("img/tiles/boxes/finish.png");
|
|
GameFrame.game.map[x][y].isFinish = true;
|
|
GameFrame.game.map[x][y].nonBombCollide = true;
|
|
} else if(file.charAt(i)=='v'){
|
|
newTile("img/tiles/background/wall.png");
|
|
GameFrame.game.map[x][y].collision = false;
|
|
GameFrame.game.map[x][y].replaceAble = true;
|
|
} else if(file.charAt(i)=='l'){
|
|
newTile("img/tiles/terrain/lava.png");
|
|
GameFrame.game.map[x][y].nonBombCollide = true;
|
|
GameFrame.game.map[x][y].kills = true;
|
|
if(y>0&&GameFrame.game.map[x][y-1]==null) {
|
|
GameFrame.game.particleTiles.add(GameFrame.game.map[x][y]);
|
|
}
|
|
} else if(file.charAt(i)=='o'){
|
|
newTile("img/tiles/boxes/steel.png");
|
|
GameFrame.game.map[x][y].movable = true;
|
|
}
|
|
x+=1;
|
|
}
|
|
}
|
|
public static void newTile(String filePath) throws IOException, SpriteException {
|
|
GameFrame.game.map[x][y]=(new SingleTile(TileX,TileY, new BufferedImageWrapper((filePath))));
|
|
}
|
|
}
|