Home > How-To Library > Forms
How to make a bouncing ball type effect
**************************************************************** * © 2007 CodeItBetter http://www.codeitbetter.com * * This notice MUST stay intact for legal use * **************************************************************** Dim intX As Integer, intY As Integer, intHeight As Integer, intCountMinus As Integer, _ intLength As Integer, intCount As Integer Private Sub Command1_Click() For intCount = 200 To 0 Step -50 '(X to 0 step Y) X = First bounce height, Y = How much the bounce decreases each time intHeight = intCount + 50 'How high the ball will bounce intLength = 2000 'Length of the bounce intY = ScaleHeight 'Sets the vertical starting position of a bounce intCountMinus = (intHeight / 100) 'intCountMinus = (intHeight/X) --> X = gravity, increase for more gravity Do Until intY > ScaleHeight 'Loops until ball hits the "ground" intX = intX + (intLength / 200) 'intX moves towards its length by intervals of 1/200 the length intY = intY - intHeight 'Moves the ball up by intHeight intHeight = intHeight - intCountMinus 'Intheight is subtracted from Circle (intX, intY), 300 'Draws the ball Loop Next intCount End Sub Private Sub Form_Load() intX = 0 'Left/right starting point of ball End Sub
If you would like to submit your code here please us. Do not forget to mention your name. We are always thankful to each and everyone of you who submitted their code here.