2022-06-06 03:18:10 +01:00
|
|
|
import javax.sound.sampled.LineUnavailableException;
|
|
|
|
import javax.sound.sampled.UnsupportedAudioFileException;
|
2022-06-03 17:22:05 +01:00
|
|
|
import java.io.*;
|
2022-06-08 03:12:40 +01:00
|
|
|
import java.util.Arrays;
|
2022-06-02 18:21:29 +01:00
|
|
|
|
2022-06-15 02:34:35 +01:00
|
|
|
public class MapReader implements Serializable {
|
2022-06-12 23:22:13 +01:00
|
|
|
public static int x = 0;
|
|
|
|
public static int y = 0;
|
2022-06-12 22:28:27 +01:00
|
|
|
public static int TileX = 0;
|
|
|
|
public static int TileY = 0;
|
2022-06-03 18:08:59 +01:00
|
|
|
//Input game map
|
2022-06-03 18:50:13 +01:00
|
|
|
/*
|
|
|
|
1: Normal Grass
|
2022-06-05 22:33:24 +01:00
|
|
|
2: Left Grass:
|
|
|
|
3: Right Grass:
|
|
|
|
Grass Tiling:
|
|
|
|
qwe
|
|
|
|
asd
|
|
|
|
zxc
|
|
|
|
!: Slime
|
2022-06-08 04:59:19 +01:00
|
|
|
v= background
|
2022-06-05 22:33:24 +01:00
|
|
|
Grass:
|
2022-06-03 18:50:13 +01:00
|
|
|
*/
|
2022-06-12 22:28:27 +01:00
|
|
|
//o = steel
|
2022-06-08 03:12:40 +01:00
|
|
|
|
|
|
|
public static void inputMap(String filePath) throws IOException, SpriteException, UnsupportedAudioFileException, LineUnavailableException {
|
|
|
|
x = 0;
|
|
|
|
y = 0;
|
2022-06-15 02:34:35 +01:00
|
|
|
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);
|
2022-06-08 03:12:40 +01:00
|
|
|
}
|
|
|
|
String file = FileManager.readFile(filePath);
|
2022-06-03 17:22:05 +01:00
|
|
|
for(int i=0; i<file.length(); i++){
|
|
|
|
if(file.charAt(i)=='\n'){
|
2022-06-08 03:12:40 +01:00
|
|
|
y+=1;
|
|
|
|
x=0;
|
2022-06-03 17:22:05 +01:00
|
|
|
}
|
2022-06-08 03:12:40 +01:00
|
|
|
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");
|
2022-06-03 18:50:13 +01:00
|
|
|
} else if(file.charAt(i)=='2'){
|
2022-06-08 03:12:40 +01:00
|
|
|
newTile("img/tiles/terrain/grassLeft.png");
|
2022-06-03 18:50:13 +01:00
|
|
|
} else if(file.charAt(i)=='3'){
|
2022-06-08 03:12:40 +01:00
|
|
|
newTile("img/tiles/terrain/grassRight.png");
|
2022-06-05 22:33:24 +01:00
|
|
|
} else if(file.charAt(i)=='q'){
|
2022-06-08 03:12:40 +01:00
|
|
|
newTile("img/tiles/terrain/grassTopLeft.png");
|
2022-06-05 22:33:24 +01:00
|
|
|
} else if(file.charAt(i)=='w'){
|
2022-06-08 03:12:40 +01:00
|
|
|
newTile("img/tiles/terrain/grassMid.png");
|
2022-06-05 22:33:24 +01:00
|
|
|
} else if(file.charAt(i)=='e'){
|
2022-06-08 03:12:40 +01:00
|
|
|
newTile("img/tiles/terrain/grassTopRight.png");
|
2022-06-05 22:33:24 +01:00
|
|
|
} else if(file.charAt(i)=='a'){
|
2022-06-08 03:12:40 +01:00
|
|
|
newTile("img/tiles/terrain/grassMiddleLeft.png");
|
2022-06-05 22:33:24 +01:00
|
|
|
} else if(file.charAt(i)=='s'){
|
2022-06-08 03:12:40 +01:00
|
|
|
newTile("img/tiles/terrain/grassCenter.png");
|
2022-06-05 22:33:24 +01:00
|
|
|
} else if(file.charAt(i)=='d'){
|
2022-06-08 03:12:40 +01:00
|
|
|
newTile("img/tiles/terrain/grassMiddleRight.png");
|
2022-06-05 22:33:24 +01:00
|
|
|
} else if(file.charAt(i)=='z'){
|
2022-06-08 03:12:40 +01:00
|
|
|
newTile("img/tiles/terrain/grassBottomLeft.png");
|
2022-06-05 22:33:24 +01:00
|
|
|
} else if(file.charAt(i)=='x'){
|
2022-06-08 03:12:40 +01:00
|
|
|
newTile("img/tiles/terrain/grassBottomMiddle.png");
|
2022-06-05 22:33:24 +01:00
|
|
|
} else if(file.charAt(i)=='c'){
|
2022-06-08 03:12:40 +01:00
|
|
|
newTile("img/tiles/terrain/grassBottomRight.png");
|
2022-06-05 22:33:24 +01:00
|
|
|
} else if(file.charAt(i)=='r'){
|
2022-06-08 03:12:40 +01:00
|
|
|
newTile("img/tiles/terrain/cornerTopLeft.png");
|
2022-06-05 22:33:24 +01:00
|
|
|
} else if(file.charAt(i)=='t'){
|
2022-06-08 03:12:40 +01:00
|
|
|
newTile("img/tiles/terrain/cornerTopRight.png");
|
2022-06-05 22:33:24 +01:00
|
|
|
} else if(file.charAt(i)=='f'){
|
2022-06-08 03:12:40 +01:00
|
|
|
newTile("img/tiles/terrain/cornerBottomLeft.png");
|
2022-06-05 22:33:24 +01:00
|
|
|
} else if(file.charAt(i)=='g'){
|
2022-06-08 03:12:40 +01:00
|
|
|
newTile("img/tiles/terrain/cornerBottomRight.png");
|
2022-06-05 16:53:03 +01:00
|
|
|
} else if(file.charAt(i)=='b'){
|
2022-06-08 03:12:40 +01:00
|
|
|
newTile("img/tiles/boxes/box.png");
|
2022-06-15 02:34:35 +01:00
|
|
|
GameFrame.game.map[x][y].breakable = true;
|
2022-06-06 03:18:10 +01:00
|
|
|
} else if(file.charAt(i)=='!'){
|
2022-06-15 02:34:35 +01:00
|
|
|
GameFrame.game.enemy.add(new NonPlayer(TileX, TileY, GameFrame.game.slimeSpriteArray, 50, 28, 100));
|
2022-06-06 03:18:10 +01:00
|
|
|
|
2022-06-06 16:24:46 +01:00
|
|
|
} else if(file.charAt(i)=='+') {
|
2022-06-08 03:12:40 +01:00
|
|
|
newTile("img/tiles/boxes/finish.png");
|
2022-06-15 02:34:35 +01:00
|
|
|
GameFrame.game.map[x][y].isFinish = true;
|
|
|
|
GameFrame.game.map[x][y].nonBombCollide = true;
|
2022-06-08 04:59:19 +01:00
|
|
|
} else if(file.charAt(i)=='v'){
|
|
|
|
newTile("img/tiles/background/wall.png");
|
2022-06-15 02:34:35 +01:00
|
|
|
GameFrame.game.map[x][y].collision = false;
|
|
|
|
GameFrame.game.map[x][y].replaceAble = true;
|
2022-06-08 04:59:19 +01:00
|
|
|
} else if(file.charAt(i)=='l'){
|
|
|
|
newTile("img/tiles/terrain/lava.png");
|
2022-06-15 02:34:35 +01:00
|
|
|
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]);
|
2022-06-09 18:05:42 +01:00
|
|
|
}
|
2022-06-12 22:28:27 +01:00
|
|
|
} else if(file.charAt(i)=='o'){
|
|
|
|
newTile("img/tiles/boxes/steel.png");
|
2022-06-15 02:34:35 +01:00
|
|
|
GameFrame.game.map[x][y].movable = true;
|
2022-06-03 17:22:05 +01:00
|
|
|
}
|
2022-06-08 03:12:40 +01:00
|
|
|
x+=1;
|
2022-06-03 17:22:05 +01:00
|
|
|
}
|
2022-06-02 18:21:29 +01:00
|
|
|
}
|
2022-06-08 03:12:40 +01:00
|
|
|
public static void newTile(String filePath) throws IOException, SpriteException {
|
2022-06-16 03:08:35 +01:00
|
|
|
GameFrame.game.map[x][y]=(new SingleTile(TileX,TileY, new BufferedImageWrapper((filePath))));
|
2022-06-08 03:12:40 +01:00
|
|
|
}
|
2022-06-02 18:21:29 +01:00
|
|
|
}
|