开发者

cant get bricks to show and ball to hit the bat

I am unable to get the following code to work i i understand that there is a problem in the checkCollision method but i am unable to 开发者_运维技巧determine what, or whether its correct in the first place.

i appriciate any help

EDIT: ty for the formatting

currently all the program does atm is spawn a ball at a random position and just falls downwards till it disappears at the bottom of the window what i intend for the program to do is once the ball hits the bat controlled by the mouse it bounces back up and hit blocks which will get destroyed


Your method checkCollision() will not be called at all. See the following lines from your actionlistener (discarded some lines....):

if (event.getSource()==btnGo){
    if (counter >0) {
        ....
        if (event.getSource()==timer1){
            ....
            checkCollision();
        }
        else
            btnGo.setEnabled(false);
    }
}

Maybe one of the blocks is not closed correctly but in the current version the method is only called if event.getSource() is at the same time btnGo and timer1 which is obviously not possible.

Second it seems strange that you compare your bat-position inside checkCollisions() (batY >= paper.getHeight()). I suppose you meant something like ballY >= batY.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