Evening
I’m trying to tidy up and make my first attempted game actually fun. In doing so I’ve found myself delving into vectors, which are fairly new to me so bear with me, and I’m having a few problems. I think I have a ball bouncing off of a rectangle successfully.
My problem occurs when the ball collides with two, or more, rectangles at the same time. Usually this happens when the ball hits between two rectangles which is a fairly frequent occurrence as I’m dealing with a grid of blocks in a Breakout clone. I’ll try a diagram to make what I mean clearer:
| | |
| | |
^
Ball hits here.
You can see my code for this here https://github.com/danieldean/Bounce/blob/master/src/me/danieldean/demo/bounce/Ball.java, see methods ‘colliding’ and ‘bounce’. There is also a demo I’ve compiled if you don’t want to do it to try for yourself https://github.com/danieldean/Bounce/releases. Drag the ball by holding the mouse to get it to collide between the two rectangles.
If anyone has any suggestions I’d be grateful. So far my consideration is to combine the blocks into one rectangle and collide with that on the fly which seems wasteful and doesn’t solve when a collision occurs with an ‘L’ of blocks. I work out what blocks to collide with in the actual game by grid positioning.
Thanks