HOME
PLATFORM
JUMPING
`Platform Jumping: Introduces gravity, jumping and collision
`Author: Hop A Long
`November 5, 2004

`*****SET UP*****
autocam off
sync rate 30
sync on
hide mouse

`  Player
Make Object Cube   1, 3
Position Object    1, 0,9 , 0
Make Object Collision Box 1, -1.5,-1.5,-1.5,1.5,1.5,1.5,0
Rotate Object      1,0,190,0
Color Object       1, RGB(248,222,135)

`  Ground 2
Make Object Cone   2, 10
Position Object    2, 0, -1.5, 0
Make Object Collision Box 2,-5,-5,-5,5,5,5,0
XRotate Object     2, 180
` Red
Color Object       2, RGB(255,128,128)

`  Ground 3
Make Object Cone   3, 20
Position Object    3, -5.0,-15,-2
Make Object Collision Box 3, -8,-10,-8,8,10,8,0
XRotate Object     3, 180
` Green
Color Object       3, RGB(190,243,139)

`  Ground 4
Make Object Cone   4, 20
Position Object    4, -10.0,-15,20
Make Object Collision Box 4, -8,-10,-8,8,10,8,0
XRotate Object     4, 180
` Orange
Color Object       4, RGB(252,195,48)

`  Ground 5
Make Object Cone   5, 20
Position Object    5, 10.0,-25,50
Make Object Collision Box 5, -8,-10,-8,8,10,8,0
XRotate Object     5, 180
` Violet
Color Object       5, RGB(247,128,238)

`  Ground 6
Make Object Cone   6, 10
Position Object    6, 7.0, -20, 70
Make Object Collision Box 6,-5,-5,-5,5,5,5,0
XRotate Object     6, 180
` Yellow
Color Object       6, RGB(245,254,86)

`  Ground 7
Make Object Cone   7, 10
Position Object    7, 7.0, -15, 90
Make Object Collision Box 7,-5,-5,-5,5,5,5,0
XRotate Object     7, 180
` Blue
Color Object       7, RGB(128,255,255)

`  Ground 8
Make Object Cone   8, 15
Scale Object       8, 100,300,100
Position Object    8, -15, 10, 30
XRotate Object     8, 180
` Blue
Color Object       8, RGB(128,255,255)

`  Ground 9
Make Object Cone   9, 15
Scale Object       9, 100,300,100
Position Object    9, 15, 10, 60
XRotate Object     9, 180
` Yellow
Color Object       9, RGB(245,254,89)

`  Declare the jump\gravity variable
jg# = 0.0
action$ = "WALK"

`*****BEGIN THE LOOP*****

   Do

      `*****SIMPLE MOVEMENT*************************************
      `  Click Mouse to Move Ahead
      click = MouseClick()
      If click = 1 Then Move Object 1,.2
      If click = 2 Then Move Object 1,.7
      If click = 3 Then Move Object 1,1.0

      `  Move Mouse to Change Player's Y Angle
      y_ang# = Object Angle Y(1)
      If action$ = "WALK"
         Yrotate object 1,wrapvalue(y_ang#+(MouseMoveX()))
      EndIf

      `*****LOCATION VARIABLES*******
      posx#=object position x(1)
      posy#=object position y(1)
      posz#=object position z(1)

      `*****lAUNCH THE JUMP**********
      If spacekey()=1 and jg#=0.0
         save_x# = Object Position X(1)
         save_y# = Object Position Y(1)
         save_z# = Object Position Z(1)
         action$ = "JUMP"
         jg#=1.75
      Endif

      jg#=jg#-0.1
      posy#=posy#+jg#

      `*****CHECK THE NEW POSITION FOR COLLISION*****
      obj_id = 0

      If Object Collision(1,0)>0

         obj_id = Object Collision(1,0)

         Dec posx#,Get Object Collision X()
         Dec posy#,Get Object Collision Y()
         Dec posz#,Get Object Collision Z()
         action$ = "WALK"
         jg# = 0.0

      EndIf

      `*****PLACE THE PLAYER IN CORRECTED POSITION
      Position Object 1,posx#,posy#,posz#

      `*****GIVE PLAYER ANOTHER CHANCE*************************************
      If posy#<-50
         jg#=0.0
         If action$ = "JUMP" Then position object 1 ,save_x#, save_y#, save_z#
         If action$ = "WALK"
            Rotate Object      1,0,190,0
            Position Object 1, 0,0,0
         EndIf
      Endif

      `*****CAMERA ROUTINES*************************************
      Set Camera To Follow posx#,posy#,posz#,0,30,(posy#+5),1,0

      `*****FORMAT OUTPUT*************************************
      Center Text 320,50, "PLATFORM JUMPING"
      Center Text 320,70, "Space to Jump, Left Click to Move, Right Click Move Faster , Mouse to Turn"

      `*****COPY EVERYTHING TO THE SCREEN
      Sync

   Loop
`*****END OF MAIN LOOP*************
A short example that uses gravity with jumping and collision
A round of thanks to Hattori Hanzo at the DB Forum for sharing the ideas used to develop this demo.