-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectCollider.pde
More file actions
52 lines (39 loc) · 1.31 KB
/
RectCollider.pde
File metadata and controls
52 lines (39 loc) · 1.31 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
class RectCollider implements Collider {
// ----- Fields
private final Vec2Int position;
private final Vec2Int size;
// ----- Constructors
public RectCollider(Vec2Int position, Vec2Int size) {
this.position = position;
this.size = size;
}
// ----- Methods
@Override
public Vec2Int getPosition() {
return position;
}
@Override
public Vec2Int getSize() {
return size;
}
@Override
public void render() {
fill(0, 0, 255);
noStroke();
rectMode(CENTER);
rect(0, 0, size.x, size.y);
}
@Override
public boolean intersects(Vec2Int point) {
boolean meetsInX = point.x >= position.x - size.x / 2 && point.x <= position.x + size.x / 2;
boolean meetsInY = point.y >= position.y - size.y / 2 && point.y <= position.y + size.y / 2;
return meetsInX && meetsInY;
}
public boolean intersects(RectCollider other) {
boolean meetsInX = this.position.x + this.size.x / 2 >= other.position.x - other.size.x / 2
&& this.position.x - this.size.x / 2 <= other.position.x + other.size.x / 2;
boolean meetsInY = this.position.y + this.size.y / 2 >= other.position.y - other.size.y / 2
&& this.position.y - this.size.y / 2 <= other.position.y + other.size.y / 2;
return meetsInX && meetsInY;
}
}