Game is here: http://www.javadaemon.com/games/breakout
However, that control scheme is hard. I want the balls new direction to reflect where it hit on the bat.
This is how I currently do it, and it does not work one bit.
float degreesPerPixel = (float)180/player.getWidth();
The bat is 80 pixels long, so this should equal 2.25, which is does.
int whereBallHit = (int) ((player.getX()+player.getWidth())-(ball.getX()+(ball.getWidth()/2)));
This bit should reflect the pixel coordinate of where the center of the ball hit the bat. It is counted from left to right because of the way degrees work. They start with 0 on the left, working over at 180 in the right.
This bit also works.
float degreesApplied = degreesPerPixel * whereBallHit;
This bit also works as intended. It is the amount of degrees on the angle the ball should now be flying in.
ball.setXV((float)Math.cos(Math.toRadians(degreesApplied)) * 1.8f);
ball.setYV((float)Math.sin(Math.toRadians(degreesApplied)) * 1.8f);
This bit however, has drawn my attention because of not working. I’m suspecting wrong use of the Math functions. The ball does not make a lot of air after this bit. How can I fix this? Also, how would I set the generel speed of the ball?
Thanks guys