-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWall.pde
47 lines (43 loc) · 1.48 KB
/
Wall.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
// Wall class. In the form of a rect.
public class Wall {
PVector pos, extents;
ArrayList<Boundary> shape;
public Wall (int x, int y, int xl, int yl) {
pos = new PVector(x, y);
extents = new PVector(xl, yl);
shape = new ArrayList<>();
shape.add(new Boundary(new PVector(x, y), new PVector(x+xl, y))); // tl -> tr
shape.add(new Boundary(new PVector(x+xl, y), new PVector(x+xl, y+yl))); // tr -> br
shape.add(new Boundary(new PVector(x+xl, y+yl), new PVector(x, y+yl))); // br -> bl
shape.add(new Boundary(new PVector(x, y+yl), new PVector(x, y))); // bl -> tl
}
public Wall (PVector _position, PVector _size) {
pos = _position;
extents = _size;
}
public void drawShape(color c) {
fill(c);
rect(pos.x, pos.y, extents.x, extents.y);
}
public boolean isPointInside(PVector p) {
return p.x >= pos.x
&& p.x < pos.x + extents.x
&& p.y >= pos.y
&& p.y < pos.y + extents.y;
}
}
// Boundary class. In the form of a line segment.
public class Boundary {
PVector start, end;
boolean isVertical, isHorizontal, isDiagonal;
public Boundary(PVector start, PVector end) {
this.start = start;
this.end = end;
isVertical = start.x == end.x;
isHorizontal = start.y == end.y;
isDiagonal = !isVertical && !isHorizontal;
}
public void show() {
line(start.x, start.y, end.x, end.y);
}
}