# How can i make it a 2 player game

**URL:** <https://discourse.processing.org/t/how-can-i-make-it-a-2-player-game/18418>\
**Category:** Coding Questions\
**Created:** [March 5, 2020, 1:59pm UTC](https://discourse.processing.org/t/how-can-i-make-it-a-2-player-game/18418 "2020-03-05T13:59:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KristianChannel](https://avatars.discourse-cdn.com/v4/letter/k/71c47a/32.png) [@KristianChannel](https://discourse.processing.org/u/KristianChannel)\
**Post date:** [March 5, 2020, 1:59pm UTC](https://discourse.processing.org/t/how-can-i-make-it-a-2-player-game/18418/1 "2020-03-05T13:59:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 5, 2020, 2:35pm UTC](https://discourse.processing.org/t/how-can-i-make-it-a-2-player-game/18418/2 "2020-03-05T14:35:45Z")

</div>

> [@KristianChannel](#):
>
> if (ballX-ballRadius \< rekkert1X + rekkertBredde && ballX + ballRadius \> rekkert1X) {  
> if (ballY \< rekkert1Y + rekkertHoyde && ballY \> rekkert1Y) {

Here you check against rekkert1 - you want to copy the entire section and change it for rekkert2

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [March 7, 2020, 11:48pm UTC](https://discourse.processing.org/t/how-can-i-make-it-a-2-player-game/18418/3 "2020-03-07T23:48:10Z")

</div>

@KristianChannel – Welcome to the forum! When you post, please help us help you by [formatting your code](https://discourse.processing.org/faq#format-your-code) with the \</\> button or by adding ``` above and below. You can still edit your top post to fix it.
