Basic Idea, no fine tuning
rem Generic Matrix Template
rem Player = object 10
set display mode 1024,768,32
SYNC ON
SYNC RATE 60
backdrop on
color backdrop rgb(10,100,100)
autocam off
set global collision off
x#=1000.0:z#=1000.0:a#=0.0:s#=0.0:h#=0.0
cx#=0.0:cy#=0.0:cz#=0.0:ca#=0.0:camght=50
camrot=0:camdist=0:camlen=0
gosub Setupland1
gosub makewalker2
gosub makeobjects
gosub resetcam
do
collx#=x#:collz#=z#
if inkey$()="e" then sync rate 0
if inkey$()="E" then sync rate 60
gosub printdata
gosub camera_controls
gosub update_camera
gosub Playercontrol
gosub checkdistance
gosub checkwall
gosub checkcollision
SYNC
loop
rem -------------ROUTINES--------------------
Setupland1:
rem ground textures
rem create texture
cls rgb(0,100,20)
inkcolor#=rgb(255,255,255)
line 0,0,0,250
line 1,1,1,250
line 2,2,2,250
line 0,0,250,0
line 1,1,250,1
line 2,2,250,2
line 0,0,250,250
line 0,250,250,0
rem next n
get image 2,0,0,250,250
rem Make landscape
landsize=4000:grid=30:mtxrandomize=1
make matrix 1,landsize,landsize,grid,grid
set matrix 1,1,0,0,1,1,1,1
prepare matrix texture 1,2,1,1
randomize matrix 1,mtxrandomize
rem ***********
rem get ground done
update matrix 1
return
Playercontrol:
rem ---- Control Character ----
mymousex=mousemovex()
if mymousex>0 and mouseclick()=0 then a#=wrapvalue(a#+3.0)
if mymousex<0 and mouseclick()=0 then a#=wrapvalue(a#-3.0)
x#=newxvalue(x#,a#,s#)
z#=newzvalue(z#,a#,s#)
h#=get ground height(1,x#,z#)
position object 10,x#,h#+hadd#,z#
yrotate object 10,a#
if upkey()=1 and s#<1.2 then s#=s#+0.02
if downkey()=1 and s#>-1.2 then s#=s#-0.02
if inkey$()="ù" then s#=0.0
if inkey$()="à" then s#=10.0
return
checkdistance:
rem check cube distance with sqrt
for n=100 to 120
xdif#=object position x(n)-x#
zdif#=object position z(n)-z#
pdist#=sqrt(xdif#*xdif#+zdif#*zdif#)
if pdist#<100 then objnum=n:return
next n
objnum=0
collcheck#=0
return
checkwall:
if objnum>0
fromx#=newxvalue(x#,a#,30)
fromz#=newzvalue(z#,a#,30)
rem calculate coords of 500 units ahead spot
tox#=newxvalue(x#,a#,500)
toz#=newzvalue(z#,a#,500)
upper#=intersect object(objnum,fromx#,h#+hadd#+5,fromz#,tox#,h#+hadd#+5,toz#)
lower#=intersect object(objnum,fromx#,h#+hadd#,fromz#,tox#,h#+hadd#,toz#)
below#=intersect object(objnum,x#,h#+10,z#,x#,h#-10,z#)
endif
if upper#=lower# and lower#>0 then text 500,0," WALL HIT !!!"
if upper#=lower# and lower#=0 then text 500,0," "
checkcollision:
if s#>0
if objnum>0
collcheck#=intersect object(objnum,fromx#,h#+hadd#+2,fromz#,tox#,h#+hadd#+2,toz#)
endif
if collcheck#<2 and collcheck#>0 then x#=collx#:z#=collz#:s#=0:hadd#=hadd#+1
endif
if below#=0 and lower#=0 then hadd#=0.0
return
rem -------CAMERA--------
camera_controls:
if inkey$()="z" then camlen=camlen+0.2
if inkey$()="x" then camlen=camlen-0.2
if inkey$()="<" then gosub Resetcam
if inkey$()="n" then camdist=-1000:camhgt=500:camrot=0:set camera range 100,20000:wait 10
if inkey$()="m" then camdist=-3000:camhgt=1000:camrot=0:set camera range 100,20000:wait 10
rem mymousex=mousemovex()
if mymousex>0 and mouseclick()=2 then camrot=camrot+3
if mymousex<0 and mouseclick()=2 then camrot=camrot-3
mymousey=mousemovey()
if mymousey>0 and mouseclick()=1 then camhgt=camhgt+5
if mymousey<0 and mouseclick()=1 then camhgt=camhgt-5
mymousez=mousemovez()
if mymousez>0 then camdist=camdist+10
if mymousez<0 then camdist=camdist-10
if mouseclick()=3 and camrotflag=0 then camrot=180:camrotflag=1:wait 10
if mouseclick()=3 and camrotflag=1 then camrot=0:camrotflag=0:wait 10
return
rem camera update
update_camera:
rem Position camera to the back of the character
if camfollow=0 then point camera x#,cy#+camhgt+camlen,z#:return
ca#=wrapvalue(a#+camrot)
cx#=newxvalue(x#,ca#,camdist)
cz#=newzvalue(z#,ca#,camdist)
cy#=h#+hadd#
position camera cx#,cy#+camhgt,cz#
rem Point camera at object
point camera x#,h#+camhgt+camlen,z#
return
rem camera reset
Resetcam:
set camera range 1,20000
camfollow=1
camdist=-150
camhgt=80
camrot=0
camlen=0
camrotflag=0
return
printdata:
set cursor 0,0
print statistic(1)
print screen fps()
print "x#= ",x#
print "h#= ",h#
print "hadd#= ",hadd#
print "z#= ",z#
print "a#= ",a#
print "s#= ",s#
print "upper#=",upper#
print "lower#=",lower#
print "below#=",below#
print "collcheck#=",collcheck#
return
rem -------------Characters----------------
makewalker1:
make object sphere 10,20
return
makewalker2:
make object cone 10,30
scale object 10,100,200,100
xrotate object 10,90
fix object pivot 10
return
makeobjects:
cubesize=100
for n=100 to 120
make object cube n,100
xpos=rnd(landsize):zpos=rnd(landsize)
position object n,xpos,cubesize/2,zpos
next n
return
end