-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTilemap.java
More file actions
86 lines (78 loc) · 2.7 KB
/
Copy pathTilemap.java
File metadata and controls
86 lines (78 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import java.util.*;
import java.io.*;
public class Tilemap implements Position, Item {
private int x;
private int y;
private String[][] blocks;
private final String[] blockFiles;
private final int[] blockBehaviors;
public boolean delete;
public Tilemap(int initialX, int initialY, String[][] blcs) throws FileNotFoundException {
ArrayList<String> albf = new ArrayList<String>();
ArrayList<Integer> albb = new ArrayList<Integer>();
Scanner scn = new Scanner(new File("blocks.dat"));
while (scn.hasNextLine()) {
int id = scn.nextInt();
//albb.ensureCapacity(id);
//albf.ensureCapacity(id);
extendIntArrList(albb, id);
extendStrArrList(albf, id);
albb.set(id, scn.nextInt());
albf.set(id, scn.next());
}
blockFiles = new String[albf.size()];
for (int i = 0; i < albf.size(); i++) {
if (albf.get(i) != "") {
blockFiles[i] = albf.get(i);
}
else {
blockFiles[i] = "null.png";
}
}
blockBehaviors = new int[albb.size()];
for (int i = 0; i < albb.size(); i++) {
blockBehaviors[i] = albb.get(i);
}
x = initialX;
y = initialY;
blocks = blcs;
delete = false;
}
public int[] getCoords() {
return new int[] {x, y};
}
public String getType() {
return "Tilemap";
}
public SpritePackage[] getSprites() {
ArrayList<SpritePackage> sprts = new ArrayList<SpritePackage>();
for (int x = 0; x < blocks.length; x++) {
for (int y = 0; y < blocks[x].length; y++) {
sprts.add(new SpritePackage(blockFiles[Integer.parseInt(blocks[x][y].substring(0, 4))], this.x + x * 32 + 16 - blocks.length * 16, this.y + y * 32 + 16 - blocks[0].length * 16));
}
}
return sprts.toArray(new SpritePackage[0]);
}
public Hitbox[] getHitboxes() {
ArrayList<Hitbox> hboxes = new ArrayList<Hitbox>();
for (int x = 0; x < blocks.length; x++) {
for (int y = 0; y < blocks[x].length; y++) {
hboxes.add(new Hitbox(blockBehaviors[Integer.parseInt(blocks[x][y].substring(0, 4))], this.x + x * 32 + 16 - blocks.length * 16, this.y + y * 32 + 16 - blocks[0].length * 16, 32, 32));
}
}
return hboxes.toArray(new Hitbox[0]);
}
public boolean shouldDelete() {
return delete;
}
private void extendIntArrList(ArrayList<Integer> arrList, int length) {
while (arrList.size() - 1< length) {
arrList.add(0);
}
}
private void extendStrArrList(ArrayList<String> arrList, int length) {
while (arrList.size() - 1 < length) {
arrList.add("");
}
}
}