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 / ~Help with a Bouncing Ball Program~

Author
Message
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 29th Oct 2009 01:08
I need to modify this program.I tried using y+=DISTANCE but that only stop the ball on top but i need the ball to bounce back to bottom after it reaches the top.
When the ball reaches the top it should reverse it direction and move back to the bottom and when it reaches the bottom of screen,it reverses again and moves back to the top.

goonj

Attachments

Login to view attachments
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 29th Oct 2009 01:08
i need some help with this... !!

goonj
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 29th Oct 2009 06:03
Looks to me as it it's designed to jump back to the screen. What you need to do is negate the value of DISTANCE. But then you need to start looking at Y being larger that your screen height minus radius and be ready to negate distance once more.




Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 29th Oct 2009 06:06
this is designed just to reach the top of screen and then reappear at the bottom and again reach the top.
But i need to change it and make it for just bouncing... i.e., from bottom to top and then top to bottom.how can i do that?

goonj
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 29th Oct 2009 06:09
I tried doing this

if(y<TOP_Y)
{
y+=DISTANCE;
}
else
{
y-=DISTANCE;
}
but this only makes the ball stop at the top and it does not come down to the bottom.

goonj
Ultimate_H
15
Years of Service
User Offline
Joined: 11th Mar 2009
Location: A place that is neither here nor there
Posted: 29th Oct 2009 06:26
what you need to do (if you are wanting the ball to move to the top, bounce and move all the way to the bottom, bounce move to the top, etc) is set up a direction variable(i usually use a bool) that will change when the ball reaches the edge of the screen. something like this:



this will make it so that the ball bounces off the top and bottom. But really, this could be simplified even more if you are using a variable to move the ball:


at least, this is what I usually do when I want to bounce things off walls.

I am not smart. I am not powerful. I am just a guy. I am strengthened through my faith.
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 29th Oct 2009 06:31
What is y> and y<?
Sorry to ask again,but i can only use the given variable that are being defined in the original program.
Can i talk to you directly if you have any id on yahoo or hotmail?

goonj
Ultimate_H
15
Years of Service
User Offline
Joined: 11th Mar 2009
Location: A place that is neither here nor there
Posted: 29th Oct 2009 07:04
Currently, I don't have a hotmail or yahoo ID.

"y>" is: if the variable "y" is greater than
"y<" is: if the variable "y" is less than

Looking at the original, you need to mess with the "if-else" statement so that the addition/subtraction to "y" is outside of it and use the second "if" structure I posted above, replacing "VELOCITY" with "DISTANCE".

it would look pretty much the same as what I posted.

I am not smart. I am not powerful. I am just a guy. I am strengthened through my faith.
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 11th Nov 2009 00:31
thank you

goonj

Login to post a reply

Server time is: 2024-10-01 16:42:27
Your offset time is: 2024-10-01 16:42:27