Pong Paddle collision not working

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; }

Tagged:

Answers

Sign In or Register to comment.