It's not easy to get a topic to be
stickied. And people arn't going to write a page of directions just because you ask them... but, I'll try to help you out anyways...
First... If you want to make an RPG, you will have to know how to use the Matrix commands...
Matrices (Terrain's)
This is in my opinion the most complicated set of commands so far. However once you have learnt how to use these you will be able to create some very nice terrain's.
A matrix is a grid of points in 3d space that once connected make up a 3d object that can be used for terrain's. There are lots of matrix commands, and whilst the basic ones are relatively simple it is hard to create nice terrain's without having a decent editor. Changing the terrain through code is not really feasible unless you want mathematically accurate terrain's, or randomly created worlds (again using math's).
If you want to create your own matrices I recommend MatEdit (I will be using it in the 3d game tutorials). This does most of the hard work for you so that you can concentrate on getting your game to work.
However to give you a bit of background here are the simpler matrix commands (for more information look in the DB help files).
Creating your Matrix
make matrix id, width, depth, xTiles, zTiles
This command creates your matrix. The width and depth are the values used for the size of the terrain. The xTiles, and zTiles are the number of divisions your matrix will have. The higher the number of tiles the more detailed your matrix will be, however using more tiles makes your game run slower. You have to be very careful to create a nice looking terrain that will run at an acceptable speed.
width=100
depth=50
xTiles=20
zTiles=15
make matrix 1,width,depth,xTiles,zTiles
randomize matrix id, maxHeight#
This lets you quickly create random matrix (you have to make it first). All this does is randomize the heights of the matrix which does not look particularly stunning but it does save some time if you just want a very simple landscape.
randomize matrix 1,10
set matrix height id, x, z, height
This is the command that you should use to create a nice detailed matrix. This gives you exact control over how high each of the vertices is.
The counting for the x and z values start at 0 and goes up to the xTiles and zTiles values you used when creating the terrain.
for xTile=0 to XTiles
for zTile=0 to ZTiles
height=rnd(20)
set matrix height id,xTile,zTile,height
next zTile
next xTile
update matrix id
Once you have finished doing things to the matrix you use this command to update everything that has been changed.
Width=100
depth=50
xTiles=20
zTiles=15
make matrix 1,width,depth,xTiles,zTiles
randomize matrix 1,10
update matrix 1
Texturing the matrix
So far the matrix has been a wireframe object. To make it look more interesting it can be textures. The way matrices are textured is different to the way standard objects are textured. So that you can have a varied landscape DarkBASIC lets you split a single texture into a number of smaller textures. You can then texture the individual tiles of the matrix with these small textures.
So you can take a texture image that looks like this:
-----------------
| | |
|grass |water |
| | |
-----------------
| | |
|sand |lava |
| | |
-----------------
...then texture a matrix with it.
When texturing the matrix you must remember that the tile numbers start from 1 and go up to the maximum number of tiles you specified when creating the terrain.
prepare matrix texture id, image, across, down
Before you can set the values of the different texture tiles you must tell DarkBASIC what texture you are using and how many tiles it has. So you have to first load the image then use the 'Prepare matrix texture' command. This tells DarkBASIC what image is associated with what matrix and how many texture tiles this image has.
set matrix tile id, xTile, zTile, textureTile
This simply textures the specified tile (xTile, zTile) of the specified matrix (id) with the specified texture tile (textureTile).
sync on
hide mouse
`---------------
`create a matrix
`---------------
`the matrix will be 100 units square and be split up into 100 squares (10*10)
make matrix 1,100,100,10,10
`set the matrix heights
`I am going to use two for loops to do this
`the first loops through the xPoints, the second through the zPoints
for xPoint=0 to 10
for zPoint=0 to 10
`create a sinewave matrix
`I just made the following bit up and it looked nice
`you can just as easily use your own numbers/ math's to create terrain's
`you could also use a loop like this to read values you have saved from
`a text file created by an editor
height=(sin(xPoint*36)+cos(zPoint*36))*5
set matrix height 1,xPoint, zPoint, height
next zPoint
next xPoint
`----------------------
`set the matrix texture
`----------------------
`load matrix texture
load image "floor1.bmp",1
`prepare the matrix texture
prepare matrix texture 1, 1, 2,2
`loop through matrix tiles
for xTile=0 to 9
for zTile=0 to 9
`set the matrix tile texture
`the texture is a random value
set matrix tile 1,xTile,zTile,rnd(3)+1
next zTile
next xTile
`update the matrix after it has been changed
update matrix 1
`position the camera so that it has a good view
Position camera 50,50,-50
point camera 50,25,50
`main loop
do
`update the screen
sync
loop
Then you will have to make a player to walk around the matrix. This can be a 3-D object or just the camera. I'd recommend a camera if you don't have any animated 3DModels on hand...
Camera Controls
The camera is the thing that you see the 3d world through. You may not realise it but this is what you have been using for most of the previous examples to look at your world.
To make your games more fun you want to be able to move and rotate the camera. This is done very easily, in fact you have almost been doing it already. The commands for moving and positioning the camera are almost the same as for moving an object. Only instead of using the command 'position object' you would use 'position camera'
position camera xPos#, yPos#, zPos#
This command positions the camera at the specified x, y, and z coordinates. This command does not affect the direction the camera is pointing so you may not see what you want to look at. To do this you need to use one of the following commands.
sync on
hide mouse
`make something to look at
for sphereNumber=1 to 20
make object sphere sphereNumber,rnd(10)+5
position object sphereNumber,rnd(100),rnd(100),rnd(100)
next sphereNumber
`set default values
xPos=50
yPos=50
zPos=0
do
`do keyboard input
if upkey()=1 then yPos=yPos+1
if downkey()=1 then yPos=yPos-1
if rightkey()=1 then xPos=xPos+1
if leftkey()=1 then xPos=xPos-1
`position the camera
position camera xPos,yPos,zPos
`update the screen
sync
loop
rotate camera xAngle#, yAngle#, zAngle#
This command rotates the camera to the specified angle(s). The angles must be numbers between 1 and 360. You should use the wrapvalue() command to ensure that the numbers are OK to use.
Sync on
hide mouse
`make something to look at
for sphereNumber=1 to 20
make object sphere sphereNumber,rnd(10)+5
position object sphereNumber,rnd(100),rnd(100),rnd(100)
next sphereNumber
`position camera in the middle of the spheres
position camera 50,50,50
`set default values
xAng=0
yAng=0
zAng=0
do
`do keyboard input
if upkey()=1 then xAng=wrapvalue(xAng+1)
if downkey()=1 then xAng=wrapvalue(xAng-1)
if rightkey()=1 then yang=wrapvalue(yang+1)
if leftkey()=1 then yang=wrapvalue(yang-1)
`rotate the camera
rotate camera xAng,yang,zAng
`update the screen
sync
loop
point camera xPos#, yPos#, zPos#
The use of this command is simple. What it does is point the camera at a point in 3d space. This is very useful for keeping your character in screen. It could be used for something like a Resident Evil style camera, where you have a fixed camera that points at the character at all times.
Any other commands?
There are some other commands that can make the camera even more useful than it is already.
Set camera to follow
This is a built in chase camera (like in Tomb Raider). It has a number of properties that you can set, and it makes camera coding even easier than it is already.
Set camera range
This changes the amount of data drawn onto the screen. It can be used to speed up your games. Everything that is further from the camera than the maximum range is not drawn which obviously makes the game run faster/ smoother. If you use this in combination with the fog commands you will be able to create a fairly convincing world.
Set camera view
If you wanted to draw the camera to only part of the screen then this would be the command you would use.
Set camera fov
FOV stands for Field of View. This command lets you do all sorts of fancy effects. The most common ones being sniper zooms in first person shooters, or a camera zoom in racing games to make the action seem faster than it is.
You can think of the camera as an invisible eye used to view your scene. The camera can be positioned, rotated, and moved much like any 3D object.
Now, you will have to be able to "move" the camera around the matrix...
Sync On
Make Matrix 1,500,500,50,50
Randomize Matrix 1,10
Do
If Upkey()=1 Then Move Camera 1
If Downkey()=1 Then Move Camera -1
If Leftkey()=1 Then Turn Camera Left 3
If Rightkey()=1 Then Turn Camera Right 3
Position Camera Camera Position X(),Get Ground Height(1,Camera Position X(),Camera Position Z())+5,Camera Position Z()
Sync
Loop
Position Camera Camera Position X(),Get Ground Height(1,Camera Position X(),Camera Position Z())+5,Camera Position Z() ...will allow the camera to move along the surface of the matrix as if it were walking on ground...
Thats all I have Time for... Well... I hope I helped...
PS: I was not the one to write these tutorials but they helped me alot when I was new... I would like to thank whoever wrote these.
Previously known as "Game_Creator".
The question is, why am I talking to myself? ...... And more importantly, why am I waiting for a reply?