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 / bounce of wall for pong

Author
Message
Making a game
16
Years of Service
User Offline
Joined: 9th Jul 2008
Location:
Posted: 10th Jul 2008 12:40
Hi

I wanted to make the classic pong game in 2D before trying something else, its a classic game and deserves to be made first above others.

Anyway, i have loaded the sprites i.e.computer paddle, player paddle and the ball. i can move the paddle using the left and right arrow keys and i can make the ball move. i can also make the computer paddle follow the ball i.e.


the problem that i am now faced with is that i cant seem to make the ball bounce of the wall.

i know the theory as i have done it before but it just isnt working.

the theory is that if the ball hits a vertical wall then reverse x and if it hits a horizontal wall then reverse y but it dosent work.



can someone help me out

thanks
programing maniac
16
Years of Service
User Offline
Joined: 19th Apr 2008
Location: Bawk, Bawkity
Posted: 10th Jul 2008 15:16
I know in python there was an easy way of doing this. I can't remember if c++ can do it though. I don't really use 2D. I think this might work-



I don't know if that is what you are trying to do, but I think that code will work. Then for the X axis, you probably want the ball to disapear because it hit a wall.

Hope it helped.


www.globalwarfare.tk
Making a game
16
Years of Service
User Offline
Joined: 9th Jul 2008
Location:
Posted: 10th Jul 2008 17:18
Thank for your help, i did figure it out eventually. it isnt ...

...but it is more like...


I however now have a problem, i am trying to get the ball to hit the paddle and bounce of it. I am using dbSpriteCollision and i can register the hit by using dbPrint to check but i cant seem to get the ball to bounce back.

what i am doing is this...

...but this does not work. can anyone help.

thanks
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 10th Jul 2008 17:20
All you need to do is reverse the Y velocity of the ball when it hits the top or bottom.

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 10th Jul 2008 18:19
Are you reversing the velocity or the ball's Y position.

Also, when you hit a vertical wall don't you want it to exit rather than bounce? The only time you should bounce it is when it hits the paddles, the top or the bottom. Mind you, for developmental purposes I've allow a ball to bounce off the bottom in order to keep the thing moving. In game play that won't happen.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Jaheco
16
Years of Service
User Offline
Joined: 30th Jun 2008
Location:
Posted: 10th Jul 2008 22:26
Personally I would not rely on the sprite collision to do the work, for at its core it's not too complex.



So this checks to see if the ball is A) intersecting the total space that could be occupied by a paddle, B) if the ball's horizontal centerline is in the area where the paddle is at that moment, and C) if the ball is touching either of the two walls.

Login to post a reply

Server time is: 2024-11-20 15:37:51
Your offset time is: 2024-11-20 15:37:51