Hi all
After i tried the "My first pong game" tut it inspired me to make a little tut on just some off the things i learned from it but first of all i wanna thank
Chris K [/u].
So thank you for all that stuff you taught me
Now lets start.
This little tut will cover the most basic on how to make a nice and simple control to an 3d object.
*Make the sync setup*
Some of the first things to do is to make the sync setup but first i will explain something about the
sync command :
Sync is acually one of the very inportnent commands and you will need to use it in ETC the main loop. You will always need the
sync command to keep you games running smooth. You need to insert this is you main loop but after all the other stuff it done.
So in every 3D game or 2D game you will need this so lets start the code like this:
The
sync on command tells darkbasic to handle the screen refresh.
Now i have written
sync rate 30 that is a good thing to write it will tell darkbasic to run the screen refreshing at 30 no matter what computer it is running on.
*Making the 3D object*
It is quite simple to make the 3D object lets make a box.
To make a box we use the
MAKE OBJECT BOX command:
MAKE OBJECT BOX object number, x, y, z (I think).
so our code should look like this now:
sync on
sync rate 30
make object box 1,1,1,3
Now the 3d box is just white so lets put some color on it.
For that we use the
COLOR OBJECT object number, color
Remember that in programming language the colors are codes but in dbpro there is an easy way to pick you the color you want without writing the code.
So now the code should look like this:
sync on
sync rate 30
make object box 1,1,1,3
color object 1, RGB(0,255,0)
To get the color picker you just need to right click on the mouse button (In the dbpro editor) then there should stand "RGB color picker" push that button and then just pick a color
.
Now we need to make it so you can try to run the program and we do that on a simple way
We need to use the
DO and
LOOP command to make the main loop.
Now put this into the code Under all the other commands:
do
position object 1,0,0,5
sync
loop
Now you when you run the code you should see a colored box. If you dont see that then maybe you have writet something wrong if you have that try to use this code:
sync on
sync rate 30
make object box 1,1,1,3
color object 1, RGB(0,255,0)
do
position object 1,0,0,5
sync
loop
Now before we go any further i have a little thing you need to solve:
try to color the box in another color.
Have you made it another color?
Good then lets move on
im sure you wanna know about the
do
position object 1,0,0,5
sync
loop
code.
So i wanna tell you something about that code.
Everything that is between the
DO and
LOOP
darkBASIC will keep looping so we call it the "main loop" or "the game loop".
Something inportnent to remember is that the
SYNC command should be in that loop also so remember to put the
SYNC command in the end of the loop.
Now you see the
Position object 1,0,0,5
That tells darkbasic to position the box in front of the screen.
Try to play around with the "Position object" command so you can learn a bit more about the position object command
*The variables*
Now this is one of the most inportnent things you need to have theese variables to make the movements of the box.
now in the code our code:
that line we need to change so it is going to look like this:
position object 1,0,0, player#
go change it to that.
This is were the variables come in.
every variables of this kind all ends with a # sign.
So we call the variable "player#".
This means that the our object is now a variable and ready to use
Now you should have a code like this one:
sync on
sync rate 30
make object box 1,1,1,3
color object 1, RGB(0,255,0)
do
position object 1,0,0, player#
if upkey() =1 then player#=player#+5.0
sync
loop
You see the:
if upkey() =1 then player#=player#+5.0
line?
This means that IF upkey is pressed our variable(the bat) will move up.
Now when you run this code:
sync on
sync rate 30
make object box 1,1,1,3
color object 1, RGB(0,255,0)
do
position object 1,0,0, player#
if upkey() =1 then player#=player#+5.0
sync
loop
you should see nothing.
Then try to hit the upkey button and then the box should be visible and you should could see it move.
now under the:
if upkey() =1 then player#=player#+5.0
line you should put this:
if downkey() =1 then player#=player#-5.0
This means that when you hit the downkey button the box will move down.
As the last thing i have a problem for you to solve:
Try to change the speed on the box.
Here is a little hint:
The speed code is somewere in this line:
1 then player#=player#+5.0
and this line:
1 then player#=player#-5.0
i hope you found this tut helpfull
if you did then please comment it
If you code dosnt work then here is the final code( I have putted some comments in it so you can see what the things means):
` make the sync setup
sync on
sync rate 30
` make the 3D object
make object box 1,1,1,3
` color the box
color object 1, RGB(0,255,0)
` *THIS IS THE START ON THE MAIN LOOP*
do
` positon the 3D box and make in a variable
position object 1,0,0, player#
` This is the control input
if upkey() =1 then player#=player#+5.0
if downkey() =1 then player#=player#-5.0
sync
loop
If you need help to more things then you can add me on you msn i would be glad to help:
Here is my msn: kattenolle@hotmail.com
Waggames