I am trying to create breakout game like this below.
http://www.2dplay.com/break-out/break-out-play.htm
I like how when balls bounces on paddle you have control over where it is goings. i need help creating some thing like this
//this is my code for when ball touch the paddle(player). i have divide the paddle in to two pices. than i am check if ball is touching the paddle on left or right side. than i am checking to see which way the ball dir is. than move the ball different dir.
//bx,by,bw,bh are ball x,y postion, width, height.
//x,y, width, height are paddle variables
public void playerBallCollision(Ball b)
{
double bx = b.getX();
double by = b.getY();
double bw = b.getRadius() * 2;
double bh = b.getRadius() * 2;
if(this.getBounds().intersects(b.getBounds())) //ball is touching the paddle
{
b.setDy(-b.getDy()); //change ball dy oppiste side
if(by+bh >= y && by <= y) //ball is touching paddle from top
{
if(bx < (x+width/2)) //ball is touch paddle from left side
{
if(b.getDx() <= 0) //ball is moving left
b.setDx(b.getDx()); //move ball right
else //ball is moving right
b.setDx(-b.getDx()); //move ball left
}
if(bx > (x+width/2)) //ball is touching paddle from right side
{
if(b.getDx() <= 0) //ball is moving left
b.setDx(-b.getDx());
else //ball is moving right
b.setDx(b.getDx());
}
}
}//End collision
}
so this code just move the ball left or right same angle. i want to make the different angles. so should i add more if statment? or just this be done in looop?