and as long as it is above the bottom of the screen then it shall fall.
once it hits the bottom its speed is reversed and a variable called decel is subtracted from the total speed so it looses a bit of speed untill finally it has none. and according to my thought process. the ball should bounce... bounce...bounce... and then stop once the speed reaches zero. because when speed is zero. usually things stop right?
well i cant seem to get this ball to find rest. it likes to bounce... bounce .... bounce.. and once it looses a certain amount of speed. it continues to bounce within a small range at the bottom of the screen.
I am using Blitz3D but i am only using 2D functions and therefore only 2 dimensions. I just want to get this to work....
here is my code:
;Graphics setup Graphics 800,600,32,2 SetBuffer BackBuffer() ;Create player type Type ball Field x,y Field speed# Field accel# Field decel# Field topspeed# End Type Global ball.ball = New ball ball\x=GraphicsWidth()/2 ball\y=5 ball\speed=1 ball\accel=.1 ball\decel=1 ball\topspeed=50 ;Main loop While Not KeyHit(1) Cls updateball() drawball() Flip Wend Function updateball() ;If ball is above bottom then fall If ball\y =< GraphicsHeight()-50 Then ball\speed = ball\speed + ball\accel ;If the ball has touched the ground then reverse the speed and decelerate Else ball\speed=-Abs(ball\speed-ball\decel) ;Make sure the ball doesn't exceed terminal velocity(topspeed) If ball\speed = ball\topspeed Then ball\speed = ball\topspeed ;Make the ball move at speed given ball\y = ball\y + ball\speed End Function ;Draw the ball and draw the ball speed at the top left corner of the screen Function drawball() Oval ball\x,ball\y,20,20,1 Text 0,0, "speed:" + Str(ball\speed) End Function End