Open DarkBASIC (Start Menu -> Programs -> DarkBASIC -> DarkBASIC v1.13)
Open your project file from File->Open Menu. (The one you created in last chapter. DarkBASIC/Projects/Proj1/Proj1.dba)
You'll see some code, and after that a line stating
`Your Code Starts From Here
If you have noticed, those code has a line #include "LoadMatrix.dba"
(Remember the one we exported using MatrixRebuild?)
Now, let's write some code of our own. Let's say load the matrix we have made. (Proj1.MDF & _Proj1.BMP)
Loading Matrix in your Game
For that, insert a command after the line `Your Code Starts From Here
Is that it? Yes! Simple?
Now let's Compile the code using F4 and run the code using F5
We can see our matrix, but the program is terminated because we haven't added anything else.
Now you must keep one thing in mind. In general programming, we don't use infinite loop much often, but in Game Programming, all the main tasks are in infinite loop because the program has to check constantly which key is being pressed and act accordingly. To terminate this loop we use F12 (or the Escape Key if the game is complete and we are running it from an EXE).
Another thing. We must refresh the screen after each time this loop has been executed. Why? Suppose we are pressing FWD key, and your player is moving Forward. Now if we don't refresh the screen, your player will leave its trail, means he will be present at both positions, the old one the new one. hence, we will use the following loop as our main (like we use main() in c/c++)
sync on -> we are telling computer that we will refresh the screen ourself, and when we need.
do -> starting of main loop
loop -> end of main loop
... -> commands to be executed - the main logic (like what should be done when player presses a key)
sync -> refreshes the screen
Now our code is like following:
It will load the matrix, and then do nothing. You must use F12 to return to the editor.
Logic can be added using If .. Then ..
(If Something happens Do something)
To understand conditions, we must know variables and operators.
Variable Type Example
We need not define variables. We can use them directly.
i = 10
r# = 2.12
st$ = "Constantin"
Of course, we must declare them if they are array or global variables.
etc. for arrays
etc. if we want to use them globally in our program.
= Equal To
<> not Equal To
> Greater Than
>= Greater Than or Equal To
< Less Than
<= Less Than or Equal To
So, if we want to check whether the value of i is 10 or not, we simply use this code.
i = 0
if i = 10 then status$ = "True" else status$ = "False"
Later on we can use the value of status$ to determine further logic.
In 3D Game, our main logic will be to sort out what to do when a user presses certain key.
There are some in built functions which returns 1 if associated key is being pressed.
Thus, we can work out some kind of logic in our main loop
if upkey() = 1 then CODE FOR MOVING CAMERA FORWARD
if downkey() = 1 then CODE FOR MOVING CAMERA REVERSE
For mouse there is a single command
Which returns 1 for leftclick & 2 for rightclick
So, now we know how to make matrix, load it in our program. We also know how to implement logic. But to move camera, we will need to know some Camera Basics. which will be covered in the next chapter.