class Ball {
float xPos;
float yPos;
float xSpeed = 2.8;
float ySpeed = 2.2;
int xDirection = 1;
int yDirection = 1;
int rad = 16;
final float speed = 5;
Paddle paddle;
public Ball(Paddle paddle){
paddle = paddle;
// set starting position of the ball, start in center of screen
xPos = width / 2;
yPos = height / 2;
}
public void move() {
// update the ball's position
//xPos += (xSpeed) + (xSpeed * xDirection);
yPos += (ySpeed) + (ySpeed * yDirection);
}
public void draw() {
ellipse(xPos, yPos, rad, rad);
checkBoundaries();
}
public void checkBoundaries() {
if(xPos > width - rad ) {
xSpeed -= 2.2;
}
if(xPos <rad ) {
xSpeed = 2.2;
}
if(yPos > height) {
ySpeed = -2.2*yDirection;
println("yDirection: " + yDirection + "yPos: " + yPos);
}
if(yPos<rad) {
ySpeed = 2.2*yDirection;
println("yDirection: " + yDirection + "yPos: " + yPos);
}
}
public void checkCollision() {
}
}