-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rectangle.pde
52 lines (46 loc) · 1.33 KB
/
Rectangle.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
class Rectangle{
public PVector loc;
private int w;
private int h;
public Rectangle(PVector loc, int w, int h){
this.loc = loc;
this.w = w;
this.h = h;
}
public void show(){
fill(0);
ellipse(this.loc.x, this.loc.y, this.w / 2, this.w / 2);
}
public void setW(int w){this.w = w;}
public void setH(int h){this.h = h;}
public int getW(){return this.w;}
public int getH(){return this.h;}
public boolean collides(Rectangle other){
if(other.loc.x > this.loc.x +this.w){
//println("Enemy to the right");
return false;
}
if(other.loc.x + other.getW() < this.loc.x){
//println("Enemy to the left");
return false;
}
if(other.loc.y > this.loc.y + this.h){
//println("Enemy below");
return false;
}
if(other.loc.y + other.getH()< this.loc.y){
//println("Enemy below");
return false;
}
return true;
}
private boolean isOutOfBounds(){
//Acounting only for top left point.
if(this.loc.x >= Constants.width || this.loc.x <= 0
||this.loc.y >= Constants.height || this.loc.y <= 0){
//println("Out of bounds");
return true;
}
return false;
}
}