final/src/MapReader.java

109 lines
4.3 KiB
Java
Raw Normal View History

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.*;
import java.util.Arrays;
2022-06-02 18:21:29 +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
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);
2022-06-03 17:22:05 +01:00
for(int i=0; i<file.length(); i++){
if(file.charAt(i)=='\n'){
y+=1;
x=0;
2022-06-03 17:22:05 +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'){
newTile("img/tiles/terrain/grassLeft.png");
2022-06-03 18:50:13 +01:00
} else if(file.charAt(i)=='3'){
newTile("img/tiles/terrain/grassRight.png");
2022-06-05 22:33:24 +01:00
} else if(file.charAt(i)=='q'){
newTile("img/tiles/terrain/grassTopLeft.png");
2022-06-05 22:33:24 +01:00
} else if(file.charAt(i)=='w'){
newTile("img/tiles/terrain/grassMid.png");
2022-06-05 22:33:24 +01:00
} else if(file.charAt(i)=='e'){
newTile("img/tiles/terrain/grassTopRight.png");
2022-06-05 22:33:24 +01:00
} else if(file.charAt(i)=='a'){
newTile("img/tiles/terrain/grassMiddleLeft.png");
2022-06-05 22:33:24 +01:00
} else if(file.charAt(i)=='s'){
newTile("img/tiles/terrain/grassCenter.png");
2022-06-05 22:33:24 +01:00
} else if(file.charAt(i)=='d'){
newTile("img/tiles/terrain/grassMiddleRight.png");
2022-06-05 22:33:24 +01:00
} else if(file.charAt(i)=='z'){
newTile("img/tiles/terrain/grassBottomLeft.png");
2022-06-05 22:33:24 +01:00
} else if(file.charAt(i)=='x'){
newTile("img/tiles/terrain/grassBottomMiddle.png");
2022-06-05 22:33:24 +01:00
} else if(file.charAt(i)=='c'){
newTile("img/tiles/terrain/grassBottomRight.png");
2022-06-05 22:33:24 +01:00
} else if(file.charAt(i)=='r'){
newTile("img/tiles/terrain/cornerTopLeft.png");
2022-06-05 22:33:24 +01:00
} else if(file.charAt(i)=='t'){
newTile("img/tiles/terrain/cornerTopRight.png");
2022-06-05 22:33:24 +01:00
} else if(file.charAt(i)=='f'){
newTile("img/tiles/terrain/cornerBottomLeft.png");
2022-06-05 22:33:24 +01:00
} else if(file.charAt(i)=='g'){
newTile("img/tiles/terrain/cornerBottomRight.png");
2022-06-05 16:53:03 +01:00
} else if(file.charAt(i)=='b'){
newTile("img/tiles/boxes/box.png");
GameFrame.game.map[x][y].breakable = true;
2022-06-06 03:18:10 +01:00
} else if(file.charAt(i)=='!'){
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)=='+') {
newTile("img/tiles/boxes/finish.png");
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");
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");
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");
GameFrame.game.map[x][y].movable = true;
2022-06-03 17:22:05 +01:00
}
x+=1;
2022-06-03 17:22:05 +01:00
}
2022-06-02 18:21:29 +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-02 18:21:29 +01:00
}