-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTilemap.java
70 lines (69 loc) · 2.26 KB
/
Tilemap.java
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
public class Tilemap {
public final int[][] tileids;
public final int[][] tiledata;
public final String theme;
public Tilemap(int[][] tileids, int[][] tiledata){
this.tileids = tileids;
this.tiledata = tiledata;
this.theme="Waterfall";
}
public Tilemap(int width, int height){
tileids = new int[height][width];
tiledata = new int[height][width];
this.theme="Waterfall";
}
public Tilemap(int width, int height, int id, int data){
tileids = new int[height][width];
tiledata = new int[height][width];
for(int x = 0; x < height; x++){
for(int y = 0; y < width; y++){
tileids[x][y] = id;
tiledata[x][y] = data;
}
}
this.theme="Waterfall";
}
public Tilemap(int[][] tileids, int[][] tiledata, String theme){
this.tileids = tileids;
this.tiledata = tiledata;
this.theme = theme;
}
public Tilemap(int width, int height, String theme){
tileids = new int[height][width];
tiledata = new int[height][width];
this.theme=theme;
}
public Tilemap(int width, int height, int id, int data, String theme){
tileids = new int[height][width];
tiledata = new int[height][width];
for(int x = 0; x < height; x++){
for(int y = 0; y < width; y++){
tileids[x][y] = id;
tiledata[x][y] = data;
}
}
this.theme=theme;
}
public boolean checkBit(int x, int y, int digit){
return (tiledata[x][y] & (1 << digit)) != 0;
}
public boolean isWalkable(int x, int y){
return checkBit(x, y, 0);
}
public boolean isInteractable(int x, int y){
return checkBit(x, y, 1);
}
public int[][] getAroundType(int x, int y){
int[][] ret = new int[3][3];
for(int ox = -1; ox < 2; ox++){
for(int oy = -1; oy < 2; oy++){
if(x+ox >= 0 && x+ox < tileids.length && y+oy >= 0 && y+oy < tileids[0].length){
ret[ox+1][oy+1] = tileids[x+ox][y+oy]!=0?(tileids[x+ox][y+oy]-1)%2+1:0;
}else{
ret[ox+1][oy+1] = 0;
}
}
}
return ret;
}
}