I made a simple breakout game for Android, and I have some problems when the ball reaches the bar (paddle). ball, bar are bitmaps. x,y are the positions of the ball, bx and by are the positions of the bar (paddle). speedX and speedY are the speed of the ball. this isn't a very nice solution. Where can I change the code?
if (y + ball.getHeight() >= c.getHeight()
- (10 + bar.getHeight())
&& (x + ball.getWidth() / 2) >= bx - bar.getWidth() / 2
&& (x + ball.getWidth() / 2) <= bx + bar.getWidth() / 2) {
mp.start();
xdirection = (((x + ball.getWidth()) / 2) - ((bx + bar
.getWidth())) / 2) / (bar.getWidth() / 2);
speedY = -speedY;
speedX = (speedX) * Math.abs(xdirection);