------

[ AD ] Port Monitor ( Try to use a Best WebSite Monitoring Tool )

------


 

DarkGDK - FPS Basics --------------

Hello Stickpage, today I am going to be showing you how to make the basics of an FPS game using the DarkGDK + Microsoft Visual C++ 2008.

Microsoft Visual C++ 2008 Download
August 2007 DirectX 9.0c SDK Download
DarkGDK Download

After all the above have been installed, open up your copy of Visual C++ 2008. Go to:
File -> New -> Project -> Wizards -> DarkGDK - Game

Name your project as you please, and set a directory. Then click "Ok". Allow it to build, which takes a few seconds.

Now, we must open the Main.cpp file to start coding - to do this we must open the Solution Explorer. If you cannot see this go to: View -> Solution Explorer. You should now see it as a tab to the left. Click it, and then double click the "Main.cpp" file.

You should see this:

Code:

// Dark GDK - The Game Creators - www.thegamecreators.com

 

// the wizard has created a very simple project that uses Dark GDK

// it contains the basic code for a GDK application

 

// whenever using Dark GDK you must ensure you include the header file

#include "DarkGDK.h"

 

// the main entry point for the application is this function

void DarkGDK ( void )

{

         // turn on sync rate and set maximum rate to 60 fps

         dbSyncOn   ( );

         dbSyncRate ( 60 );

 

         // our main loop

         while ( LoopGDK ( ) )

         {

                 // update the screen

                 dbSync ( );

         }

 

         // return back to windows

         return;

}

I personally tend to remove most of the comments, and replace it with this:

Code:

// files to include

#include "DarkGDK.h"

 

// the main entry point for the application is this function

void DarkGDK ( void )

{

         // sync on, and fps at 60

         dbSyncOn   ( );

         dbSyncRate ( 60 );

 

         // main loop

         while ( LoopGDK ( ) )

         {

                 // update the screen every frame

                 dbSync ( );

         }

 

         // return back to windows

         return;

}

The first thing we are going to do is load an object which is called "Atomiser.x", it is the gun we will eventually position and lock to the camera. Download it here.

We are going to need to save this file to our project folder. I've saved mine to the desktop, so I must go into Project Name Here -> Project Name Here.
Note: You must remember to go into that directory twice, otherwise the DarkGDK won't be able to load your objects!

So, we now have our Atomiser.x in the folder. We must use the function to load it and give it a unique ID (int). Under the dbSyncRate ( 60 ); line, add the following:

Code:

dbLoadObject("Atomiser.x", 10);

This loads the object "Atomiser.x" and gives it an ID of 10 which we will use as a future reference when rotating and positiong the object.

Press F5 to debug your game, you see a gun pointing downwards. We now want to rotate this object -90 degrees, so it's at a decent angle for a gun to be pointing. Do this by adding a line below dbLoadObject:

Code:

dbRotateObject(10, -90, 0, 0);

As you can see, we are using the "10" identifier (our Atomiser.x file) to get the object we set earlier. It should now be rotated -90 degrees. Have a look by debugging again! Looks quite awkward.

We are now going to position the object, so that when we lock it to the screen it doesn't look like a pile of rubbish. The function for this is: dbPositionObject(int ID, float fX, float fY, float fZ).

Add the following line after the last line of code:

Code:

dbPositionObject(10, 10, -15, 20);

If you debug that now, you will see the position has changed slightly. We are now going to lock it to the camera, so it is in the position of a gun. Do this by adding the following line:

Code:

dbLockObjectOn(10);

Debug it!

Yayyyy we have a slightly deformed-looking-blank-gun on our screen! We are now going to add the texture for this object. Place it in the same place as Atomiser.x, and download it
here.

If you debug it now, it will look much better.

Now, we are going to create our camera and make it movable via the arrow keys. We do this by using the dbControlCameraUsingArrowKeys(int id, float fVelocity, float fTurnSpeed) function. Under your db Sync ( ); line in the while loop, add the following line:

Code:

dbControlCameraUsingArrowKeys(0, 2.0f, 2.0f);

Yes fool, you are actually moving - but because there is nothing except blue... it wouldn't seem so. We are now going to add a matrix (lots of tiley squarey things) to show that we are moving. Under the camera line we are going to use the dbMakeMatrix() function. Add this line:

Code:

dbMakeMatrix(4, 100, 100, 10, 10);

Debug, and watch your person (well... gun) move!

This is where the tutorial ends, folks. Here are the links to some more texture and .x files to download. You should now try adding them in, positioning them and rotating them. Have a good one!

Download Links:
Bezerker
.x File
.bmp File

Note: I will add more files, but I currently don't have time!

Hope this tutorial helped you in some way or other, please comment on the tutorial and suggest what you would like to see in future tutorials!

Full Source Code

Code:

// files to include

#include "DarkGDK.h"

 

// the main entry point for the application is this function

void DarkGDK ( void )

{

         // sync on, and fps at 60

         dbSyncOn   ( );

         dbSyncRate ( 60 );

 

         dbLoadObject("Atomiser.x", 10);

         dbRotateObject(10, -90, 0, 0);

         dbPositionObject(10, 10, -15, 20);

         dbLockObjectOn(10);

 

         // main loop

         while ( LoopGDK ( ) )

         {

                 // update the screen every frame

                 dbSync ( );

 

                 dbControlCameraUsingArrowKeys(0, 2.0f, 2.0f);

                 dbMakeMatrix(4, 100, 100, 10, 10);

         }

 

         // return back to windows

         return;

}

http://forums.stickpage.com/showthread.php?34782-DarkGDK-FPS-Basics

 
몬스터 추가


'온라인게임' 카테고리의 다른 글

DarkGDK - Sprite Animation / 2D  (0) 2011.10.28
Dark GDK - Terrain / 3D  (0) 2011.10.27
Dark GDK - 이미지 로딩 예제 / 2D  (0) 2011.10.25
MS SQL Server Alter Table  (0) 2011.10.24
6. SDL Entities  (0) 2011.10.24

+ Recent posts