-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapData.pde
109 lines (87 loc) · 3.81 KB
/
MapData.pde
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//1 rectangle, 2 right angled triangle going up right
class MapData{
List<int[][]> visualValues = new ArrayList();
HashMap<Integer, TileMap> tileMaps = new HashMap();
int[][] colliderValues;
String tileSetName = "";
int layers = 0;
int xLength;
int yLength;
int tileWidth;
int tileHeight;
int xMargin;
int yMargin;
int tileSetXLength;
int tileSetYLength;
MapData(String mapName){
switch (mapName){
case "Level 1" : tileSetName = "Jungle_terrainwater.png";
layers = 3;
xLength = 200;
yLength = 100;
tileWidth = tileHeight = 32;
xMargin = yMargin = 0;
tileSetXLength = 28;
tileSetYLength = 15;
break;
}
for (int i = 0; i < layers; i++)
visualValues.add(getMapData("assets/Maps/visuals/" + mapName + "_" + i + ".csv", xLength, yLength));
colliderValues = getMapData("assets/Maps/colliders/" + mapName + ".csv", xLength, yLength);
}
TileMap loadTileMap(int mapLayer, int _layer, int _tileWidth, int _tileHeight, Camera _camera){
if (!tileMaps.containsKey(mapLayer))
tileMaps.put(mapLayer, new TileMap(this, mapLayer, _layer, _tileWidth, _tileHeight, _camera));
return tileMaps.get(mapLayer);
}
void loadColliderMap(TileMap tileMap){
for (int y = 0; y < yLength; y++){
for (int x = 0; x < xLength; x++){
int colliderValue = colliderValues[y][x];
if (colliderValue > 0)
addTileCollider(tileMap.tiles[x][y], tileMap.tileWidth, tileMap.tileHeight, colliderValue);
}
}
}
private void addTileCollider(Tile colliderHost, int currentColliderWidth, int tileHeight, int currentColliderType){
TileCollider t = null;
if (currentColliderType == 1)
t = new SquareTileCollider(colliderHost, currentColliderWidth, tileHeight);
else if (currentColliderType == 2){
t = new TriangleTileCollider(colliderHost, currentColliderWidth, tileHeight, new PVector(0, 0), new PVector(tileWidth, tileHeight), new PVector(tileWidth, 0));
}
else if (currentColliderType == 5){
t = new TriangleTileCollider(colliderHost, currentColliderWidth, tileHeight, new PVector(0, tileHeight), new PVector(tileWidth, 0), new PVector(0, 0));
}
else if (currentColliderType == 6){
t = new TriangleTileCollider(colliderHost, currentColliderWidth, tileHeight, new PVector(0, 0), new PVector(tileWidth, tileHeight * 0.5f), new PVector(tileWidth, tileHeight));
t.setTag("SmoothUpSlope");
}
else if (currentColliderType == 7){
t = new TriangleTileCollider(colliderHost, currentColliderWidth, tileHeight, new PVector(0, tileHeight), new PVector(tileWidth, tileHeight), new PVector(0, tileHeight * 0.5f));
t.setTag("SmoothUpSlope");
}
else if (currentColliderType == 8){
t = new TriangleTileCollider(colliderHost, currentColliderWidth, tileHeight, new PVector(tileWidth, 0), new PVector(0, tileHeight * 0.5f), new PVector(0, tileHeight));
t.setTag("SmoothUpSlope");
}
else if (currentColliderType == 9){
t = new TriangleTileCollider(colliderHost, currentColliderWidth, tileHeight, new PVector(tileWidth, tileHeight), new PVector(0, tileHeight), new PVector(tileWidth, tileHeight * 0.5f));
t.setTag("SmoothUpSlope");
}
/*if (t != null)
t.toggleColliderDisplay(camera, 8, true);*/
}
int[][] getMapData(String mapFilePath, int xLength, int yLength){
String[] lines = loadStrings(mapFilePath);
int[][] result = new int[yLength][xLength];
for (int i = 0 ; i < lines.length; i++) {
String[] items = lines[i].split(",");
int len = items.length;
for (int j = 0; j < len; j++){
result[i][j] = Integer.parseInt(items[j]);
}
}
return result;
}
}