made mapBackground a 2D array
This commit is contained in:
parent
8d2416f4cf
commit
09e1b8c799
@ -14,14 +14,14 @@ import java.util.Scanner;
|
||||
public class ImageCell {
|
||||
private static BufferedImage image;
|
||||
private static LinkedList<BufferedImage> imagesOfTiles;
|
||||
private int[] mapBackground;
|
||||
private int[][] mapBackground;
|
||||
|
||||
public void readMapFile(String name) {
|
||||
try {
|
||||
mapBackground = new int[WindowOfFreeMove.CANVAS_WIDTH * WindowOfFreeMove.CANVAS_HEIGHT];
|
||||
int count = 0;
|
||||
mapBackground = new int[WindowOfFreeMove.CANVAS_WIDTH][WindowOfFreeMove.CANVAS_HEIGHT];
|
||||
File mapFile = new File("src/main/resources/maps/" + name + ".txt");
|
||||
Scanner scanner = new Scanner(mapFile);
|
||||
int j = 0;
|
||||
while (scanner.hasNextLine()) {
|
||||
String data = scanner.nextLine();
|
||||
if (data.contains("<tileset>")) {
|
||||
@ -30,9 +30,9 @@ public class ImageCell {
|
||||
} else {
|
||||
String[] mapColumn = data.split(" ");
|
||||
for (int i = 0; i < mapColumn.length; i++) {
|
||||
mapBackground[count] = Integer.parseInt(mapColumn[i]);
|
||||
count++;
|
||||
mapBackground[i][j] = Integer.parseInt(mapColumn[i]);
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
@ -77,8 +77,8 @@ public class ImageCell {
|
||||
return imagesOfTiles;
|
||||
}
|
||||
|
||||
public void paintBackground(Graphics g, int x, int y, int count) {
|
||||
g.drawImage(imagesOfTiles.get(mapBackground[count]), y * WindowOfFreeMove.CELL_SIZE,
|
||||
x * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null);
|
||||
public void paintBackground(Graphics g, int x, int y) {
|
||||
g.drawImage(imagesOfTiles.get(mapBackground[x][y]), x * WindowOfFreeMove.CELL_SIZE,
|
||||
y * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,8 +19,8 @@ import java.util.LinkedList;
|
||||
|
||||
public class WindowOfFreeMove extends JFrame {
|
||||
public static final int CELL_SIZE = 40;
|
||||
public static final int CANVAS_WIDTH = 10;
|
||||
public static final int CANVAS_HEIGHT = 10;
|
||||
public static final int CANVAS_WIDTH = 15;
|
||||
public static final int CANVAS_HEIGHT = 15;
|
||||
|
||||
private static boolean canPersonMove;
|
||||
private static int nextMove;
|
||||
@ -210,11 +210,9 @@ public class WindowOfFreeMove extends JFrame {
|
||||
Graphics2D g2D = (Graphics2D) g;
|
||||
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
int count = 0;
|
||||
for (int i = 0; i < CANVAS_WIDTH; i++) {
|
||||
for (int j = 0; j < CANVAS_HEIGHT; j++) {
|
||||
map.getActualMap().getImageCell().paintBackground(g2D, i, j, count);
|
||||
count++;
|
||||
map.getActualMap().getImageCell().paintBackground(g2D, i, j);
|
||||
}
|
||||
}
|
||||
for (Cell cell : map.getActualMap().getMoveToCells()) {
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 35 KiB |
@ -1,12 +1,12 @@
|
||||
<tileset> A2_Ground.png 512 384 32
|
||||
<tileset> D_OutDoor.png 512 512 32
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 82 94 0 0 82 94 0 0
|
||||
0 0 83 95 0 0 83 95 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 153 0 0 0 0 153 0 0
|
||||
0 0 0 153 153 153 153 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 82 94 1 1 82 94 1 1
|
||||
1 1 83 95 1 1 83 95 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 153 1 1 1 1 153 1 1
|
||||
1 1 1 153 153 153 153 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
<tileset> A2_Ground.png 512 384 32
|
||||
<tileset> D_OutDoor.png 512 512 32
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 82 94 0 0 82 94 0 0
|
||||
0 0 83 95 0 0 83 95 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 153 0 0 0 0 153 0 0
|
||||
0 0 0 153 153 153 153 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 82 94 1 1 82 94 1 1
|
||||
1 1 83 95 1 1 83 95 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 153 1 1 1 1 153 1 1
|
||||
1 1 1 153 153 153 153 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
<tileset> A2_Ground.png 512 384 32
|
||||
<tileset> D_OutDoor.png 512 512 32
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 82 94 0 0 82 94 0 0
|
||||
0 0 83 95 0 0 83 95 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 153 0 0 0 0 153 0 0
|
||||
0 0 0 153 153 153 153 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 82 94 1 1 82 94 1 1
|
||||
1 1 83 95 1 1 83 95 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 153 1 1 1 1 153 1 1
|
||||
1 1 1 153 153 153 153 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
<tileset> A2_Ground.png 512 384 32
|
||||
<tileset> D_OutDoor.png 512 512 32
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 82 94 0 0 82 94 0 0
|
||||
0 0 83 95 0 0 83 95 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 153 0 0 0 0 153 0 0
|
||||
0 0 0 153 153 153 153 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 82 94 1 1 82 94 1 1
|
||||
1 1 83 95 1 1 83 95 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 153 1 1 1 1 153 1 1
|
||||
1 1 1 153 153 153 153 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
<tileset> A2_Ground.png 512 384 32
|
||||
<tileset> D_OutDoor.png 512 512 32
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 82 94 0 0 82 94 0 0
|
||||
0 0 83 95 0 0 83 95 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 153 0 0 0 0 153 0 0
|
||||
0 0 153 153 153 153 153 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0 0 0
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 82 94 1 1 82 94 1 1
|
||||
1 1 83 95 1 1 83 95 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 153 1 1 1 1 153 1 1
|
||||
1 1 153 153 153 153 153 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
1 1 1 1 1 1 1 1 1 1
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user