forked from phu004/JavaRTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrid.java
More file actions
74 lines (53 loc) · 1.53 KB
/
Copy pathgrid.java
File metadata and controls
74 lines (53 loc) · 1.53 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
package core;
import entity.*;
public class grid {
public int size;
public solidObject[][] tiles; //a list of colliable objects, used by local path finding
public boolean[] previousObstacleMap, currentObstacleMap; //a boolean representation of the collideble objects, used by A star
public grid(int size){
this.size = size;
tiles = new solidObject[size * size][5];
previousObstacleMap = new boolean[size * size];
currentObstacleMap = new boolean[size * size];
for(int i = 0; i < size * size; i++){
previousObstacleMap[i] = true;
currentObstacleMap[i] = true;
}
}
public void update(){
int l = size * size;
for(int i = 0; i < l; i++){
previousObstacleMap[i] = currentObstacleMap[i];
currentObstacleMap[i] = true;
}
for(int i = 0; i < size; i++){
currentObstacleMap[i] = false;
currentObstacleMap[l - 1 - i] = false;
currentObstacleMap[i * 128] = false;
currentObstacleMap[(i+1) * 128 - 1] = false;
}
}
public void reset() {
for(int i = 0; i < size * size; i++){
previousObstacleMap[i] = true;
currentObstacleMap[i] = true;
for(int j = 0; j < 5; j++) {
if(tiles[i][j] != null && tiles[i][j].teamNo != -1)
tiles[i][j] = null;
}
}
}
public void draw(){
int w = mainThread.screen_width;
int pos = 2 + 20 * w;
boolean tile;
int[] screen = mainThread.screen2;
for(int i = 0; i < 128; i++){
for(int j = 0; j < 128; j++){
tile = previousObstacleMap[j + i*128];
if(!tile)
screen[pos + j + i*w] = 0;
}
}
}
}