aspose file tools*
The moose likes Game Development and the fly likes BreakOut Java Bug Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "BreakOut Java Bug" Watch "BreakOut Java Bug" New topic
Author

BreakOut Java Bug

Phil Wood
Greenhorn

Joined: Aug 12, 2011
Posts: 5
Here is my Code for a java breakout game below:



My problem is that I have a bug where when I move the paddle towards the ball as it is passing it appears two of my collision points are within the paddle and therefore the ball keeps repeatedly bouncing up and down within the paddle.
Is there anyway i can check that this is not occuring, or is there another more simply solution.

thanks
Nathan Lane
Greenhorn

Joined: Aug 12, 2011
Posts: 5

First off -- nice game. I really like it. Very well done. Second, I played it a few times and I think that I understand what your saying:
when I move the paddle towards the ball as it is passing it appears two of my collision points are within the paddle and therefore the ball keeps repeatedly bouncing up and down within the paddle.

however I don't think that I was able to reproduce the issue at all. I tried moving the paddle left or right into the ball as it was passing the paddle -- is this when you're saying you're seeing this problem occur? It seems like a difficult issue to reproduce. Most of the time I guess I was too slow, and the ball passed by, and the other half of the time I think I was just barely too fast and caught the ball before it started by me -- there seems to be a rectangle around the ball and so maybe the collision doesn't seem as natural as I would have expected. Do you have any more detail on what exactly is happening and how to reproduce it?

As an aside to my blabbering, there are several more complicated collision algorithms around. I can search some up if you'd like, but I'll just be using Google probably. So let me know.
Phil Wood
Greenhorn

Joined: Aug 12, 2011
Posts: 5
Ok so the best way I've found to replicate this is to change the

to BALL_DELAY = 100, I actually think I accidently left it at this speed in my code posted before, apologies. It occurs if you pass the paddle through the center of the ball ass it passes it.

My guess is that as the paddle collides with the ball one collision point flips the vertical velocity (vy) to the negative and this become flipped again by another collision point hitting the paddle.

If you time this right, you can get the ball stuck to the paddle, I have partially solved it, but if the bottom two corners of the collision rectangle around the ball hit the paddle at the same time it becomes glued to the paddle. The same i assume also happens with the top collision points.

Hope this is enough informations, also thanks for your response.

Nathan Lane
Greenhorn

Joined: Aug 12, 2011
Posts: 5

Alright I think what you need to do is ensure that the position of the ball is outside of the bounds of the paddle. Here is an example:


See changes on lines 48-59. Here I check whether the ball's location sits within the bounds of the paddle, and if it does I reposition the ball. Another option would be to set a flag until the ball clears the paddle after it has been set and then reset it. this is a little more work, but it would probably look better (less choppy).
Phil Wood
Greenhorn

Joined: Aug 12, 2011
Posts: 5
Thanks that seems to have sorted the problem out, like you say it is still a little bit jerky at times, but I can live with that for now, still got a few things I want to implement.

One very small issue I have is, Why when I click the mouse to start the game, sometimes it takes three or four clicks before it starts, but on the gameover screen and the win screen, its seems to work every time??
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: BreakOut Java Bug