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