HOME | ||||||||||
PLATFORM TEDDY | ||||||||||
This takes the previous platform demo one step further. An animated model is used instead of the box object. Down load the teddy file and unzip it into the same folder as the source code. | ||||||||||
`Platform Teddy: Introduces gravity, jumping and collision using an animated model `Author: Hop A Long `November 20, 2004 `To run the demo, download the teddy file and unzip it into the folder containing `the demo code. The zip contains the x animations and ted's skin. `*****SET UP***** autocam off sync rate 30 sync on hide mouse file$ = "teddy.x" Load Object file$,1 idlestart=0 : idleend = 30 walkstart = 31 : walkend = 60 Make Object Collision Box 1, -1.0,-1.0,-1.0,1.0,1.0,1.0,0 Position Object 1,0,9,0 ` Ground 2 Make Object Cone 2, 10 Position Object 2, 0, -1.5, 0 Make Object Collision Box 2,-5,-5,-5,5,4,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, -10,-10,-10,10,10,10,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,4,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,4,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$ = "IDLE" last_action$ = "IDLE" `*****BEGIN THE LOOP***** Do `*****SIMPLE MOVEMENT************************************* click = MouseClick() ` BOOST If click = 3 Then Move Object 1,-1.0 ` IDLE If click = 2 And action$ = "WALK" action$ = "IDLE" ` remember what he was doing last_action$ = "IDLE" Set Object Frame 1,idlestart EndIf ` WALK If click = 1 And action$ = "IDLE" action$ = "WALK" ` remember what he was doing last_action$ = "WALK" ` this frame blends well with idle Set Object Frame 1,walkstart + 7 EndIf ` 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 If action$ = "IDLE" Set Object Speed 1,30 Loop Object 1,idlestart,idleend EndIf If action$ = "WALK" Set Object Speed 1,30 Loop Object 1,walkstart,walkend Move Object 1,-0.2 EndIf If action$ = "JUMP" Then Move Object 1,-.5 ` Move Mouse to Change Player's Y Angle y_ang# = Object Angle Y(1) If action$ <> "JUMP" 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) `*****Jump and Gravity Math***** 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() If action$ = "JUMP" Then action$ = last_action$ 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$ = "WALK" Or action$ = "IDLE" action$ = "IDLE" last_action$ = "IDLE" Position Object 1, 0,0,0 EndIf If action$ = "JUMP" position object 1 ,save_x#, save_y#, save_z# action$ = "IDLE" last_action$ = "IDLE" EndIf Endif `*****CAMERA ROUTINES************************************* Set Camera To Follow posx#,posy#,posz#,0,30,(posy#+5),1,0 `*****FORMAT OUTPUT************************************* Center Text 320,20, "PLATFORM TEDDY" Center Text 320,40, "Spacekey : Jump Mouse : Turn L-Click : Walk R-Click : Idle L and R Click : Boost " Text 10,380,"action : "+action$ Text 10,400,"collision with object : "+str$(obj_id) `*****COPY EVERYTHING TO THE SCREEN Sync Loop `*****END OF MAIN LOOP************* |