Bouncing Ball?
Übersicht

raynesaBetreff: Bouncing Ball? |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Hi there,
I am trying to create an animation of a ball which goes in a random direction and bounces of the edge of each screen. So far I have been able to use the LoadImage function along with keyboard inputs to have the image move around the screen and stop at the wall boundaries. I am unsure as how to assign a random velocity and direction to the ball so it moves automatically and then rebounds in another direction once it hits a wall. Any help would be greatly appreciated. Cheers |
||
![]() |
XeresModerator |
![]() Antworten mit Zitat ![]() |
---|---|---|
May i ask why you use a german forum instead of the official website?
As for your problem: please post a short version of your code, so we can get you a hint. You probably need Rand ![]() ![]() ![]() |
||
Win10 Prof.(x64)/Ubuntu 16.04|CPU 4x3Ghz (Intel i5-4590S)|RAM 8 GB|GeForce GTX 960
Wie man Fragen richtig stellt || "Es geht nicht" || Video-Tutorial: Sinus & Cosinus THERE IS NO FAIR. THERE IS NO JUSTICE. THERE IS JUST ME. (Death, Discworld) |
![]() |
das wurgel |
![]() Antworten mit Zitat ![]() |
---|---|---|
It's probably easier to use a vector instead an angle for the direction. Just multiplikate the vector with the velocity, add it to the position and redraw the ball.
Code: [AUSKLAPPEN] Repeat
ballx = ballx + directionx * velocity bally = bally + directiony * velocity Draw the ball on it's position Until You need to use a normal vector for the direction. If the ball rebounds on a vertical edge you negate directionx, on a horizontal edge you negate directiony. |
||
1 ist ungefähr 3 |
raynesaBetreff: Thanks |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Thanks a lot for your help guys I have got it working ![]() ![]() |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group