Sync On:Sync Rate 0:Autocam Off
Set Camera Range .3,2000
Fog On
Fog Distance 20,1000.0
Set Normalization On
 
Water(5)
Make_Terrain()
 
Make_3DGrass(11)
 
h#=Get Terrain Ground Height(1,500,500)-1
Position Object 11,500,h#,500
grassobj=12
For patch=1 to 20
   Do
      px#=rnd(400)+300:pz#=rnd(400)+300
      py#=Get Terrain Ground Height(1,px#,pz#)
      if py#>8 Then Exit
   Loop
   For i =1 to 30
      Instance Object grassobj,11
      x#=px#+rnd(10):z#=pz#+rnd(10)
      y#=Get Terrain Ground Height(1,x#,z#)-1.2
      Position Object grassobj,x#,y#,z#
      Turn Object Right grassobj,rnd(360)
      inc grassobj
   Next i
Next patch
 
 
Make Object Plain 2,2000,2000
Pitch Object Down 2,90
Texture Object 2,5
Position Object 2,500,5,500
Scale Object Texture 2,4,4
Set Object Emissive 2,rgb(20,20,100)
Set Object Specular 2,rgb(255,255,0)
Set Object Specular Power 2,500
Set Object Fog 2,0
Clone Object 3,2
Position Object 3,500,5.2,500
Set Alpha Mapping On 3,50
Set Object Fog 3,0
 
Make Light 1
Position Light 1,0,200,0
Set Light Range 1,3000
Color Light 1,rgb(255,255,0)
 
 
Position Light 0,0,200,0
 
h#=Get Terrain Ground Height(1,500,500)+1
Position Camera 500,h#,500
 
 
 
