Click here to Skip to main content
15,907,396 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to direct the circle to othe direction when it hits the end of one side of the screen???

I assume you mean that you have a program which draws a circle, and moves it across the screen. When it hits teh right hand side, you want to reverse it and start it moving the other way?

If so, then I can't give you any precise information - I don't know how you are drawing the circle, I don't know how you are moving it. I don't know anything about your program at all in fact, other than it is in C and it draws a circle.

So the best I can do is general advice:
Find out the width of your screen in pixels (or in whatever unit you are using for the size of the circle, that is what you will compare against)
Set a variable with the amount to move the circle each time (rather than a constant value in your function)
Before you move the circle, check if the current position (on the X axis), plus the radius of the circle is greater than or equal to the width of the screen. If it is, make the variable amount negative, but leave the actual value alone. So if you were moving it by ten units each time, make it minus ten.
Add on the movement amount, and draw it as normal.

You will probably want to do a similar test against the left hand side of the screen as well.
Share this answer
The program you are searching for is Bouncing Ball.

Here is an implementation :[^]

For more examples use Google.

Hope it helps.
Share this answer
Albert Holguin 16-Jan-12 16:42pm    
Sounds like that's what the OP is trying to do.. +5
Amir Mahfoozi 17-Jan-12 0:32am    
Thanks Albert

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900