Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / BrickBreaker Collision Help

Author
Message
MBPSOFTLLC
11
Years of Service
User Offline
Joined: 15th May 2012
Location:
Posted: 16th May 2012 02:01
I have a brick breaker clone working fairly well. The collision between the ball and the blocks does not work all of the time. I needed to figure out if the ball was hitting a left, right, top, or bottom side so I could react accordingly. So I came up with this function:



Now in my game loop I test like so:


It works as expected sometimes, but other times, the ball goes right through the brick.
BraindeaD
16
Years of Service
User Offline
Joined: 30th Mar 2008
Location:
Posted: 16th May 2012 07:37
Hi MBPSOFTLLC,
I'm making an arkanoid style game too. When I did the bricks I've tried two options:

-make physical sprites (kinetic type) and check the contacts between the balls and the bricks. Using this way you don't need where the ball collisions with the brick because the physics lib makes all the job for you.

-if you don't want use physical sprites, try this in each loop:
1. store the x and y coordinates of the ball.
2. put the ball in the new coordinates depending on its angle, speed, and so.
3. check for collisions
4. if there are collisions, put the ball in the stored Y coordinate
5. check again for collisions
6. if there are NOT collisions, the previous one collisions was in the Y axis, so change the vertical speed
7. if there are collisions, they are the X axis, so change the horizontal speed

I'm using the first method, is more easy and clear, but time ago I used the second one in another compilers and works well. Hope it helps you.
Excuse my english.

Regards

Login to post a reply

Server time is: 2024-04-27 10:44:21
Your offset time is: 2024-04-27 10:44:21