Tutorial: Making a game with DarkGDK part two

Part 2: Media

I’m not going to go into detail about making 3d meshes or textures right now but I will supply you with some to use.


Now lets get back to working on the game and use those art assets. Open up the project again and here’s what you’ve got to do in Main.cpp to load up everything and get your character moving round. I commented the hell out of it so even if you just copy and paste it all at once hopefully it will make sense. It will be easier to read from within the IDE.

//include DarkGDK and Sparky's collission detection which well be needing for later
#include "DarkGDK.h"
#include "SC_Collision.h"

//now declare the variables that we are going to need to use.
//I want to play in fullscreen without changing the resoltution and GetSystemMetrics is a good way to find out what the current desktop resolution is.
int screenx=GetSystemMetrics(SM_CXSCREEN);
int screeny=GetSystemMetrics(SM_CYSCREEN);
//dark gdk identafies 3d objects by a number and you cant assign multiple objects to the same number so I number them by the order there created in so you can check what the next available number is by keeping track of how many objects already exist.
int objcount=1;
//your going to want to remember what the object number is for your charecter since your going to be moving it around.
int youobj;
//isnt really neccessary but I like to record keypresses as variables
int up;int down;int left;int right;
//keep track of your movement speed and what angle your heading in.
//using double rather then int essentially means that it can deal with decimals rather then only whole numbers.
double movespeed;double moveangle=0;
//you will want to have a few multi purpose variables
double x;double y;double z;

void DarkGDK ( void ){
//now to start with the rest of the pre game setup.
//set the game resolution to the current desktop resolution which we found out before.
//since the games in full screen people probable wotn see this but its good to label things.
//set it to full screen.
//set what color will be shown on screen where there arent any visisble objects.
//throutle the frame rate to a predetermend rate (in this case 30)
//keep DarkGDK for doing anything anoying with the camera.
//turn off the mouse cursore.
//start up Sparky's collission detection.

//now we start loading those objects.
//load the room.
//load the texture.
//apply the texture.
//update the object count so we know not to assign that number to anymore objects.

//load your charecter model.
//keep track of its oject number.
//update the object count so we know not to assign that number to anymore objects.

//now we run the loop that the actual game occures in.
while ( LoopGDK ( ) ){

//update the charecter object and camera rotation based on mouse movements so you can turn and aim.

//check what keys are down.
//now if more then one key is down we need to change your movement direction and speed based on what combenation of keys are being used.
if (up+down+left+right==0){
if (up==1)if(down==0)if(left==0)if(right==0)moveangle=0;
if (up==0)if(down==1)if(left==0)if(right==0)moveangle=180;
if (up==0)if(down==0)if(left==1)if(right==0)moveangle=270;
if (up==0)if(down==0)if(left==0)if(right==1)moveangle=90;
if (up==1)if(down==0)if(left==1)if(right==0)moveangle=315;
if (up==1)if(down==0)if(left==0)if(right==1)moveangle=45;
if (up==0)if(down==1)if(left==1)if(right==0)moveangle=225;
if (up==0)if(down==1)if(left==0)if(right==1)moveangle=135;

//update your position and reposition the camera just behind you.

//update the screen.
dbSync ( );
//complete the loop.
//exit the game (by default DarkGDK automatically does this when the esc key is hit).

You might have noticed there seemingly random numbers being used when checking what keys where being pressed. It isn’t actually at all arbitrary. Each key on a keyboard is assigned a scan code and the dbKeyState() command returns a one if the specified key is being pressed down and zero if it isn’t. Here’s a nice little diagram to check anytime you want to know what the scan code is for a key.