`***********************************
`****** Platform Game Program ******
`****** By Hamish McHaggis ******
`***********************************
Rem Setup Environment
rem #include "statlib.dba"
sync on:hide mouse
load bitmap "loading.bmp",10
get image 10,0,0,256,256
delete bitmap 10
make object cube 10000,8
position object 10000,0,0,8
texture object 10000,10
zrotate object 10000,180
scale object texture 10000,1,1
lock object on 10000
print "Loading"
gosub variables
gosub setup
gosub scenery
dir#=1
delete object 10000
Rem Main Loop
do
gosub controls
gosub character
gosub plat
gosub camera
sync
loop
Rem Control Character Movement
controls:
ox#=x#:oy#=y#:oz#=z#
if leftkey()=1 then a#=wrapvalue(a#-turnspd#):way#=0
if rightkey()=1 then a#=wrapvalue(a#+turnspd#):way#=0
if upkey()=1 then x#=newxvalue(x#,a#,walkspd#):z#=newzvalue(z#,a#,walkspd#):way#=1
if downkey()=1 then x#=newxvalue(x#,a#,0-walkspd#):z#=newzvalue(z#,a#,0-walkspd#):way#=-1
if spacekey()=1 and jump#=0 and pgrav#=0 then pgrav#=jumppower#:jump#=1
return
Rem Control Character
character:
inc y#,pgrav#
dec pgrav#,grav#
if get static collision hit(ox#-s#,oy#-s#,oz#-s#,ox#+s#,oy#+s#,oz#+s#,x#-s#,y#-s#,z#-s#,x#+s#,y#+s#,z#+s#)
dec x#,get static collision x()
dec y#,get static collision y()
dec z#,get static collision z()
if get static collision y()<0
pgrav#=0
jump#=0
endif
endif
con=0
if object collision(1,0)>1
obj#=object collision(1,0)
if objtype#(obj#)=0 and way#<>0 then gosub collision
if objtype#(obj#)=1 then gosub stairs
if objtype#(obj#)=2 then gosub platform
endif
if y#<-200 then x#=0:y#=30:z#=0:a#=0
position object 1,x#,y#,z#
yrotate object 1,a#
return
Rem Control Collision With Plains
collision:
ca#=object angle y(obj#)
da#=wrapvalue(a#-ca#)
if da#>270 or da#<90 then ca#=wrapvalue(ca#+180)
while object collision(1,obj#)=1
x#=newxvalue(x#,ca#,1*way#)
z#=newzvalue(z#,ca#,1*way#)
position object 1,x#,y#,z#
endwhile
gosub getcollision
if repeat=1 then goto collision
x#=newxvalue(x#,wrapvalue(ca#+180),1*way#)
z#=newzvalue(z#,wrapvalue(ca#+180),1*way#)
return
getcollision:
if object collision(1,0)>1
obj#=object collision(1,0)
repeat=1
else
repeat=0
endif
return
Rem Control Collision With Stairs
stairs:
while object collision(1,obj#)<>0
y#=y#+1
position object 1,x#,y#,z#
endwhile
y#=y#-1
if y#>oy#+50 then x#=ox#:y#=oy#:z#=oz#
pgrav#=0
jump#=0
return
platform:
dec x#,get object collision x()
dec y#,get object collision y()
dec z#,get object collision z()
dec y#
pgrav#=0
jump#=0
con=1
return
Rem Control Camera
camera:
cx#=curvevalue(newxvalue(x#,a#,camposx#),cx#,5)
cy#=curvevalue(y#+camposy#,cy#,2)
cz#=curvevalue(newzvalue(z#,a#,camposz#),cz#,5 )
position camera cx#,cy#,cz#
point camera x#,y#,z#
return
plat:
opx#=object position x(2)
opz#=object position z(2)
if object position x(2)>=1700 then dir#=-1
if object position x(2)<=550 then dir#=1
move object 2,4*dir#
px#=object position x(2)
pz#=object position z(2)
if con=1 then x#=x#+px#-opx#:z#=z#+pz#-opz#
return
Rem Setup Variables and Arrays For Program Attributes
variables:
x#=0:y#=20:z#=0:a#=0:s#=20
camposx#=-200:camposy#=100:camposz#=-200
walkspd#=15:turnspd#=3
jumppower#=10
grav#=1:pgrav#=0
way#=1
dim objtype#(1000)
return
Rem Make Character
setup:
make object cylinder 1,s#*2
yrotate object 1,90
fix object pivot 1
make object collision box 1,-20,-20,-20,20,20,20,1
return
Rem Setup Scenery
scenery:
bc=makeblock(1000,20,1000,0,0,0)
makestaticblock(1000,20,1000,0,0,0,bc)
objtype#(51)=makestairs(51,0.0,10.0,440.0,400.0,100.0,600.0,10)
make object cube 2,100:position object 2,550,-40,0:yrotate object 2,90
make object collision box 2,-50,-50,-50,50,50,50,0:objtype#(2)=2
make object plain 5,500,200
yrotate object 5,45
return
Rem Make box objects
function makeblock(sx,sy,sz,px,py,pz)
inc blockcount
make object box blockcount+100,sx,sy,sz
position object blockcount+100,px,py,pz
endfunction blockcount
Rem Texture box objects
function textureblock(t,tx,ty,blockcount)
texture object blockcount+100,t
scale object texture blockcount+100,tx,ty
endfunction
Rem Colour box objects
function colorblock(red,grn,blu,blockcount)
color object blockcount+100,rgb(red,grn,blu)
endfunction
Rem Make static objects
function makestaticblock(sx,sy,sz,px,py,pz,blockcount)
make static object blockcount+100
make static collision box px-sx/2,py-sy/2,pz-sz/2,px+sx/2,py+sy/2,pz+sz/2
delete object blockcount+100
endfunction
Rem Make stairs to walk up
function makestairs(objnum,px#,py#,pz#,sx#,sy#,sz#,numstairs,tex)
sl#=sqrt(sy#^2+sz#^2)
rota#=sy#/sz#
rot#=atan(rota#)
make object plain objnum,sx#,sl#
xrotate object objnum,wrapvalue(90-rot#)
position object objnum,px#,py#+sy#/2,pz#+sz#/2.0
hide object objnum
objtype#=1
stepw#=sx#
stepl#=sz#/(numstairs+1)
steph#=sy#/(numstairs+1)
for stair=1000 to 999+numstairs
make object box stair,stepw#,steph#,stepl#
position object stair,px#,sh#+steph#*1.5+steph#*(stair-1000),(pz#+stepl#/2)+stepl#*(stair-999)
texture object stair,tex
make static object stair
delete object stair
next stair
endfunction objtype#
Yum! Yum! Yum! Yum!