I think I can help you out a bit here.

You need to let go of the (x,y) thinking. A ball is not simply described by where it is, but where it's going and how fast that's changing. It's these relationships that causes the parabola to appear. This can be accomplished in 3 steps as shown below.

**Step 1**
What you need to do is to implement position, velocity and acceleration as individual coordinates (that's vectors in mathematics). To do this we're going to need some stuff as usual; a Vector TYPE. This will do:

Code: Select all

```
TYPE Vector
x AS DOUBLE
y AS DOUBLE
END TYPE
```

**Step 2**
Now when that's in place, we can start writing our program. We need:

[*]Constants like what the gravity is, how large the ball is and how much of the velocity that will be preserved after impact with the ground.

[*]Declare the ball's position, velocity and acceleration.

Code: Select all

```
CONST G = 9.82 'Gravity on earth 9.82 m/s^2
CONST RA = .25 'Fairly large ball with a diameter of 1 meter
CONST S = 20 '1 meter equals 100 pixels on the screen as we draw
CONST T = .002 'Step time 2 ms each loop
CONST E = .8 '80% bounce efficiency
DIM r AS Vector 'Location
DIM v AS Vector 'Velocity
DIM a AS Vector 'Acceleration
r.x = 0 'Position the ball in the center,
r.y = 20 'ten meters above the ground.
v.x = .1 'Let the ball have a small initial
v.y = 0 'velocity to the right
a.x = 0 'No initial acceleration
a.y = 0
```

Notice here that we're measuring in meters. This is generally a good thing to do, and we can scale the graphics later on as we draw them.

**Step 3**
We are now ready to write the general bounce method, so let's jump right into it:

Code: Select all

```
SCREEN 12
DO
'Gravity causes the ball to get acceleration
a.y = -G
'Acceleration causes the ball to get a new velocity
v.x = v.x + T * a.x
v.y = v.y + T * a.y
'A new velocity causes the ball to move
r.x = r.x + T * v.x
r.y = r.y + T * v.y
'Check for bounce
IF r.y < 0 THEN
r.y = 0 'The ball can't go through the ground
v.y = -v.y * E 'Reverse the velocity of the y-coordinate
'and lose some speed to bounce efficiency
END IF
'Draw the ball and scale, but leave the old one in place,
'so one can view the parabola trail left by the ball.
CIRCLE (S + 320 * r.x, 400 - S * r.y), RA * S, 14
LOOP UNTIL INKEY$ <> ""
```

That's pretty much all there's to it. A possible addition is the implementation of coefficients of restitution, but that's a bit over our heads right now. Hope this helps out not only with the bouncing ball but delivers some insight into organizing code for applications.

Now this program runs beautifully and looks like this:

The one and only.

AKA xerent