'' Allow us to use the vector class.
#include once "pristd\priVect2D.bi"
'' FB graphics headers and useful thinger.
#include once "fbgfx.bi"
Randomize timer
'' A type for a ball. No radius please. :P
Type Ball
Pos as pri.Vect2D
Vel as pri.Vect2D
End Type
'' I love 32-bit...
screenres 640, 480, 32
'' Ball position
'' Set up the ball at a random position on our screen.
Dim as Ball Ball
Ball.Pos = type( Rnd * 640, Rnd * 480 )
'' World Gravity
'' 9.81 going doooown
Dim as pri.Vect2D Grav = type( 0, .981 )
Screenlock
Do
'' Increase ball velocity by gravity.
Ball.Vel += Grav
'' Increase the ball position by velocity
Ball.Pos += Ball.Vel
'' Reset ball position and velocity if anything's out of bounds.
If Ball.Pos.X < 0 then
Ball.Pos = type( Rnd * 640, Rnd * 480 )
Ball.Vel = -Grav * 20
End If
If Ball.Pos.Y < 0 then
Ball.Pos = type( Rnd * 640, Rnd * 480 )
Ball.Vel = -Grav * 20
End If
If Ball.Pos.X >= 640 then
Ball.Pos = type( Rnd * 640, Rnd * 480 )
Ball.Vel = -Grav * 20
End If
If Ball.Pos.Y >= 480 then
Ball.Pos = type( Rnd * 640, Rnd * 480 )
Ball.Vel = -Grav * 20
End If
'' Draw the ball.
Circle ( Ball.Pos.X, Ball.Pos.Y ), 20, rgb(255, 255, 255), , , , f
'' 'flip' our page
Screenunlock
sleep 31, 1
Screenlock
cls
Loop until multikey(FB.SC_ESCAPE)
Screenunlock |