Hi,
Try this code:
Its not mine (creds to Mark Fleury)
REM ************************************************************************
REM All-Code Tutorials #9
REM Adding Gravity
REM Copyright 2002 Marc Fleury
REM ************************************************************************
REM This and many other DB resources are available at
REM www.DBHeaven.com
REM ************************************************************************
RANDOMIZE TIMER()
HIDE MOUSE
SYNC ON
SYNC RATE 60
radius = 10
leftedge = 1
rightedge = 639
topedge = 1
bottomedge = 479
xpos# = 320.0
ypos# = 240.0
yspeed# = 0.0
xspeed# = 0.0
acc# = 0.1
gravity# = 0.05
wind# = 0.01
REM These are the new variables that we'll be using to add external
REM forces outside of the user's control. You can play with the values
REM of wind#, gravity#, and acc# (acceleration).
REM Main loop. Today I'll be putting eveything in the main loop proper,
REM just to show all the new code.
DO
REM Processing Input
IF UPKEY() THEN yspeed# = yspeed# - acc#
IF DOWNKEY() THEN yspeed# = yspeed# + acc#
IF RIGHTKEY() THEN xspeed# = xspeed# + acc#
IF LEFTKEY() THEN xspeed# = xspeed# - acc#
REM In previous code, the direction keys were used to directly change
REM the x and y position of the circle. Today, they work indirectly,
REM by changing the SPEED at which the circle moves. Then the speed will
REM change the position, like so:
xpos# = xpos# + xspeed#
ypos# = ypos# + yspeed#
REM Other Input
IF RETURNKEY() THEN wind# = wind# + 0.01
IF SHIFTKEY() THEN wind# = wind# - 0.01
REM Add forces
yspeed# = yspeed# + gravity#
xspeed# = xspeed# + wind#
REM Simple, eh?
REM Detect collision with screen edge
IF xpos# < (leftedge + radius)
xpos# = (leftedge + radius)
xspeed# = 0.0 - xspeed#
REM The single line of code above "xspeed# = 0.0 - xspeed#" is a beautiful
REM line of code. It (and the three similar lines below) makes the ball
REM bounce. Basically, when the ball hits the edge of the screen, the
REM *sign* on the direction of movement is changed, so that left movement
REM becomes right movement and vice versa, while upward movement becomes
REM downward movement, and vice versa.
ENDIF
IF xpos# > (rightedge - radius)
xpos# = (rightedge - radius)
xspeed# = 0.0 - xspeed#
ENDIF
IF ypos# < (topedge + radius)
ypos# = (topedge + radius)
yspeed# = 0.0 - yspeed#
ENDIF
IF ypos# > (bottomedge - radius)
ypos# = (bottomedge - radius)
yspeed# = 0.0 - yspeed#
ENDIF
REM Update Screen
CLS 50
TEXT 0,0,"Use ENTER and SHIFT to change the wind"
TEXT 0,25,"Wind: "+STR$(wind#)
CIRCLE xpos#,ypos#,radius
SYNC
REM Even though the screen coordinates are integers, DB lets you use
REM a real value for the coordinates -- it simply truncates the decimal
REM part, which saves us using the INT() command to do the same thing.
LOOP
It helped me - and its a fun example!
You can look through it and still code it your own way. His rem statements explain the process.