Do
   Scroll Object Texture 2,.0002,.0001
   Scroll Object Texture 3,-.0001,-.0002
   `oldx#=Camera Position X():oldy#=Camera Position Y():oldz#=Camera Position Z()
   Control Camera Using Arrowkeys 0,.1,1
   cx#=Camera Position X():cz#=Camera Position Z()
   h#=Get Terrain Ground Height(1,cx#,cz#)+1
 
   if h#<6
      mh#=0
      For i=0 to 360 step 45
         x#=sin(i)*.11+cx#:z#=cos(i)*.11+cz#
         th#=Get Terrain Ground Height(1,x#,z#)
         if th#>mh#
            mh#=th#
            nx#=x#:nz#=z#
         Endif
      Next i
      h#=mh#+1:cx#=nx#:cz#=nz#
   Endif
 
   Position Camera cx#,h#,cz#
   Set Cursor 0,0
   Print Camera Position X()
   Print Camera Position Y()
   Print Camera Position Z()
   Print
   Print Screen FPS()
 
   Sync
Loop
 
End
 
 
`*************************************************
`****************Level 1 Functions****************
`*************************************************
` These functions are intended for direct call or can be called by other functions
 
 
 
Function Make_Terrain()
   Grass(4,4)
   Create_Heightmap()
   If Object Exist(1) then Delete Object 1
   Make Object Terrain 1
   Set Terrain Heightmap 1,"Heightmap.bmp"
   Set Terrain Texture 1,3,4
   Set Terrain Tiling 1,2
   Set Terrain Scale 1,5,.4,5
   Set Terrain Light 1,0,500,0,255,255,100,0
   Build Terrain 1
   Set Object Collision Off 1
   Set Object Specular 1,rgb(255,255,100)
   Set Object Specular Power 1,100
Endfunction
 
 
 
Function Create_Heightmap()
   Ink rgb(0,0,0),0
   Box 0,0,200,200
   For j = 0 to 1
      Splotch(240,100)
      Sprite 1,-1000,0,1
      Set Sprite 1,0,1
      Set Sprite Diffuse 1,255,255,255
      For i = 1 to 40
         Size Sprite 1,100-i*2,100-i*2
         p=Sigmoidal(i,1)*5
         Set Sprite Alpha 1,p
         Paste Sprite 1,j*40+i+rnd(1)+5,j*40+i+rnd(1)+5
      Next i
   Next j
   if file exist("Heightmap.bmp") Then Delete File "Heightmap.bmp"
   Get Image 2,0,0,200,200,1
   Save Image "Heightmap.bmp",2
   Ink rgb(0,10,0),0
   Box 0,0,200,200
   Sprite 1,0,0,2
   Set Sprite Diffuse 1,50,255,50
   Set Sprite Alpha 1,180
   Size Sprite 1,200,200
   Rotate Sprite 1,-90
   Paste Sprite 1,0,200
   Get Image 3,0,0,200,200,0
 
   If Sprite Exist(1) Then Delete Sprite 1
   Ink Rgb(255,255,255),0
Endfunction
 
 
Function Grass(img1,img2)
 
   Ink Rgb(0,90,0),0
   Box 0,0,256,256
   g=0
   Splotch(180,45)
   Do
      Sprite 1,200,200,1
      Set Sprite 1,0,1
      Size Sprite 1,rnd(5)+2,Rnd(5)+2
      Set Sprite Alpha 1,128
      Set Sprite Diffuse 1,0,150,0
      Paste Sprite 1,rnd(256)-2,rnd(256)-2
      g=g+1
      If rnd(300)+300<g Then Exit
   Loop
   Get Image img1,1,1,256,256,0
 
   Ink Rgb(50,200,50),0
   Box 0,0,512,512
   g=0
   Splotch(200,30)
   Do
      Sprite 1,200,200,1
      Set Sprite 1,0,1
      Size Sprite 1,rnd(10)+10,Rnd(10)+10
      Set Sprite Alpha 1,rnd(20)+10
      Set Sprite Diffuse 1,80,180,80
      Paste Sprite 1,rnd(256)-10,rnd(256)-10
      g=g+1
      If rnd(1000)+500<g Then Exit
   Loop
   Get Image img2,1,1,256,256,0
Endfunction
 
Function Water(img1)
 
   Ink Rgb(0,0,200),0
   Box 0,0,511,511
   g=0
   Splotch(180,45)
   Do
      Sprite 1,200,200,1
      Set Sprite 1,0,1
      Size Sprite 1,rnd(5)+2,Rnd(5)+2
      Set Sprite Alpha 1,200
      Set Sprite Diffuse 1,140,150,255
      Paste Sprite 1,rnd(67)-2,rnd(67)-2
      g=g+1
      If rnd(100)+100<g Then Exit
   Loop
   Get Image img1,1,1,64,64,0
Endfunction
 
Function Make_3DGrass(obj)
   Ink 0,0
   Box 0,0,256,256
   Ink Rgb(200,200,200),0
   For i = 25 to 39
      Line 32,0,i,256
   Next i
   Get Image 101,0,0,256,256,0
   Ink 0,0
   Box 0,0,256,256
 
   For i = 1 to 150
      Sprite 101,0,0,101
      Set Sprite 1,0,1
      a#=rnd(40)-20:s#=rnd(30)+20
      Rotate Sprite 101,a#
      Scale Sprite 101,s#
      Set Sprite Diffuse 101,10,Rnd(50)+120,10
      Paste Sprite 101,28+Rnd(200),32+rnd(32)
      Delete Sprite 101
   Next i
   Get Image obj,1,1,255,255,1
   Make Object Plain obj,5,5
   Make Mesh from Object 1,obj
   Add Limb obj,1,1
   Rotate Limb obj,1,0,60,0
   Add Limb obj,2,1
   Rotate Limb obj,2,0,-60,0
   Texture Object obj,obj
   Set Object Transparency obj,3
   Set Object Cull obj,0
   Set Object Light obj,0
   Delete Image 101
   Ink Rgb(255,255,255),0
Endfunction
 
 
 
 
 
`*************************************************
`****************Level 2 Functions****************
`*************************************************
` These functions are not intended for direct call, but to be called by other functions
 
 
Function Sigmoidal(value#,curve#)
   `the sigmoidal formula. Graph this on a spreadsheet to see how it works.
   result#=1.0/(1.0+2.04541^-((value#)/(curve#*.1)))
   `The result# is a value between >0 and <1. Curve is the number standard deviations in a normal distribution.
Endfunction result#
 
`Splotch creates a randomized roundish pattern.
Function Splotch(h,s)
   If Bitmap Exist(2) Then Delete Bitmap 2
   Create Bitmap 2,s,s
   Set Current Bitmap 2
   Lock Pixels
   Ink 0,0
   Box 0,0,s,s
   Ink Rgb(h,h,h),0
   r=s/2-rnd(s/10)
   stp#=s:stp#=20.0/stp#
   For i# = 0.0 to 360.0 step stp#
      x=(sin(i#)*r)+s/2
      y=(cos(i#)*r)+s/2
      line s/2,s/2,x,y
      line s/2+1,s/2+1,x+1,y+1
      line s/2-1,s/2+1,x-1,y+1
      r=r+(Sigmoidal(Rnd(20)-10,5)*3-1)
      if r>s/2 then r=s/2
      m=s/2-15:If m<2 then m=2
      if r<m then r=m
   Next i#
   Unlock Pixels
   Get Image 1,0,0,s,s
   Set Current Bitmap 0
   Delete Bitmap 2
Endfunction