final/src/MapReader.java

38 lines
1.4 KiB
Java
Raw Normal View History

2022-06-03 17:22:05 +01:00
import java.io.*;
2022-06-02 18:21:29 +01:00
import java.util.ArrayList;
2022-06-02 19:48:16 +01:00
import java.util.Scanner;
2022-06-02 18:21:29 +01:00
public class MapReader {
2022-06-03 18:08:59 +01:00
//Input game map
2022-06-03 18:50:13 +01:00
/*
1: Normal Grass
2: Left Grass
3: Middle Grass
4: Right Grass
*/
2022-06-03 18:17:03 +01:00
public static void inputMap(ArrayList<Tile> map, String filePath) throws IOException, SpriteException {
2022-06-03 18:08:59 +01:00
String file = FileManager.readFile(filePath);
2022-06-05 16:53:03 +01:00
int x = -GamePanel.WIDTH*Tile.length;
2022-06-03 17:22:05 +01:00
int y = 0;
for(int i=0; i<file.length(); i++){
if(file.charAt(i)=='\n'){
y+=Tile.length;
2022-06-05 16:53:03 +01:00
x= -GamePanel.WIDTH*Tile.length;
2022-06-03 17:22:05 +01:00
}
else if(file.charAt(i)=='1'){
2022-06-03 18:17:03 +01:00
map.add(new SingleTile(x,y, GamePanel.getImage("img/tiles/terrain/grass.png")));
2022-06-03 18:50:13 +01:00
} else if(file.charAt(i)=='2'){
map.add(new SingleTile(x,y, GamePanel.getImage("img/tiles/terrain/grassLeft.png")));
} else if(file.charAt(i)=='3'){
map.add(new SingleTile(x,y, GamePanel.getImage("img/tiles/terrain/grassMid.png")));
} else if(file.charAt(i)=='4'){
map.add(new SingleTile(x,y, GamePanel.getImage("img/tiles/terrain/grassRight.png")));
2022-06-05 16:53:03 +01:00
} else if(file.charAt(i)=='b'){
map.add(new SingleTile(x,y, GamePanel.getImage("img/tiles/boxes/box.png")));
map.get(map.size()-1).collision = false;
2022-06-03 17:22:05 +01:00
}
x+=Tile.length;
}
2022-06-02 18:21:29 +01:00
}
}