Jump on a matrix with sliding collision by Dark Lord4th Aug 2005 23:05
|
---|
Summary Code with jumping on a matrix, taken from the DB Sliding Collision Demo. Includes simple gravity and collision with matrix and objects. Description Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com Rem Set up environment hide mouse sync on : sync rate 40 Rem Create sphere make object sphere 1,10 color object 1,rgb(20,100,255) make object collision box 1,-5,-5,-5,5,5,5,0 position object 1,990,400,670 Rem Create matrix make matrix 1,10000,10000,25,25 randomize matrix 1,100 Rem Make simple objects for collision for a = 10 to 20 make object box a,50,8,50 position object a,1300*a/3,100,(a*200)+(a+300) make object collision box a,-25,-4,-25,25,4,25,0 position object a,1000,4+(a*10),100+(a*50) color object a,RGB(0,200,0) next a Rem _______________________________________________________________________ rem Start off player gravity playergrav#=2.0 rem Main loop do rem User prompts ink rgb(255,255,0),0 center text 320,20,"USE ARROWS TO MOVE AND SPACE TO JUMP" center text 320,38,"COLLISION WITH A MATRIX" center text 320,56,"TAKEN FROM THE DB SLIDING COLLISION DEMO" rem Store old positions oldposx#=object position x(1) oldposy#=object position y(1) oldposz#=object position z(1) rem Control player object if upkey()=1 then move object 1,2 if downkey()=1 then move object 1,-2 if leftkey()=1 then yrotate object 1,wrapvalue(object angle y(1)-3) if rightkey()=1 then yrotate object 1,wrapvalue(object angle y(1)+3) if spacekey()=1 and playergrav#=0.0 then playergrav#=2.0 rem Get current object position posx#=object position x(1) posy#=object position y(1) posz#=object position z(1) rem Handle a touch of gravity playergrav#=playergrav#-0.1 posy#=posy#+playergrav# rem Handle sliding collision for player object with other objects position object 1,posx#,posy#,posz# if object collision(1,0)>0 dec posx#,get object collision x() dec posy#,get object collision y() dec posz#,get object collision z() playergrav#=0.0 endif rem HANDLE COLLISION WITH THE MATRIX if posy#<get ground height(1,posx#,posz#)+50.0 playergrav#=0.0 posy# = get ground height(1,posx#,posz#)+50.0 endif rem Set a size for the player object s#=object size y(1)/2.0 rem Ensure camera stays out of static collision boxes if get static collision hit(oldposx#-s#,oldposy#-s#,oldposz#-s#,oldposx#+s#,oldposy#+s#,oldposz#+s#,posx#-s#,posy#-s#,posz#-s#,posx#+s#,posy#+s#,posz#+s#)=1 dec posx#,get static collision x() dec posy#,get static collision y() dec posz#,get static collision z() if get static collision y()<>0.0 then playergrav#=0.0 endif rem Update with new object position position object 1,posx#,posy#,posz# rem Use camera tracker to follow player object angle#=object angle y(1) camdist#=25.0 : camhigh#=posy#+10.0 : camfade#=3.5 set camera to follow posx#,posy#,posz#,angle#,camdist#,camhigh#,camfade#,1 rem Tilt camera down a little xrotate camera 15 rem For fun, slightly move pedastal step move object 10,0.01 rem Update screen sync rem End loop loop |