footprint by Phaelax21st Jul 2004 14:08
|
---|
Summary Example of how to leave a footprint on terrain Description Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com sync on sync rate 60 autocam off hide mouse randomize timer() `load image "grass.bmp", 1 make matrix 1, 1000, 1000, 40, 40 `prepare matrix texture 1, 1, 1, 1 randomize matrix 1, 200 smooth_matrix(1,2,40,40) update matrix 1 rem footprint make object plain 999,10,10 xrotate object 999,270 fix object pivot 999 DO gosub camera_stuff if spacekey() and flag = 0 flag = 1 make_footprint(1, camera position x(),camera position z()) endif if spacekey() = 0 then flag = 0 sync LOOP REM ========================================================================== REM Parameters: REM matrix number REM X coordinate REM Z coordinate function make_footprint(number as integer, x# as float, z# as float) h1# = get ground height(number, x#, z#) h2# = get ground height(number, x#+2, z#) a# = h2# - h1# b# = 2 angz# = atan(a#/b#) h2# = get ground height(number, x#, z#+2) a# = h2# - h1# angx# = 360 - atan(a#/b#) position object 999, x#, h1#+0.5, z# rotate object 999,angx#,0,angz# endfunction REM ========================================================================== REM Parameters: REM matrix number REM number of iterations REM number of X tiles REM number of Z tiles function smooth_matrix(number as integer, iter as integer, xsegs as integer, zsegs as integer) dim heights#(xsegs, zsegs) rem store original heights for z = 0 to zsegs for x = 0 to xsegs heights#(x,z) = get matrix height(number,x,z) next x next z for t = 1 to iter for z = 0 to zsegs for x = 0 to xsegs count = 0 h1# = 0 h2# = 0 h3# = 0 h4# = 0 h5# = 0 h6# = 0 h7# = 0 h8# = 0 if z < zsegs if x > 0 then h1# = heights#(x-1,z+1) : inc count h2# = heights#(x,z+1) : inc count if x < xsegs then h3# = heights#(x+1,z+1) : inc count endif if x > 0 then h4# = heights#(x-1,z) : inc count if x < xsegs then h5# = heights#(x+1,z) : inc count if z > 0 if x > 0 then h6# = heights#(x-1,z-1) : inc count h7# = heights#(x,z-1) : inc count if x < xsegs then h8# = heights#(x+1,z-1) : inc count endif avg# = (h1#+h2#+h3#+h4#+h5#+h6#+h7#+h8#) / count set matrix height number,x,z,avg# heights#(x,z) = avg# next x next z next t rem delete array undim heights#() endfunction camera_stuff: oldcx#=cx# oldcz#=cz# speed# = 5 if shiftkey() then speed# = 10 if upkey()=1 cx#=newxvalue(cx#,a#,speed#) cz#=newzvalue(cz#,a#,speed#) endif if downkey()=1 cx#=newxvalue(cx#,a#,-speed#) cz#=newzvalue(cz#,a#,-speed#) endif if leftkey()=1 cx#=newxvalue(cx#,wrapvalue(a#-90.0),speed#) cz#=newzvalue(cz#,wrapvalue(a#-90.0),speed#) endif if rightkey()=1 cx#=newxvalue(cx#,wrapvalue(a#+90.0),speed#) cz#=newzvalue(cz#,wrapvalue(a#+90.0),speed#) endif `if shiftkey() then inc cy#, 2 `if controlkey() then dec cy#, 2 a#=wrapvalue(a#+(mousemovex()/3.0)) cxa#=cxa#+(mousemovey()/3.0) if cxa#<-90.0 then cxa#=-90.0 if cxa#>90.0 then cxa#=90.0 cy# = get ground height(1,cx#,cz#) position camera cx#,cy#+50,cz# rotate camera wrapvalue(cxa#),a#,0 RETURN |