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
.
精彩评论