-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlock.pde
66 lines (61 loc) · 1.6 KB
/
Block.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
60
61
62
63
64
65
66
public class Block{
private float x, y, w, h;
private int numBlocks; //CHANGED FROM EPISODE 3
private boolean status;
private int r, g, b;
public Block(){
x = 0;
numBlocks = 8;
y = 0;
w = width / numBlocks;
h = 30;
}
public Block(int col, int row, int theNumBlocks){
numBlocks = theNumBlocks;
w = width / numBlocks;
h = 30;
x = w * col;
y = h * row;
r = (int)random(0, 256);
g = (int)random(0, 256);
b = (int)random(0, 256);
status = true;
}
public void display(){
fill(r,g,b);
if(status){
fill(b,r,g);
rect(x+2,y,w-17,h-17,2);
fill(g,b,r);
arc(x, y, 28, 28, PI, TWO_PI);
}
}
public void checkBall(Ball ball){
if(status){
//Bottom
if(ball.x > x && ball.x < x+w && ball.y < (y+h+ball.d/2)&& ball.y>y+h){
ball.Vy*=-1;
status=false;
score++;
}
//Top
if(ball.x > x && ball.x < x+w && ball.y > y-ball.d/2 && ball.y < y){
ball.Vy*=-1;
status=false;
score++;
}
//Left
if(ball.x > x - ball.d/2 && ball.y > y && ball.y < y+h && ball.x < x){
ball.Vx*=-1;
status=false;
score++;
}
//Right
if(ball.x > x+w && ball.y > y && ball.y < y+h && ball.x<x+w+ball.d/2){
ball.Vx*=-1;
status=false;
score++;
}
}
}
}