10. Terrain
Time to modify the flat plane into hills and valleys using a special grayscale heightmap! Creating terrain is a lot easier than you might think. The commented code should provide sufficient explanation or you can use the built-in Blitz HELP files and tutorials for further elaboration.

You can create your own terrain heightmap with any paint program that has a spray paint tool. The heightmap image should be square, a power of 2 (64 x 64, 512 x 512, etc), and grayscale (white is the highest peak, black is the lowest valley, shades of gray are in between.

If you haven't already downloaded the tutorial files do so now, unzip to your desktop and OPEN up lesson10.bb, functions10.bb, and loadworld10.bb (below) and RUN / LAUNCH the lesson10.bb program by pressing the ROCKET ICON

and you should see this...

Here's the CODE (NEW CODE is BOLD) with commented explanations!

No new code added here!


Function object_key_control( obj )
   If run_snd Then run_vol#=.5 Else run_vol#=0
   ; Make sure player is always on Terrain
   objx#=EntityX(obj) : objz#=EntityZ(obj)
   PositionEntity obj, objx, TerrainY( land,objx,0,objz ), objz

End Function
Function MoveCharacters(target)
    ; Make sure characters are always on Terrain
   PositionEntity Character\ID, objx, TerrainY( land,objx,0,objz ), objz

End Function
Function LoadRandomSprites(sprite$, total, x1, x2, z1, z2)
   ; Make sure trees are always on Terrain
   PositionEntity copied_sprite, objx, TerrainY( land,objx,0,objz ), objz

   FreeEntity temp_sprite
End Function



Global land = LoadTerrain( "terrain_hmap.jpg" )
tex_terrain = LoadTexture( "terrain_tex.jpg" )
ScaleTexture tex_terrain, 10, 10
EntityTexture land, tex_terrain
PositionEntity land,-512, -8, -512
ScaleEntity land, 2, 25, 2

; Remove Plane code now that we have terrain!
;ScaleTexture texture1, 10, 10
;EntityTexture plane1,texture1

For C=1 To 3
   Character\pt1 = CreatePivot() : Character\pt2 = CreatePivot()

   ; Adjust Path Endpoints to Terrain Level
   PositionEntity Character\pt1, X, TerrainY( land, X ,0, Z ), Z
   PositionEntity Character\pt2, X2, TerrainY( land, X2 ,0, Z2 ), Z2


Replace the current terrain heightmap and texture with ones of your own design!
FREE Textures HERE or in the Blitz3D example sub-folders!

NEXT : Lesson 11 - Mesh