Im am working on this project and can’t seem to understand how i can make the ball react to the second paddle aswell as the first. Have in mind that im a beginner and don’t understand a lot of code.
Translation:
Fart = Speed
Hoyde = Height
Bredde = Width
rekkert = paddle
float ballX;
float ballY;
float ballXFart = 2;
float ballYFart = 2;
float ballRadius = 9;
float ballDiameter = ballRadius * 2;
float rekkertHoyde = 66;
float rekkertBredde = 5;
float rekkert1X = 20;
float rekkert1Y = 100;
float rekkert2X = 580;
float rekkert2Y = 100;
void setup() {
size(600, 300);
ballX = width / 2;
ballY = height / 2;
}
void draw() {
if (keyPressed) {
if (keyCode == UP) {
rekkert1Y = rekkert1Y - 2;
}
if (keyCode == DOWN) {
rekkert1Y = rekkert1Y + 2;
}
}
if (keyPressed) {
if (key == ‘w’) {
rekkert2Y = rekkert2Y - 2;
}
if (key == ‘s’) {
rekkert2Y = rekkert2Y + 2;
}
}
if (ballX-ballRadius < rekkert1X + rekkertBredde && ballX + ballRadius > rekkert1X) {
if (ballY < rekkert1Y + rekkertHoyde && ballY > rekkert1Y) {
ballX = ballX + rekkertBredde;
ballXFart = -ballXFart;
}
}
ballX = ballX + ballXFart;
ballY = ballY + ballYFart;
if (ballX < ballRadius) {
}
if (ballX > width - ballRadius) {
ballXFart = -ballXFart;
}
if (ballY < ballRadius) {
ballYFart = -ballYFart;
}
if (ballY > height - ballRadius) {
ballYFart = -ballYFart;
}
background(0);
rect(rekkert1X, rekkert1Y, rekkertBredde, rekkertHoyde);
rect(rekkert2X, rekkert2Y, rekkertBredde, rekkertHoyde);
ellipse(ballX, ballY, ballDiameter, ballDiameter);
}
If you see the solution please tell me, thank you.