a simple height map can be used to create different levels from one matrix such as this DB Classic v1.13 code:
`set screen properties
set display mode 1024,768,16
sync on
sync rate 0
hide mouse
fog on
fog color rgb(0,0,0)
fog distance 15000
`input primary file name
set cursor ((screen width()/2)/100)*75,screen height()/2
input "Please enter the image name: ",imageName$
label$=imageName$+":"
fileName$=imageName$+".dat"
imageName$=imageName$+".bmp"
cls
`load bump map
load bitmap imageName$,1
imageX=bitmap width()
imageY=bitmap height()
get image 1,0,0,imageX,imageY
set current bitmap 0
delete bitmap 1
paste image 1,0,0
`matrix constants
matrixNumber=1
tileSize=imageX-1
matrixSizeX=(imageX*tileSize)*4
matrixSizeZ=(imageY*tileSize)*4
dim heightMap(tileSize,tileSize)
center text screen width()/2,screen height()/2,"Processing..."
`read image data into heightMap()
for a=0 to tileSize
for b=0 to tileSize
heightMap(a,b)=int(point(a,b)/39000)
next b
next a
`make matrix
make matrix matrixNumber,matrixSizeX,matrixSizeZ,tileSize,tileSize
`terraform matrix using heightMap()
for c=0 to tileSize
for d=0 to tileSize
set matrix height matrixNumber,c,d,heightMap(c,d)
next d
next c
update matrix matrixNumber
`make file
if file exist(fileName$) then delete file fileName$
open to write 1,fileName$
for e=0 to tileSize
for f=0 to tileSize
write word 1,heightMap(e,f)
next f
next e
close file 1
`get 3d scene ready
backdrop on
color backdrop rgb(0,0,0)
`camera constants
yangle=1
rotationSpeed#=1
camDist#=-2000
do : `#############################################################
`print HUD
text 0,0,"Height data wrote to file: '"+fileName$+"'"
text 0,20,"Hold the left mouse button and move left and right to rotate camera."
text 0,40,"Hold the right mouse button and move up and down to zoom camera."
center text screen width()-100,5,"Frames per second: "+str$(screen fps())
`camera movement
if mouseclick()=1
yangle#=wrapvalue(curvevalue(yangle#+(mousemovex()*3),yangle#,10))
xangle#=wrapvalue(curvevalue(xangle#+(mousemovey()*3),xangle#,10))
else
yangle#=wrapvalue(curvevalue(yangle#+rotationSpeed#,yangle#,10))
endif
if mouseclick()=2
camDist#=curvevalue(camDist#-(mousemovey()*30),camDist#,10)
endif
position camera matrixSizeX/2,1000,matrixSizeZ/2
point camera matrixSizeX/2,1000,matrixSizeZ/2
yrotate camera curvevalue(yangle#,yangle#,1)
xrotate camera curvevalue(xangle#,xangle#,1)
move camera camDist#
point camera matrixSizeX/2,10,matrixSizeZ/2
sync
loop : `###########################################################
`FUNCTIONS --------------------------------------------------------
useage:
put a 50x50 grayscale .bmp file in the same folder as this code then run the code. When the code is executed enter the filename WITHOUT the suffix (enter 'level1' for 'level1.bmp' file!) then hit enter, this will generate the .dat file for that level which can be loading in your program again using this code:
`reads data from dat file
function terraForm(fileName$)
`matrix constants
matrixNumber=1
tileSize=49
matrixSizeX=6400
matrixSizeZ=6400
`create 2D height array
dim heightMap(tileSize,tileSize)
`read data into heightMap()
open to read 1,"levels/"+fileName$
for a=0 to tileSize
for b=0 to tileSize
read word 1, heightData
heightMap(a,b)=heightData/2
next b
next a
close file 1
`terraform matrix using heightMap()
for c=0 to tileSize
for d=0 to tileSize
set matrix height 1,c,d,heightMap(c,d)
next d
next c
update matrix 1
endfunction
easy!
![](/images/smilies/happy.gif)
The grayscale levels in the .bmp file determine the terrain height. i.e. if this image is used
![](http://www.garyw.uklinux.net/level1.bmp)
you get a 3d maze terrain!
P.S. this code is very old so it may need a little tweaking, try it and find out
![](/images/smilies/wink.gif)
i know that it acts a little strange in DBPro
What the flame does not consume, consumes the flame.
------------------------------------------------------------------------
AMD XP2100+, Geforce4Ti 4400, 512Mb DDR, Abit KX7, WinXP Home