Help with Java Pong Game

Soldato
Joined
26 Aug 2005
Posts
6,901
Location
London
Hi guys,

Am abit stuck with some logic. Basically if the ball hits the walls it will change direction obviously. However, I can't get get the ball to change direction when the ball hits the paddle.
Code:
if(inPlay)
{
		if( (x==0) || (x== getWidth() - size) || (x>box.getWidth()+batWidth && x<box.getWidth()+batWidth)  )
		{
			xd *= -1;
		}
		if( (y==20) || (y == getHeight() - size) ||  (y>box.getHeight()+batWidth && y<box.getHeight()+batWidth)    )
		{
			yd *= -1;
		}
			x+= xd;
			y += yd;
}
 
Something like this? I've tried it, but it doesn't like..

Code:
((x > box.getWidth() - batWidth - getWidth()/9) && (x < box.getWidth() - batWidth))

((y > box.getHeight() - batHeight - getHeight()/9) && (y < box.getHeight() - getHeight()/9)
 
Back
Top Bottom