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 / Hi, problem with first game, Breakout

Author
Message
s1lverblade 331
20
Years of Service
User Offline
Joined: 14th Jul 2004
Location:
Posted: 17th Jul 2004 05:36
I've started to make my first game and it is a version of breakout, but I'm having trouble with collision between the paddle and the ball.
How can I fix this?
s1lverblade 331
20
Years of Service
User Offline
Joined: 14th Jul 2004
Location:
Posted: 17th Jul 2004 05:37
Here is code:
s1lverblade 331
20
Years of Service
User Offline
Joined: 14th Jul 2004
Location:
Posted: 17th Jul 2004 05:39
and it's in dbc

p.s. when I click edit it says error 404
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 17th Jul 2004 07:40


Or are you looking for a way to reflect the ball from the paddle?

"eureka" - Archimedes
s1lverblade 331
20
Years of Service
User Offline
Joined: 14th Jul 2004
Location:
Posted: 17th Jul 2004 08:36
yes, I do want it to reflect off the paddle
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 17th Jul 2004 15:07
paddle_x = center of paddle

a = max angle of reflection (if the ball hits the paddle at the very edge, this is the angle it'll reflect at. 0 is straight up, 90 is sideways, so an angle between there, like 70)

d = distance of ball and paddle (X coordinates only)
L = paddle length

s = a / (L/2)
d = abs(ball_x - paddle_x)

if ball_x => paddle_x then angle = d * s
if ball_x < paddle_x then angle = 360 - d * s

So if the paddle is 100 units, and the balls hits the paddle 50 units from the center, it'll reflect at angle "a" or for this example 70. At 25 units from the center, it'll be "a/2" or 35, and at 0 units it'll be 0 degrees. This just uses proportions to calculate the angle based on the balls distance from the paddle's center. "S" only has to be calculated once, unless the size of the paddle changes.

"eureka" - Archimedes

Login to post a reply

Server time is: 2024-09-22 17:26:29
Your offset time is: 2024-09-22 17:26:29