0

我为Android制作了一个简单的突破游戏,当球到达横杆(桨)时我遇到了一些问题。ball、bar 是位图。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); 
4

0 回答 0