Simple code for recording and playing back your walkthroughs
Stores to arrays and replays from arrays
it only considers y cam turning as to camera angle
Rem Project: Camera Record and Playback
Rem Created: 06/2005
Rem By Scorpyo
Top:
Rem ***** Main Source File *****
set display mode 800,600,16
hide mouse
sync on
backdrop on
gosub Vars1
gosub Setupland1
gosub setambient
gosub makeobjects
gosub Character
set global collision off
sync rate 50
set camera range 10,40000
sync
Code:
do
if playflag=0 then gosub Playercontrol
gosub Printdata
x#=newxvalue(x#,a#,s#)
z#=newzvalue(z#,a#,s#)
rem --------------
if inkey$()="r" then recordflag=0:playflag=0:a$="RECORDING !!!"
if inkey$()="p" and arrayloaded=1 then playflag=1:s#=0:a$="PLAYBACK"
if inkey$()="p" and arrayloaded=0 then a$="RECORDING NOT PERFORMED"
if recordflag=0 then gosub Playercontrol:gosub camrecord:gosub update_camera:gosub camera_controls
if playflag=0 then gosub update_camera:gosub camera_controls
if arraysaved=1 and arrayloaded=0 then gosub loadcamplay
if playflag=1 then gosub camplay
rem --------------
h#=get ground height(1,x#,z#)
position object 9999,x#,h#+5,z#
yrotate object 9999,a#
rem Update screen
sync
loop
Setupland1:
make matrix 1,landsize,landsize,grid,grid
rem seed for matrix randomize
randomize 1
randomize matrix 1,mtxrandomize
update matrix 1
return
setambient:
rem Create fog and ambience
set ambient light 60
if fog available()=1
fog on
fog distance 20000
fog color rgb(150,150,255)
endif
return
rem make and position cubes
makeobjects:
for n=1 to 50
make object cube n,500
xpos#=rnd(40000):zpos#=rnd(40000)
position object n,xpos#,get ground height(1,xpos#,zpos#)+250,zpos#
next n
return
rem ******** VARIABLES ******
Vars1:
rem
mtxrandomize=300
landsize=40000
grid=40
rem **Player Start position**
x#=landsize/2
z#=landsize/2
oldx#=0
oldz#=0
s#=0
rem initial cam settings
camdist=-500
camhgt=200
camrot=0
camlen=200
cx#=0
cy#=0
cz#=0
dim cameraplayx(1000)
dim cameraplayy(1000)
dim cameraplayz(1000)
dim cameraangley(1000)
count=0
recordflag=1
playflag=0
arraysaved=0
arrayloaded=0
choose=0
a$="PRESS R FOR RECORDING OR P FOR PLAYBACK"
return
rem ***** PLAYERCONTROL *****
Printdata:
set cursor 0,0
set text opaque
rem debug check
print "Polygons=",statistic(1)
print "Fps=",screen fps()
print "x#=",x#
print "z#=",z#
print "a#=",a#
print "h#=",h#
print "playflag=",playflag
print "recordflag=",recordflag
print
print "Use arrow keys for moving"
print
print a$
print "count=",count
return
Playercontrol:
rem ****Character walk ****
if upkey()=1 and s#<12 then s#=s#+2
if downkey()=1 and s#>-12 then s#=s#-2
if leftkey()=1 then a#=wrapvalue(a#-4)
if rightkey()=1 then a#=wrapvalue(a#+4)
position listener x#,50,z#
rem stop if "-"
if inkey$()="-" then s#=0.0
if inkey$()="ù" then s#=60.0
return
rem ****BUILD PLAYER****
rem object 9999
Character:
rem make cone
make object cone 9999,100
scale object 9999,80,100,140
rem point tip forward
xrotate object 9999,60
set object cull 9999,0
return
rem **********CAMERA*****************
camera_controls:
if inkey$()="<" then camrot2=wrapvalue(camrot2)+2
if inkey$()="z" then camdist=camdist+2
if inkey$()="x" then camdist=camdist-2
if inkey$()="b" then camrot=camrot+2
if inkey$()="n" then camrot=camrot-2
if inkey$()="c" then camhgt=camhgt+2
if inkey$()="v" then camhgt=camhgt-2
if inkey$()="m" then camlen=camlen+2
if inkey$()="," then camrot = 180
if inkey$()="." then gosub Resetcam
return
rem camera update
update_camera:
rem Position camera to the back of the character
ca#=wrapvalue(a#+camrot)
cx#=newxvalue(x#,ca#,camdist)
cz#=newzvalue(z#,ca#,camdist)
cy#=get ground height(1,x#,z#)
position camera cx#,cy#+camhgt,cz#
rem Point camera at object
point camera x#,cy#+camhgt,z#
return
rem camera reset
Resetcam:
camdist=-500
camhgt=200
camrot=0
camlen=200
return
camrecord:
cameraplayx(count)=camera position x()
cameraplayy(count)=camera position y()
cameraplayz(count)=camera position z()
cameraangley(count)=camera angle y()
if count>999
save array "cameraplayx.arr",cameraplayx(0)
save array "cameraplayy.arr",cameraplayy(0)
save array "cameraplayz.arr",cameraplayz(0)
save array "camangle.arr",cameraangley(0)
recordflag=1:arraysaved=1:count=0:s#=0
a$="PRESS R FOR RECORDING OR P FOR PLAYBACK"
endif
count=count+1
return
loadcamplay:
if arraysaved=1
load array "cameraplayx.arr",cameraplayx(0)
load array "cameraplayy.arr",cameraplayy(0)
load array "cameraplayz.arr",cameraplayz(0)
load array "camangle.arr",cameraangley(0)
arrayloaded=1:a$="PRESS R FOR RECORDING OR P FOR PLAYBACK"
endif
return
camplay:
if count>999 then playflag=0:count=0:a$="PRESS R FOR RECORDING OR P FOR PLAYBACK"
cx#=cameraplayx(count)
cy#=cameraplayy(count)
cz#=cameraplayz(count)
ca#=cameraangley(count)
position camera cx#,cy#,cz#
yrotate camera ca#
inc count
return
end