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.

Dark GDK / Reflection?

Author
Message
niekvanderkooy
14
Years of Service
User Offline
Joined: 13th Mar 2010
Location:
Posted: 13th Mar 2010 18:41
Good day everyone,

I'm stuck with a problem for my (first) darkGDK program I'm creating.

It's sort of a pong variant with one paddle on each wall, with the object to keep bouncing the ball between the paddles for as long as possible.

Now my question is:
I am able to detect the collision between baddle and ball (using dbSpriteCollision(), but I dont know how I can then make it reflect (keeping in minde that the lower the incoming angle is, the lower the outward angle must be aswell).

Is anyone able to help me?

Many thanks
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 13th Mar 2010 22:03 Edited at: 13th Mar 2010 22:05
Um, all you need to do is just multiply the speeds of the X and Y positions by -1.

What I mean is like this



Understand?

http://www.darkgdk.us/ <- You can now submit pages, upload images, yet were lacking content. We need your help!
niekvanderkooy
14
Years of Service
User Offline
Joined: 13th Mar 2010
Location:
Posted: 13th Mar 2010 23:00
I understand the principle, but the way I'm moving it is that I first rotate it with dbRotateSprite(), and then move it 'forward' with dbMoveSprite. In this situation, theree is no XSpeed or YSpeed, because it is always moving 'forwards'.

So, when it hits the paddle, it should be moved by a certain amount by using dbRotateSprite() again right? Or should I be doing it very differently?
Cetobasilius
14
Years of Service
User Offline
Joined: 29th Dec 2009
Location: Mexico
Posted: 14th Mar 2010 05:41
well maybe its easier to do on 3d XD hehe

hi
niekvanderkooy
14
Years of Service
User Offline
Joined: 13th Mar 2010
Location:
Posted: 14th Mar 2010 07:19
hmmm... maybe it is... But shouldnt it be possible to do in 2D aswell?
niekvanderkooy
14
Years of Service
User Offline
Joined: 13th Mar 2010
Location:
Posted: 14th Mar 2010 13:52
Anyone who was about to answer: Thank you, but I've solved the problem.

To anyone wondering to a solution: what I did was just rotate the ball by 360-dbSpriteAngle(ball) for when it hit the top/bottom paddle, and by 180-dbSpriteAngle(ball) for the left and right paddles.

Login to post a reply

Server time is: 2024-11-20 03:21:20
Your offset time is: 2024-11-20 03:21:20