Android用の簡単なブレイクアウトゲームを作りましたが、ボールがバー(パドル)に到達したときにいくつかの問題があります。ボール、バーはビットマップです。x、y はボールの位置、bx と by はバー (パドル) の位置です。speedX と speedY はボールの速度です。これはあまり良い解決策ではありません。コードはどこで変更できますか?
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);