Creating a Terrain

One of the quickest ways to create a terrain (or the ground) for your games is to use the programming code called CreateTerrain. This code allows you to create and specify a size for the terrain (again, think of this as the ground) of your game. In this example, we’ll add a terrain to an empty program. Take a basic program:

Graphics3D 640,480
SetBuffer BackBuffer()

Const ESC_KEY = 1

; Create camera
camera=CreateCamera()
; Creating a light
light=CreateLight()
; The following code makes the program run
While Not KeyDown(ESC_KEY)
RenderWorld
Flip
Wend
End

If you ran this program now, you would see only a blank, black screen. We are now going to add the code to create a terrain for this program. Add the following code under the “Creating a Light” section to create the terrain:

; Creating the terrain
ground=CreateTerrain (512)

If you ran this program right now, you’d see nothing because the camera isn’t looking at the terrain (see Figure 9.1). We’ll fix that in a moment, but for now let’s take a closer look at the code we just entered. ground is just the name we are giving to the terrain, CreateTerrain is the code that creates the terrain, and the number in parentheses (512) is how far the terrain extends along the x and z axes.

Figure 9.1. Oh, no! There’s nothing on the screen. That’s okay, the terrain is actually there–it’s just out of the view of the camera.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.34.205