TGC Codebase Backup



3D jumping for beginners by Charlie

8th Jan 2007 21:14
Summary

Basic 3D jumping for beginners. No media.



Description

Basic 3D jumping action for beginners. Includes moving, graity set, camera tracking, matrix texturing, and some ambient settings.Hope it helps. Sorry but for the bad positioning of the object, since it seems to overlap the matrix. You can try fixing it. If not, I'll put the correction later.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    rem Simple Gravity Example by CW

rem basic setting
sync rate 60
hide mouse
autocam off

rem texture for matrix
cls rgb(255,255,255)
for x=0 to 1000
dot rnd(32),rnd(32),rgb(00,00,255)
next x
get image 1,0,0,32,32
cls
color backdrop 0

rem make objects
make matrix 1,512,512,64,64
prepare matrix texture 1,1,1,1
update matrix 1
make object cube 1,1
color object 1,rgb(00,255,00)

rem state variables and position
g#=0
gravity#=0
jumpower#=0
onground=0
y#=0
x#=0
z#=0
position object 1,150,6,100

rem set ambient
set ambient light 0
position light 0,x,100,z
point light 0,x#,y,z#
color light 0,rgb(255,255,255)
set light range 0,50

do
rem state variables values
x#=object position x(1)
y#=object position y(1)
z#=object position z(1)
a#=object angle y(1)
rem move object fowards
if upkey()=1
x#=newxvalue(x#,a#,.5)
z#=newzvalue(z#,a#,.5)
endif
rem move object backwards
if downkey()=1
x#=newxvalue(x#,a#,-.5)
z#=newzvalue(x#,a#,-.5)
endif
rem rotate object right
if rightkey()=1 then yrotate object 1,wrapvalue(object angle y(1)+2)
rem rotate object left
if leftkey()=1 then yrotate object 1,wrapvalue(object angle y(1)-2)
rem jump by setting a jumpower
if spacekey()=1 and onground=1 then jumpower#=0.3

rem jumpower# decrements when you are in air
if jumpower#>0 then jumpower#=jumpower#-.004

rem the jumping action
rem because you position the object adding it the jumpower value
y#=y#+jumpower#

rem state g# value
g#=get ground height(1,x#,y#)

rem if you aren't on ground then set gravity
rem else stop gravity
if y#>g#
gravity#=gravity#+.005
y#=y#-gravity#
onground=0
else
y#=g#
gravity#=0
onground=1
endif

rem position object according to the modified values
position object 1,x#,y#,z#

rem camera tracking
set camera to follow x#,y#,z#,a#,10,3,20,1

loop

rem Hope this heleped you
rem Try adding more :)

remstart
Remember, the jumping happens only because the adding and decrementing of the 
object y position. I first though it to be something difficult but really it is not that hard at all
remend