Edit:
For information on the progress of the conversion of this code, please look at post number three.
If you want to see the finished conversion to DBPro, then here you go:
http://forum.thegamecreators.com/?m=forum_view&t=36053&b=6
Original:
Hello People,
Well, I was browsing through the Code Base looking for some sliding collision examples for DBC, When I stumbled accross some rather neat code by some dude called Sparky:
http://developer.thegamecreators.com/?m=codebase_view&i=398ad5ba24f82319b72c58cb923854b2
Looking at the code, I found that it would be possible to easily introduce a .X or .3DS object into it, and it would still work.
With this in mind, I started to add to the code to make it more suitable for this. All it really needed was some gravity and another type of collision.
`Well Made by Sparky
`messed with by Aura
set display mode 800,600,16
sync on
sync rate 0
autocam off
Set camera range 1,20000
hide mouse
set mipmap mode 2
set normalization on
disable escapekey
backdrop on
color backdrop RGB(98,98,255)
rem Make normal light
set ambient light 30
rem Make shadow light
make light 1
position light 1,250,100,250
color light 1,225,205,105
set light range 1,10000
if fog available()=1
fog on : fog distance 50000 : fog color RGB(100,100,100)
endif
rem inilalize player origin
X#=0
Z#=0
Y#=0
`**********************LEVEL****************************************
rem Stick your level in here
load object "OBJECT NAME HERE.x",7
position object 7,0,-100,0
scale object 7,1000,1000,1000
Set object collision to polygons 7
set object texture 7,0,1
`**********************LEVEL****************************************
rem this is the players sliding sphere
make object sphere 10,25
Set object collision to polygons 10
hide object 10
rem create player ground collision
make object plain 4,15,15
set object collision to polygons 4
scale object 4,20,200,20
hide object 4
player_speedz1=0
Rem Main loopy loop
Do
set cursor 10,10
print screen fps()
rem gravity
position object 4,Object position x(10),Object position y(10)-3,Object position z(10)
if Object collision(4,7)>0=0
if player_speedz1=>1
player_speedz1=0
endif
player_speedz1=player_speedz1-1
position object 10,Object position x(10),Object position y(10)+player_speedz1,Object position z(10)
endif
position object 4,Object position x(10),Object position y(10)-4,Object position z(10)
if Object collision(4,7)>0
if player_speedz1=<-1
player_speedz1=0
endif
player_speedz1=player_speedz1+1
position object 10,Object position x(10),Object position y(10)+player_speedz1,Object position z(10)
endif
if player_speedz1=>10
player_speedz1=10
endif
if player_speedz1=<-10
player_speedz1=-10
endif
oldcAY# = cAY#
oldcAX# = cAX#
cAY# = WrapValue(cAY#+MousemoveX()*0.2)
cAX# = WrapValue(cAX#+MousemoveY()*0.2)
caZ# = Camera angle Z()
Rem input for the players wall collision
If Upkey()=1
XTest# = Newxvalue(X#,cAY#,10)
ZTest# = Newzvalue(Z#,cAY#,10)
gosub SlidingCollision
else
If Downkey()=1
XTest# = Newxvalue(X#,Wrapvalue(cAY#-180),10)
ZTest# = Newzvalue(Z#,Wrapvalue(cAY#-180),10)
gosub SlidingCollision
Endif
Endif
If Leftkey()=1
XTest# = Newxvalue(X#,Wrapvalue(cAY#-90),10)
ZTest# = Newzvalue(Z#,Wrapvalue(cAY#-90),10)
gosub SlidingCollision
else
If Rightkey()=1
XTest# = Newxvalue(X#,Wrapvalue(cAY#+90),10)
ZTest# = Newzvalue(Z#,Wrapvalue(cAY#+90),10)
gosub SlidingCollision
Endif
Endif
Rem Rotate camera accordint to mouse movement
YRotate camera CurveAngle(cAY#,oldcAY#,24)
XRotate camera CurveAngle(cAX#,oldcAX#,24)
rem position camera at the position of the players sliding sphere
Position Camera X#,Object position y(10)+40,Z#
Sync
Loop
Rem Heres the magic
SlidingCollision:
position object 10,XTest#,Object position y(10),Z#
if object collision(10,7) = 0 then X# = XTest#
position object 10,X#,Object position y(10),ZTest#
if object collision(10,7) = 0 then Z# = ZTest#
return
Hope it helps, as Sparky did when he made the original.
Feed back please.
P.S. Remember, you need to load an object or level in there for it to work. ;¬)