TGC Codebase Backup



Static and box sliding collision by MiR

2nd Sep 2003 13:59
Summary

Code that slides the character when it hits a box shaped object or a static object



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    rem Activate manual syncronization
sync on : hide mouse
rem make matrix
make matrix 1,2000,2000,20,20

rem make player
make object box 1,50,50,50
x#=900
z#=900
y#=get ground height(1,x#,z#)+25
position object 1,x#,y#,z#

rem Make a box
make object box 2,100,100,100
position object 2,700,50,700

rem Make a pedastal
make object box 3,50,2,50
position object 3,800,20,800
color object 3,rgb(100,200,100)

rem Make the walls
make object box 4,10,400,2000 : position object 4,2000,0,1000
make object box 5,10,400,2000 : position object 5,0,0,1000
make object box 6,2000,400,10 : position object 6,1000,0,2000
make object box 7,2000,400,10 : position object 7,1000,0,0

rem Set collision
make object collision box 1,-25,-25,-25,25,25,25,0
make object collision box 2,-50,-50,-50,50,50,50,0
make object collision box 3,-25,-1,-25,25,2,25,0
make static collision box 1995,-200,0,2005,200,2000
make static collision box -5,-200,0,5,200,2000
make static collision box 0,-200,1995,2000,200,2005
make static collision box 0,-200,-5,2000,200,5

do

Rem Store old object data
a#=object angle y(1)
oldx#=object position x(1)
oldz#=object position z(1)
oldy#=get ground height(1,x#,z#)
s#=object size(1)/2

rem Move
if upkey()=1
move object 1,5
stage=1
endif
if downkey()=1 and grav#=0.0
move object 1,-5
stage=1
endif
rem Jump
if spacekey()=1 and grav#=0.0
canjump=1
endif
if canjump=1
grav#=grav#+10
if grav#=>50.0 then canjump=0
endif

rem Store new object data
x#=object position x(1)
z#=object position z(1)
y#=get ground height(1,x#,z#)+25

rem gravity
if grav#>0.0
grav#=grav#-5
y#=y#+grav#
endif
rem Sliding collision
if object collision(1,0)>0
dec x#,get object collision x()
dec z#,get object collision z()
endif

rem Static sliding collision
if get static collision hit(oldx#-s#,oldy#-s#,oldz#-s#,oldx#+s#,oldy#+s#,oldz#+s#,x#-s#,y#-s#,z#-s#,x#+s#,y#+s#,z#+s#)=1
   dec x#,get static collision x()
   dec z#,get static collision z()
endif

rem This updates the character´s position
position object 1,x#,y#,z#
rem This rotates the character left
if leftkey()=1
yrotate object 1,wrapvalue(a#-5)
endif
rem This rotates the character right
if rightkey()=1
yrotate object 1,wrapvalue(a#+5)
endif
rem This controls the camera´s position
set camera to follow x#,y#,z#,a#,200,y#+100,3.5,1
cameraposy#=y#+100
position camera camera position x(),cameraposy#,camera position z()
point camera newxvalue(x#,a#,100),y#,newzvalue(z#,a#,100)
rem This updates the screen
sync
loop