made mapBackground a 2D array

This commit is contained in:
musilto9 2020-03-17 10:54:29 +01:00
parent 8d2416f4cf
commit 09e1b8c799
8 changed files with 61 additions and 63 deletions

View File

@ -14,14 +14,14 @@ import java.util.Scanner;
public class ImageCell { public class ImageCell {
private static BufferedImage image; private static BufferedImage image;
private static LinkedList<BufferedImage> imagesOfTiles; private static LinkedList<BufferedImage> imagesOfTiles;
private int[] mapBackground; private int[][] mapBackground;
public void readMapFile(String name) { public void readMapFile(String name) {
try { try {
mapBackground = new int[WindowOfFreeMove.CANVAS_WIDTH * WindowOfFreeMove.CANVAS_HEIGHT]; mapBackground = new int[WindowOfFreeMove.CANVAS_WIDTH][WindowOfFreeMove.CANVAS_HEIGHT];
int count = 0;
File mapFile = new File("src/main/resources/maps/" + name + ".txt"); File mapFile = new File("src/main/resources/maps/" + name + ".txt");
Scanner scanner = new Scanner(mapFile); Scanner scanner = new Scanner(mapFile);
int j = 0;
while (scanner.hasNextLine()) { while (scanner.hasNextLine()) {
String data = scanner.nextLine(); String data = scanner.nextLine();
if (data.contains("<tileset>")) { if (data.contains("<tileset>")) {
@ -30,9 +30,9 @@ public class ImageCell {
} else { } else {
String[] mapColumn = data.split(" "); String[] mapColumn = data.split(" ");
for (int i = 0; i < mapColumn.length; i++) { for (int i = 0; i < mapColumn.length; i++) {
mapBackground[count] = Integer.parseInt(mapColumn[i]); mapBackground[i][j] = Integer.parseInt(mapColumn[i]);
count++;
} }
j++;
} }
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
@ -77,8 +77,8 @@ public class ImageCell {
return imagesOfTiles; return imagesOfTiles;
} }
public void paintBackground(Graphics g, int x, int y, int count) { public void paintBackground(Graphics g, int x, int y) {
g.drawImage(imagesOfTiles.get(mapBackground[count]), y * WindowOfFreeMove.CELL_SIZE, g.drawImage(imagesOfTiles.get(mapBackground[x][y]), x * WindowOfFreeMove.CELL_SIZE,
x * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null); y * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null);
} }
} }

View File

@ -19,8 +19,8 @@ import java.util.LinkedList;
public class WindowOfFreeMove extends JFrame { public class WindowOfFreeMove extends JFrame {
public static final int CELL_SIZE = 40; public static final int CELL_SIZE = 40;
public static final int CANVAS_WIDTH = 10; public static final int CANVAS_WIDTH = 15;
public static final int CANVAS_HEIGHT = 10; public static final int CANVAS_HEIGHT = 15;
private static boolean canPersonMove; private static boolean canPersonMove;
private static int nextMove; private static int nextMove;
@ -210,11 +210,9 @@ public class WindowOfFreeMove extends JFrame {
Graphics2D g2D = (Graphics2D) g; Graphics2D g2D = (Graphics2D) g;
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON); RenderingHints.VALUE_ANTIALIAS_ON);
int count = 0;
for (int i = 0; i < CANVAS_WIDTH; i++) { for (int i = 0; i < CANVAS_WIDTH; i++) {
for (int j = 0; j < CANVAS_HEIGHT; j++) { for (int j = 0; j < CANVAS_HEIGHT; j++) {
map.getActualMap().getImageCell().paintBackground(g2D, i, j, count); map.getActualMap().getImageCell().paintBackground(g2D, i, j);
count++;
} }
} }
for (Cell cell : map.getActualMap().getMoveToCells()) { for (Cell cell : map.getActualMap().getMoveToCells()) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 35 KiB

View File

@ -1,12 +1,12 @@
<tileset> A2_Ground.png 512 384 32 <tileset> A2_Ground.png 512 384 32
<tileset> D_OutDoor.png 512 512 32 <tileset> D_OutDoor.png 512 512 32
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 82 94 0 0 82 94 0 0 1 1 82 94 1 1 82 94 1 1
0 0 83 95 0 0 83 95 0 0 1 1 83 95 1 1 83 95 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 153 0 0 0 0 153 0 0 1 1 153 1 1 1 1 153 1 1
0 0 0 153 153 153 153 0 0 0 1 1 1 153 153 153 153 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1

View File

@ -1,12 +1,12 @@
<tileset> A2_Ground.png 512 384 32 <tileset> A2_Ground.png 512 384 32
<tileset> D_OutDoor.png 512 512 32 <tileset> D_OutDoor.png 512 512 32
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 82 94 0 0 82 94 0 0 1 1 82 94 1 1 82 94 1 1
0 0 83 95 0 0 83 95 0 0 1 1 83 95 1 1 83 95 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 153 0 0 0 0 153 0 0 1 1 153 1 1 1 1 153 1 1
0 0 0 153 153 153 153 0 0 0 1 1 1 153 153 153 153 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1

View File

@ -1,12 +1,12 @@
<tileset> A2_Ground.png 512 384 32 <tileset> A2_Ground.png 512 384 32
<tileset> D_OutDoor.png 512 512 32 <tileset> D_OutDoor.png 512 512 32
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 82 94 0 0 82 94 0 0 1 1 82 94 1 1 82 94 1 1
0 0 83 95 0 0 83 95 0 0 1 1 83 95 1 1 83 95 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 153 0 0 0 0 153 0 0 1 1 153 1 1 1 1 153 1 1
0 0 0 153 153 153 153 0 0 0 1 1 1 153 153 153 153 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1

View File

@ -1,12 +1,12 @@
<tileset> A2_Ground.png 512 384 32 <tileset> A2_Ground.png 512 384 32
<tileset> D_OutDoor.png 512 512 32 <tileset> D_OutDoor.png 512 512 32
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 82 94 0 0 82 94 0 0 1 1 82 94 1 1 82 94 1 1
0 0 83 95 0 0 83 95 0 0 1 1 83 95 1 1 83 95 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 153 0 0 0 0 153 0 0 1 1 153 1 1 1 1 153 1 1
0 0 0 153 153 153 153 0 0 0 1 1 1 153 153 153 153 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1

View File

@ -1,12 +1,12 @@
<tileset> A2_Ground.png 512 384 32 <tileset> A2_Ground.png 512 384 32
<tileset> D_OutDoor.png 512 512 32 <tileset> D_OutDoor.png 512 512 32
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 82 94 0 0 82 94 0 0 1 1 82 94 1 1 82 94 1 1
0 0 83 95 0 0 83 95 0 0 1 1 83 95 1 1 83 95 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 153 0 0 0 0 153 0 0 1 1 153 1 1 1 1 153 1 1
0 0 153 153 153 153 153 0 0 0 1 1 153 153 153 153 153 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1