/
Maze.pde
59 lines (50 loc) · 1.47 KB
/
Maze.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
////////////////////////////////////////////////////////
// DRAWS THE MAZE
// This is where the collison map is set up
// All classes inherit this for movement
////////////////////////////////////////////////////////
class Maze
{
////////////////////////////////////////////////////////
// GLOBAL VARIABLES
////////////////////////////////////////////////////////
// maze variables
PImage visib;
boolean[][] collisionMap;
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// VARIABLES VALUES (CONSTRUCTOR)
////////////////////////////////////////////////////////
Maze()
{
// the collision map must be black and white
PImage collisionImage = loadImage("collision_map.png");
// generate our collision map as an two-dimensional boolean array
// black is false (blocked)
// white is true (clear)
collisionMap = new boolean[collisionImage.width][collisionImage.height];
color black = color(0);
color white = color(255);
// looks through collision map rows
for (int i = 0; i < collisionImage.width; i++)
{
// looks through collision map columns
for (int j = 0; j < collisionImage.height; j++)
{
color c = collisionImage.get(i, j);
if (c == black)
{
collisionMap[i][j] = false;
}
else if (c == white)
{
collisionMap[i][j] = true;
}
else
{
// make sure the only colors are black and white
println("There are colors other than black and white in the collision map!");
}
}}}
////////////////////////////////////////////////////////
}