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.

Newcomers DBPro Corner / Breakout - bouncing the ball of the bricks in right dirrection

Author
Message
Kirneh
20
Years of Service
User Offline
Joined: 24th Feb 2004
Location:
Posted: 24th Feb 2004 10:26
Hi all.

Im new to DBP and im trying to make a breakout clone. I move the ball with a speed and a angle. When it hits the sides of the screen i get the new angle with 360 - angle, and if it hist the top/pad i use 180-angle. That works fine.

But when i hit the bricks it can hit on the bottom or on the sides (or top) of the brick. It then have to bounce back in the right dirrection. How do i se on wich side of the brick the ball hits ?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Feb 2004 12:11
You could compare the ball position with the brick position to determine if it's far enough to the left or right to assume it has hit the side.

BatVink (formerly StevieVee)
http://facepaint.me.uk/catalog/default.php
Kirneh
20
Years of Service
User Offline
Joined: 24th Feb 2004
Location:
Posted: 24th Feb 2004 14:42
I have been thinking about the same myself.
When i have a collision i could check:
-if the top of the ball is below or equal to the bottom of the brick it hits the bottom of the brick.
-if the right side of the ball is equal or lower than the bricks left side it hit the left side of the brick.
Gotta make 4 checks this way.

Im gonna think a bit more to see if I can make this so 1 check is for top/bottom and 1 is for right/left, since the action for top/left is the same and right/left is the same.
KNau
22
Years of Service
User Offline
Joined: 25th Nov 2002
Location: Canada
Posted: 24th Feb 2004 17:55
I'm working on a pong styled game right now and the way I've been doing it is something like this:

1) Store the ball's current position in "oldballx". "oldbally" variables.

2) Update the ball position (based on speed and angle).

3) Check if the ball has moved within the X and Y distance from an object to cause a collision (or use built in collision, if you prefer).

4) Check the ball's oldx and y positions to determine hits on the x and y axis. For example, if the ball's "old x" position is outside of the collision radius for your object but the new one is within that radius then a horizontal or "X hit" has occurred. Same principle applies to the Y axis.

5) If an X-hit has occurred then reverse the horizontal angle, if a Y-hit has occurred then reverse the vertical angle.

Here is the code that does the check for x and y hits:

IF oldballx# < enemies#(x,2) - 22 OR oldballx# > enemies#(x,2) + 22 THEN xhit = 1
IF oldbally# < enemies#(x,3) - 22 OR oldbally# > enemies#(x,3) + 22 THEN yhit = 1

Note the "enemies#(x,2) - 22" parts are just checking my object positions (stored in an array) to see if the ball was originally outside the collision zone.

So it's 3 checks for me:
1) Check to see if the ball had collided with an object
2) Check to see if an X collision has occurred
3) Check to see if a Y collision has occurred

I hope this helped.
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 24th Feb 2004 20:30
The way I'd do it is pretty much like you said.

code like this :

if x#<(brick(t,1)+***half the brick width*** then <180 bounce>
if z#<(brick(t,3)+***half the brick depth*** then <360 bounce>


Inside a for...next loop, of course.


Coming Soon...
mm0zct
21
Years of Service
User Offline
Joined: 18th Nov 2003
Location: scotland-uk
Posted: 28th Feb 2004 19:53 Edited at: 28th Feb 2004 20:11
i've done this but there are some collision problems because if the ball moves too fast it can miss the collision range and if you set the range too big you get the ball rebounding inside the bat, collision and controls for my gam (basically all of it except the original setup at the start and the loop:

i hope you can understand it and that it helps if you want more explination then email me. edit:i've added some rems(the balls variable is actually the number of cubes left. sorry it's a bit messy)

http://www.larinar.tk
AMD athlon thoroughbred 2200, 512Mb ram, 40Gb HD, ati saphire radeon 9600 atlantis w/128mb ddr ram, good creative-labs soundcard, cd-rw + dvd drives.
sponge008
20
Years of Service
User Offline
Joined: 8th Feb 2004
Location: MA, USA
Posted: 28th Feb 2004 22:37
I haven't read the whole thing, but try making line-things by all sides of the bricks, and after that, you're all set. I haven't read the whole thread, so sorry if I'm reposting.

Login to post a reply

Server time is: 2024-11-26 07:51:52
Your offset time is: 2024-11-26 07:51:52