Here's a long snippet I made. It demonstrates simple gravity and a bounce
. There is a small section in the loop marked IMPORTANT STUFF. It should have everything that you need to know. The rest is... well... just there.
rem *****************************************
rem BALL+GRAVITY WITH A SIMPLE BOUNCE EXAMPLE
rem *****************************************
sync on
sync rate 60
autocam off
rem Make an image for the landscape
create bitmap 1,10,10
for d = 1 to 1000
r=rnd(255)
ink rgb(r,r,r),0
dot rnd(10),rnd(10)
next d
get image 1,0,0,10,10
delete bitmap 1
rem Make a little landscape
make matrix 1,1000,1000,21,21
prepare matrix texture 1,1,1,1
randomize matrix 1,100
position matrix 1,-500,-100,-500
update matrix 1
rem Creata a ball
Make object sphere 1,10
position object 1,0,10,0
color object 1,rgb(255,0,0)
rem Make a little tile that you can move
make object box 2,50,1,50
position object 2,0,-1,0
color object 2,rgb(0,0,255)
rem Position the camera
position camera 0,100,-200
rem =======================
rem SET IMPORTANT VARIABLES
rem =======================
rem Set the strength of the gravity.
GravityStrength#=0.1
rem State whether we want the ball to bounce. 0 will not let the ball bounce, and 1 will make it bounce.
Bounce=1
rem Set the condition to condition 0 (Tile makes the ball bounce)
Condition=0
rem Specify the bounce limit to avoid tons of tiny bounces.
BounceLimit#=0.5
rem rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
rem BEGIN MAIN LOOP
rem rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
do
circle OBject screen x(1),OBject screen y(1),3
rem Get the ball's positions
x#=object position x(1)
y#=object position y(1)
z#=object position z(1)
rem Say the condition has not been met. If it is met then this will change.
ConditionMet=0
rem Print various thngs.
set cursor 0,0
ink rgb(255,155,155),0
print "Use the arrowkeys to move the blue tile."
print "Use WASD to move the ball."
print "Use the spacebar to make the ball rise."
print "Use SHIFT to change whether the ball will bounce when it hits the matrix or the tile."
print " "
print BallBouncesWhen$
print "USe ENTER to change whether the ball bounces or not."
print " "
print "BALL BOUNCING?> ",YesOrNo$
if Bounce=0 then YesOrNo$="No." else YesOrNo$="Yes."
rem Press shift to decide the condition.
if shiftkey() and Key=0 and Condition=0 then Condition=1 : Key=1 : Grav#=0.0
if shiftkey() and Key=0 and Condition=1 then Condition=0 : Key=1
if shiftkey()=0 then Key=0
rem Check for condition 0 (Ball hits tile)
if Condition=0
BallBouncesWhen$="The ball bounces/sticks when it hits the blue tile."
if Object Collision(1,2) then ConditionMet=1
endif
rem Check for condition 1 (Ball goes under matrix)
if Condition=1
BallBouncesWhen$="The ball bounces/sticks when it goes below the matrix."
rem Say that the condition has been met. Also, put it on the matrix if it goes under.
if y#<Get Ground height(1,x#+500,z#+500)-100 then ConditionMet=1 : y#=Get Ground height(1,x#+500,z#+500)-100
endif
rem Allow you to change whether the ball bounces or not.
if returnkey() and Pressed=0 and Bounce=0 then Bounce=1 : Pressed=1
if returnkey() and Pressed=0 and bounce=1 then bounce=0 : Pressed=1
if returnkey()=0 then Pressed=0
rem Allow you to move the blue tile
position object 2,Object position x(2)+4*(rightkey()-leftkey()),0,Object position z(2)+4*(upkey()-downkey())
rem Allow you to move the ball.
x#=x#+2*(Keystate(32)-Keystate(30))
z#=z#+2*(KEystate(17)-KEystate(31))
rem *******************************
rem IMPORTANT STUFF
rem *******************************
rem Make the amount of gravity go down
Grav#=Grav#-GravityStrength#
rem If the ball meets our condition then make it bounce or stay there.
if ConditionMet=1
rem If the ball is set not to bounce, then just make it stay there.
if Bounce=0
rem Set the gravity amount to 0.
Grav#=0.0
endif
rem If it is set to bounce, then make it bounce up:>:
if Bounce=1
rem Set the gravity to 75% of what it was before.
Grav#=abs( Grav#*0.75 )
rem To avoid a bunch of tiny bounces, we must specify a bounce limit.
rem If the bounce gets too small, it'll just stop.
if Grav#>0.0 and Grav#<=BounceLimit# then Grav#=0.0
endif
endif
rem If you press space then move the gravity up
if spacekey() then Grav#=4.0
rem Finally, add the amount of gravity to the ball's Y position.
y#=y#+Grav#
rem Put the ball at its new position
position object 1,x#,y#,z#
rem *****************************
rem END OF IMPORTANT STUFF
rem *****************************
rem Point the camera at the ball
point camera x#,y#,z#
sync
loop
Ummm...