-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTileGrid.java
More file actions
113 lines (99 loc) · 2.79 KB
/
TileGrid.java
File metadata and controls
113 lines (99 loc) · 2.79 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package data;
import static helpers.Artist.*;
import java.util.Map;
public class TileGrid {
public Tile[][] tilemap;
public Tile[] path;
public Tile spawnPoint;
public int pathCount = 0;
public int locPathCount = 0;
public TileGrid() {
tilemap = new Tile[20][15];
for (int i = 0; i < tilemap.length; i++){
for(int j = 0; j < tilemap[i].length; j++){
tilemap[i][j] = new Tile(i * 64, j * 64, 64, 64, TileType.Path);
}
}
}
public TileGrid(int[][] newtilemap){
int tilemapLength = 0;
tilemap = new Tile[20][15];
int pathCount = 0;
int n = 0;
for (int i = 0; i < tilemap.length; i++){
for(int j = 0; j < tilemap[i].length; j++){
if(newtilemap[j][i]>=1){
n++;
}
}
}
path = new Tile[n];
for (int i = 0; i < tilemap.length; i++){
for(int j = 0; j < tilemap[i].length; j++){
if(newtilemap[j][i] == 0){
tilemap[i][j] = new Tile(i * 64, j * 64, 64, 64, TileType.Water);
System.out.println(tilemap[i][j]);
}
else if(newtilemap[j][i] >= 1){
tilemap[i][j] = new Tile(i * 64, j * 64, 64, 64, TileType.Path);
tilemap[i][j].setIdNum(newtilemap[j][i]);
System.out.println(tilemap[i][j]);
if(tilemapLength == 0){
spawnPoint = tilemap[i][j];
}
path[pathCount]= tilemap[i][j];
path[pathCount] = tilemap[i][j];
pathCount++;
tilemapLength++;
}
}
}
sortPath();
print();
}
public void Draw(){
for (int i = 0; i < tilemap.length; i++){
for(int j = 0; j < tilemap[i].length; j++){
if(tilemap[i][j] != null){
Tile t = tilemap[i][j];
DrawQuadTex(t.getTexture(), t.getX(), t.getY(), t.getWidth(), t.getHight());
}else{
System.out.println(tilemap[i][j]);
}
}
}
}
public void sortPath(){
Tile temp;
for(int i=0; i < path.length; i++){
for(int j=1; j < path.length; j++){
if(path[j-1].idNum > path[j].idNum){
//swap elements
temp = path[j-1];
path[j-1] = path[j];
path[j] = temp;
}
}
}
}
public void print(){
for(int i=0; i < path.length; i++){
System.out.println(path[i].getIdNum());
}
}
public void SetTile(int xCord, int yCord, TileType type){
tilemap[xCord][yCord] = new Tile(xCord * 64, yCord * 64, 64, 64, type);
}
public Tile GetTile(int xCord, int yCord){
return tilemap[xCord][yCord];
}
public Tile[][] getTileMap(){
return tilemap;
}
public Tile[] getPath(){
return path;
}
public Tile getSpawnPoint(){
return spawnPoint;
}
}