-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPUGenius.java
More file actions
50 lines (37 loc) · 1.79 KB
/
CPUGenius.java
File metadata and controls
50 lines (37 loc) · 1.79 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
import java.awt.Color;
public class CPUGenius extends CPUChallenging {
//CPU Challenging Paddle attributes
public static final double CPU_GENIUS_PADDLE_LENGTH = 25.0;
public static final double CPU_GENIUS_PADDLE_SPEED = 3.0;
public static final Color CPU_GENIUS_PADDLE_COLOR = Color.pink;
//CONSTRUCTORS
public CPUGenius(){
super(CPU_GENIUS_PADDLE_LENGTH, CPU_GENIUS_PADDLE_SPEED, CPU_GENIUS_PADDLE_COLOR);
}
public CPUGenius(double length, double speed, Color color){
super(length, speed, color);
}
//Determines how the paddle moves when the ball is moving left
protected int reactBallMovingLeft(double bX, double bY, double bXVel, double bYVel){
//moves the same way as CPUChallenging
return super.reactBallMovingLeft(bX, bY, bXVel, bYVel);
}
protected int reactBallMovingRight(double bX, double bY, double bXVel, double bYVel){
double bounceX = TrigHelpers.calcNextWallBounceX(bX, bY, bXVel, bYVel, getWindowHeight());
//if the calculated bounceX is greater the width of the window(i.e x of paddle), then the ball will not bounce
if (bounceX > this.getX())
return super.reactBallMovingRight(bX, bY, bXVel, bYVel);
//looping until a value for bounceX > PaddleX (i.e the ball reaches the volleying area) is found
while (bounceX <= this.getX()){
bX = bounceX;
if(bYVel < 0){
bY = 0; bYVel *= -1;
}
else {
bY = this.getWindowHeight(); bYVel *= -1;
}
bounceX = TrigHelpers.calcNextWallBounceX(bX, bY, bXVel, bYVel, getWindowHeight());
}
return super.reactBallMovingRight(bX, bY, bXVel, bYVel);
}
}