Bouncing Ball?

Übersicht BlitzBasic Beginners-Corner

Neue Antwort erstellen

 

raynesa

Betreff: Bouncing Ball?

BeitragFr, Sep 30, 2011 14:02
Antworten mit Zitat
Benutzer-Profile anzeigen
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

Xeres

Moderator

BeitragFr, Sep 30, 2011 14:16
Antworten mit Zitat
Benutzer-Profile anzeigen
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, Sin, Cos.
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
T
HERE IS NO FAIR. THERE IS NO JUSTICE. THERE IS JUST ME. (Death, Discworld)

das wurgel

BeitragFr, Sep 30, 2011 15:31
Antworten mit Zitat
Benutzer-Profile anzeigen
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
 

raynesa

Betreff: Thanks

BeitragSa, Okt 01, 2011 9:53
Antworten mit Zitat
Benutzer-Profile anzeigen
Thanks a lot for your help guys I have got it working Smile
Shocked

Neue Antwort erstellen


Übersicht BlitzBasic Beginners-Corner

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group