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.

DarkBASIC Professional Discussion / breakout remake...ball reflection

Author
Message
blank
22
Years of Service
User Offline
Joined: 4th Mar 2003
Location: My Computer
Posted: 7th Apr 2004 01:33
hey all,
im making a breakout remake because im quite new to db so i took everyones advice and started making breakout, ive got the ball movement and everything but how do i make it so that when the ball hits the paddle on the right hand side it will bounce right off the paddle and the same for left and when it hits the side of it the ball will bounce correctly?
im basically asking how do i make the ball bounce correctly?
thanks in advance, when i know this ill be able to finish the game in no time and ill post it on the forum. Thanks again
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 7th Apr 2004 03:44
post your code then we can help you more easily

Tapewormz
22
Years of Service
User Offline
Joined: 15th Sep 2002
Location: Winnipeg, Mantoba, Canada
Posted: 7th Apr 2004 05:37 Edited at: 7th Apr 2004 07:56
You need to use a formula where you set zones on your paddle.

Say your paddle is 40 pixels wide... And you want the first 20 pixels to move the ball left and the last 20 pixels to move the ball right. You would need an if statement to check to see if the ball's x/y coords (taking the radius into consideration) collide with the paddles x/y coords using your conditions.


Here's a sloppy example:


Ofcourse you'll need to take the ball and paddles dimensions into consideration, and the speed at which the ball is travelling for proper collision...Oh, and you probably want a neutral zone. Oh, and you probably want everything between the extreme corners and the neutral zone to be variable.

Quote: " Timesoft - Your wife is death. How? NO idea.
But it is murder. REVENGE!!!!!!!!!"

Hands down the funniest synopsis for a game ever. All your base are belong to us!
blank
22
Years of Service
User Offline
Joined: 4th Mar 2003
Location: My Computer
Posted: 8th Apr 2004 03:27
thanks for the help though im still confused. damn my lack of knowledge. anyhoo heres my code:

thanks in advance
Don Malone
22
Years of Service
User Offline
Joined: 27th Apr 2003
Location: Birmingham, Alabama
Posted: 8th Apr 2004 07:11
The key is to keep the idea simple.

You know how wide the paddle is. You know how wide the ball is.
If my paddle is 60 units wide (just for reference) I will divide it into 6 sections of ten units each and have a predetermined
angle for each segment of the paddle. When I register the collision I would determine where the ball and paddle touch and then change the ball direction using my predetermined angle and simple math.

I wish I could give you code but I hope my thought process will help.

Wasting CPU Cycles since the 286 was a hot machine.
Billj
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location:
Posted: 8th Apr 2004 07:12
if you bounce on the top or bottom walls then multiply your x movement factor by -1 and if you hit the side walls multiply your y movement factor by -1.

Redneck Word: wichadidya
Sentence: "You didn't bring your truck wichadidya?"
TheOneRing
21
Years of Service
User Offline
Joined: 28th Aug 2003
Location: Right here.
Posted: 8th Apr 2004 16:16
@Billj - wichadidya Jeff Foxworthy is funny!
blank
22
Years of Service
User Offline
Joined: 4th Mar 2003
Location: My Computer
Posted: 8th Apr 2004 16:44
thanks for your help, ill work on it and try and get it going, thanks alot.

Login to post a reply

Server time is: 2025-06-05 19:03:57
Your offset time is: 2025-06-05 19:03:57