This is something I made kinda quick after I saw Ric’s post on clouds. I used his code to make the clouds, hopefully this will help someone make terrain of their own.
You could export the height array to a bmp or other file to get a height map if you wanted.
Ric's post
http://forum.thegamecreators.com/?m=forum_view&t=79448&b=6
The code
`Made by New Guy
`---------------
`basic setup
sync on
fog on
fog distance 750
fog color rgb(100,100,250)
color backdrop rgb(100,100,250)
global SyncRateNum#
global SyncTime
`create the ground
Create_LandMatrix(1)
`setup the cloud array and create the clouds
type CloudInfo
Obj
Height
endtype
cAmount = 100
dim Clouds(cAmount) as CloudInfo
Create_Clouds(cAmount)
`setup camera movement
type CamInfo
Height#
endtype
global Camera as CamInfo
Camera.Height# = 10
`main loop
do
Camera()
Move_Clouds()
text 0,0,str$(screen fps())
`figure out the syncrate multiplyer
SyncRateNum# = (timer()-SyncTime)/33.3333
SyncTime = timer()
sync
loop
function Move_Clouds()
for CurCloud = 1 to array count(Clouds(0))
`move and position the cloud above the ground
cXpos# = object position x(Clouds(CurCloud).Obj)
cZpos# = object position z(Clouds(CurCloud).Obj)
cYpos# = Clouds(CurCloud).Height+get ground height(1,cXpos#,cZpos#)
position object Clouds(CurCloud).Obj,cXpos#,cYpos#,cZpos#-0.5*SyncRateNum#
`reset its position if it goes off the map
if object position z(Clouds(CurCloud).Obj) < -200
Clouds(CurCloud).Height = rnd(100)+100
position object Clouds(CurCloud).Obj,rnd(2000),Clouds(CurCloud).Height,rnd(2000)+200
endif
next CurCloud
endfunction
function Create_Clouds(cAmount)
`create a cloud image
CloudImage = Get_FreeImg()
Create_CloudImage(CloudImage)
`create the cloud objects
for CurCloud = 1 to cAmount
`rember the ID
Clouds(CurCloud).Obj = Get_FreeObj()
`make the plain
make object plain Clouds(CurCloud).Obj,rnd(50)+100,rnd(50)+100
Clouds(CurCloud).Height = rnd(100)+100
position object Clouds(CurCloud).Obj,rnd(2000),Clouds(CurCloud).Height,rnd(2000)
`rotate it correctly
xrotate object Clouds(CurCloud).Obj,90
fix object pivot Clouds(CurCloud).Obj
`texture it
texture object Clouds(CurCloud).Obj,CloudImage
ghost object on Clouds(CurCloud).Obj,0
disable object zwrite Clouds(CurCloud).Obj
`set object light Clouds(CurCloud).Obj,0
next CurCloud
endfunction
function Create_CloudImage(cloudimage)
`create the cloud texture
TempBmp = Get_FreeBmp()
create bitmap TempBmp,50,50
ink rgb(255,255,200),0
Thickness = 1000
for x=1 to Thickness
ang=rnd(360)
rad=rnd(20)
box 25+sin(ang)*rad,25+cos(ang)*rad,rnd(3)+25+sin(ang)*rad,rnd(3)+25+cos(ang)*rad
next x
blur bitmap TempBmp,4
get image cloudimage, 0, 0, 50, 50
delete bitmap TempBmp
endfunction cloudimage
function Create_LandMatrix(MatrixNum)
GroundImg = Get_FreeImg()
Create_GroundImage(GroundImg)
`rember the heights
Dim LandHeights#(50,50)
`make the matrix
make matrix MatrixNum,2000,2000,50,50
prepare matrix texture MatrixNum,GroundImg,1,1
`setup the varables to make the ground heights
NumCenters = 75
MaxCenterHeight = 30
`set this to 180 or 270 (try 360 and 5-10 centers for a cool effect)
CenterSinVal = 270
CenterRadius = 400
`make each center
for Center = 1 to NumCenters
`give it a random position/height
cXpos = rnd(2000)
cYpos = rnd(2000)
cHeight = rnd(MaxCenterHeight)
`go through all the matrix tiles
for mXtile = 0 to 50
for mYtile = 0 to 50
`calculate the dist form center
Dist# = sqrt((cXpos-mXtile*20)^2+(cYpos-mYtile*20)^2)
`if it is close to the center
if Dist# < CenterRadius
`get a percent based on dist
Pcnt# = sin(((CenterRadius-Dist#)/(CenterRadius+0.0))*CenterSinVal)
`add to the existing height
mTileHeight = LandHeights#(mXtile,mYtile)
LandHeights#(mXtile,mYtile) = (cHeight*Pcnt#)+mTileHeight
endif
next mYtile
next mXtile
next Center
for mXtile = 0 to 50
for mYtile = 0 to 50
`go through a final time and set the heights
set matrix height MatrixNum,mXtile,mYtile,LandHeights#(mXtile,mYtile)
next mYtile
next mXtile
update matrix MatrixNum
endfunction
function Create_GroundImage(ImgNum)
TempBmp = Get_FreeBmp()
create bitmap TempBmp,100,100
cls RGB(128,64,0)
`draw the dirt
for X = 0 to 100 step 10
for y = 0 to 100 step 10
`make the box a random shade of brown
Pcnt# = rnd(100)/100.0
ink RGB(150*Pcnt#,100*Pcnt#,0),0
box X,Y,X+10,Y+10
next y
next x
`go through twice and make shades of green for grass
for Num = 1 to 2
for X = -10 to 100
for y = -10 to 100
`get a shade
ink RGB(0,rnd(100)+50,0),0
inc sin#
box X,Y,X+(sin(sin#)*2)*(rnd(7)+1),Y+(cos(sin#)*2)*(rnd(7)+1)
next y
next x
blur bitmap TempBmp,2
next Num
`save the image
get image ImgNum,0,0,100,100
delete bitmap TempBmp
endfunction
`get the first open ID
function Get_FreeBmp()
repeat
inc BmpID
until Bitmap exist(BmpID) = 0
endfunction BmpID
function Get_FreeImg()
repeat
inc ImgID
until Image exist(ImgID) = 0
endfunction ImgID
function Get_FreeObj()
repeat
inc ObjID
until Object exist(ObjID) = 0
endfunction ObjID
`camera controls
function Camera()
CameraAngleY# = Camera angle y()
CameraAngleX# = Camera angle x()
OldCamAngleY# = CameraAngleY#
OldCamAngleX# = CameraAngleX#
CameraAngleY# = WrapValue(CameraAngleY#+MousemoveX()*10)
CameraAngleX# = WrapValue(CameraAngleX#+MousemoveY()*10)
Rem Control input for camera
X# = camera position X()
Y# = camera position Y()
Z# = camera position Z()
If Upkey()=1
X# = Newxvalue(X#,Wrapvalue(CameraAngleY#),8*SyncRateNum#)
Z# = Newzvalue(Z#,Wrapvalue(CameraAngleY#),8*SyncRateNum#)
Endif
If Downkey()=1
X# = Newxvalue(X#,Wrapvalue(CameraAngleY#),-8*SyncRateNum#)
Z# = Newzvalue(Z#,Wrapvalue(CameraAngleY#),-8*SyncRateNum#)
Endif
If Leftkey()=1
X# = Newxvalue(X#,Wrapvalue(CameraAngleY#-90),5*SyncRateNum#)
Z# = Newzvalue(Z#,Wrapvalue(CameraAngleY#-90),5*SyncRateNum#)
Endif
If Rightkey()=1
X# = Newxvalue(X#,Wrapvalue(CameraAngleY#+90),5*SyncRateNum#)
Z# = Newzvalue(Z#,Wrapvalue(CameraAngleY#+90),5*SyncRateNum#)
Endif
Yrotate camera CurveAngle(CameraAngleY#,OldCamAngleY#,24)
Xrotate camera CurveAngle(CameraAngleX#,OldCamAngleX#,24)
`set the y to the ground height
Y# = get ground height(1,X#,Z#)+Camera.Height#
Position Camera X#,Y#,Z#
endfunction
Its fairly simple, but any comments would be appreciated
Remember remember the fifth of November. The gunpowder treason and plot. I know of no reason why the gunpowder treason should ever be forgot.