-
Notifications
You must be signed in to change notification settings - Fork 0
/
Peg.pde
65 lines (59 loc) · 1.12 KB
/
Peg.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
class Peg
{
float xpos;
float ypos;
float diam;
int rowMax;//Please don't change :) thanks.
Peg left;//initializes the next pegs
Peg right;
float slope;
Peg(float x,float y, int row)
{
xpos=x;
ypos=y;
diam=10;
rowMax=6;
slope=(diam*5)/(height/10);
if(row<rowMax)
{
//check if theres already a peg there
left = new Peg(x-diam*5,y+height/10,row+1);
right = new Peg(x+diam*5,y+height/10,row+1);
}
}
void display()
{
fill(0,0,100);
ellipse(xpos,ypos,diam,diam);
if(left!=null && right!=null)
{
left.display();
right.display();
}
}
void ballCheck(Ball ball)
{
if (ball.ypos+ball.diam/2 == ypos-diam/2) //below
{
if(int(random(0,2))==0)//randomization function
{
ball.xChange=(-1)*slope;
}
else
{
ball.xChange=slope;
}
}
else//interaction with the lower pegs
{
if (ball.xChange<0 && left!=null)
{
left.ballCheck(ball);
}
else if( ball.xChange>0 && right!=null)
{
right.ballCheck(ball);
}
}
}
}