We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So I just started processing... I'm working on a pong game but the paddle on the left doesn't make the ball bounce o.0 Can someone help?
float ballX=300; float ballY=100; float speedX=6; float speedY=6; float padY=200; float padX=970; float padH=200; float pad2X=10; float pad2Y=200; float pad2H=200; float padSpeed=35; void setup() { size(1000,600); } void keyPressed() { if (key==CODED) { if (keyCode==UP) { padY=padY-padSpeed; } if (keyCode==DOWN) { padY=padY+padSpeed; } } if (key=='w') { pad2Y=pad2Y-padSpeed; } if (key=='s') { pad2Y=pad2Y+padSpeed; } } void draw() { background(255); fill(#00BC24); rect(500,0,width/2,height); if (ballX<width/2) fill(#00BC24); else fill(255); ellipse(ballX,ballY,40,40); //Ball fill(255); rect(padX,padY,20,padH); fill(#00BC24); rect(pad2X,pad2Y,20,pad2H);
if ((ballX>padX-10) && (ballY>=padY) && (ballY<=padY+padH)) speedX=-speedX; if ((ballX<pad2X+10) && (ballY<=pad2Y) && (ballY<=pad2Y+pad2H)) speedX=-speedX; if (ballY>height) speedY=-speedY; if (ballY<0) speedY=-speedY; ballX=ballX+speedX; ballY=ballY+speedY; }
Answers
Please edit your post so that people can read, so that they can copy-paste to test, so that they can help you.
Edit your post with the gear icon. Highight your code and press Ctrl-o. Details here:
https://forum.processing.org/two/discussion/15473/readme-how-to-format-code-and-text
Look at the two conditions for the two paddles. Notice anything wrong about them?
The X part should be different because the paddles are on opposite sides of the screen but the y part should be pretty similar...