-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComputer.pde
52 lines (46 loc) · 1.17 KB
/
Computer.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 Computer {
int xpos;
float ypos;
float old;
float computerSpeed = 1.0;
color white = color(255);
int lives;
Computer(int screen_x) {
xpos=screen_x;
ypos=RESY/2;
lives = 3;
}
void move(Ball tBall) {
old = ypos;
if (tBall.dx != 0) {
if (ypos+0.5*HEIGHT-computerSpeed>tBall.y) ypos -= computerSpeed;
else if (ypos+0.5*HEIGHT>tBall.y) ypos = tBall.y-0.5*HEIGHT;
else if (ypos+0.5*HEIGHT+computerSpeed<tBall.y) ypos += computerSpeed;
else if (ypos+0.5*HEIGHT<tBall.y) ypos = tBall.y-0.5*HEIGHT;
}
}
void reset(float yBall) {
ypos = yBall-0.5*HEIGHT;
}
void draw() {
fill(white);
rect(xpos, ypos, WIDTH, HEIGHT);
textFont(font, 50);
text(lives, 3*RESX/4, 75);
if (lives == 0) {
textFont(font, 50);
textAlign(CENTER);
text("Congratulations", RESX/2, 150);
} else {
computerSpeed = (4-lives)*(1+0.1*(3-lives));
textFont(font, 20);
text(("Computer Speed: " + round(computerSpeed)), 3*RESX/4, RESY-75);
}
}
void compLife() {
lives -= 1;
if (lives == 0) {
bgcolor = (#00FF00);
}
}
}