My background with TGC is mostly in DarkBasic Professional. But thanks to bad ass little venom (A.K.A. lllll venom lllll), I have started to dabble with C++ and DGDK. I have the books Beginning C++ Game Programming and Beginning DirectX 9, so I have a little experience with C++ programming. This is my second DGDK program, the first being lllll venom lllll’s split screen, witch I’ll also share with you.
This source is an example; it is designed to run in your FPSCreator directory. Simply build a level and run a level test. Copy the LoadFPSCLevel executable to the FPSCreator directory and run the program from there. The program uses the same controls as FPSC and has collision checking. For this program I have used Visual C++ 2008 Express Edition and Dark GDK Update - 26th October 2010. The project file is in the attached download.
LoadFPSCLevel source.
// Dark GDK - The Game Creators - www.thegamecreators.com
// Project: LoadFPSCLevel
// Created: 12/31/2011
// Stripped down source code and steps for bare bones FPSC level loading.
// 1. Run FPSCREATOR.EXE.
// 2. Scroll to the TOP/LEFT corner of the default level (level 5) in the editing area.
// 3. Make a level starting from this corner.
// 3. Click the TEST LEVEL button to build the test level.
// 4. Exit FPSCREATOR.EXE.
// 5. Move this compiled executable to the FPSCREATOR directory.
// 6. From the FPSCREATOR directory run LoadFPSCLevel.exe.
// Whenever using Dark GDK you must ensure you include the header file.
#include "DarkGDK.h"
int tkeystate30;
int tkeystate32;
int tkeystate17;
int tkeystate31;
int materialtype;
float cammovex;
float cammovey;
float cox;
float coy;
float coz;
float speed;
float x;
float y;
float z;
float sy;
float cmx;
float cmy;
float cmz;
float grav;
float camangx;
float camangy;
// The main entry point for the application is this function.
void DarkGDK ( void )
{
// Set screen mode to full screen 1024 x 768 32 bit.
dbSetDisplayMode ( 1024, 768, 32 );
dbSetWindowOff ( );
dbSetDir ( "Files" );
// Load level (load static objects read a DBO and DBU file pair)
dbLoadStaticObjects ( "levelbank\\testlevel\\universe.dbo", 0 );
// Load the skybox. Remove this code for an enclosed level.
dbLoadObject ( "skybank\\WXG\\sky\\sky.x", 1 );
dbSetObjectLight ( 1, 0 );
dbSetObjectTexture ( 1, 3, 0 );
dbPositionObject ( 1, 2000, 500, -2000 );
dbScaleObject (1, 60000, 60000, 60000 );
dbSetDir ( ".." );
// Set ambience and position camera.
dbSetAmbientLight ( 50 );
dbSetCameraRange ( 0.5, 32768 );
dbPositionCamera ( 50, 570, -50 );
dbRotateCamera ( 0, 90, 0 );
// Set global application properties, we begin by turning the sync rate on,
// this means we control when the screen is updated, we also set
// the maximum rate to 60 which means the maximum frame rate will
// be set at 60 frames per second.
dbSyncOn ( );
dbSyncRate ( 60 );
// Hide the mouse and disable the escape key.
dbHideMouse ( );
dbDisableEscapeKey ( );
while ( !dbEscapeKey ( ) )
{
// Control camera.
// Input source.
tkeystate30 = 0;
tkeystate32 = 0;
tkeystate17 = 0;
tkeystate31 = 0;
if ( dbKeyState ( 17 ) || dbMouseClick ( ) == 1 )
{
tkeystate17 = 1;
}
if ( dbKeyState ( 31 ) || dbMouseClick ( ) == 2 )
{
tkeystate31 = 1;
}
if ( dbKeyState ( 30 ) )
{
tkeystate30 = 1;
}
if ( dbKeyState ( 32 ) )
{
tkeystate32 = 1;
}
cammovex = dbMouseMoveX ( );
cammovey = dbMouseMoveY ( );
// Camera old information.
cox = dbCameraPositionX ( );
coy = dbCameraPositionY ( );
coz = dbCameraPositionZ ( );
// Control camera movement.
speed = 3.0;
x = dbCameraAngleX ( ); z = dbCameraAngleZ ( ); sy = dbCameraAngleY ( ); y = sy;
if ( tkeystate30 )
{
y -= 90;
}
if ( tkeystate32 )
{
y += 90;
}
dbRotateCamera ( 0, y, 0 );
if ( tkeystate17 || tkeystate30 || tkeystate32 )
{
dbMoveCamera ( speed );
}
if ( tkeystate31 )
{
dbMoveCamera ( speed * -1.0 );
}
dbRotateCamera ( x, sy, z );
// Camera new information.
cmx = dbCameraPositionX ( );
cmy = dbCameraPositionY ( ) - grav;
cmz = dbCameraPositionZ ( );
// Overall ellipse collision for camera.
if ( dbStaticVolume ( cox, coy - 20, coz, cmx, cmy - 20, cmz, 1.0 ) )
{
materialtype = dbGetStaticCollisionValue ( );
cmx = cox + dbGetStaticCollisionX ( );
cmy = coy + dbGetStaticCollisionY ( );
cmz = coz + dbGetStaticCollisionZ ( );
grav = 0.5;
}
else
{
grav += 0.5;
}
// Stop falling forever.
if ( cmy < -200.0 )
{
cmy = -200;
}
// Update camera position.
dbPositionCamera ( cmx, cmy, cmz );
// Control camera view.
camangx = dbCameraAngleX ( ) + cammovey / 1.5;
camangy = dbCameraAngleY ( ) + cammovex / 1.5;
if ( dbWrapValue ( camangx ) > 85 && dbWrapValue ( camangx ) < 180 )
{
camangx = 85.0;
}
if ( dbWrapValue ( camangx ) > 180 && dbWrapValue ( camangx) < 275 )
{
camangx = 275.0;
}
dbRotateCamera ( camangx, camangy, dbCameraAngleZ ( ) );
// Update
dbSync ( );
}
// Before quitting delete our objects.
dbShowMouse ( );
dbEnableEscapekey ( );
dbDeleteStaticObjects ( );
dbDeleteObject ( 1 );
// Now everything is ready to return back to Windows
return;
}
Here is the split screen source. The top is the cube’s view of the sphere and the bottom is the sphere’s view of the cube.
#include "DarkGDK.h"
void DarkGDK ( void )
{
dbSetDisplayMode ( 800, 600, 32 );
dbSyncOn ( );
dbSyncRate ( 60 );
dbBackdropOn ( );
dbColorBackdrop ( 0 );
dbMakeCamera ( 1 );
dbColorBackdrop ( 1, 0 );
dbSetCameraView ( 0, 0, 800, 299 );
dbSetCameraView ( 1, 0, 300, 800, 599 );
dbSetCameraAspect ( 2.66 );
dbSetCameraAspect ( 1, 2.66 );
dbMakeObjectCube ( 1, 10 );
dbMakeObjectSphere ( 2, 10 );
dbPositionObject ( 1, 0, 0, -50 );
dbPositionObject ( 2, 0, 0, 50);
dbPositionCamera ( dbObjectPositionX ( 1 ), dbObjectPositionY ( 1 ), dbObjectPositionZ ( 1 ) );
dbPositionCamera ( 1, dbObjectPositionX ( 2 ), dbObjectPositionY ( 2 ), dbObjectPositionZ ( 2 ) );
dbPointCamera ( dbObjectPositionX ( 2 ), dbObjectPositionY ( 2 ), dbObjectPositionZ ( 2 ) );
dbPointCamera ( 1, dbObjectPositionX ( 1 ), dbObjectPositionY ( 1 ), dbObjectPositionZ ( 1 ) );
while ( LoopGDK ( ) )
{
dbLine ( 0, 300, 800, 300 );
dbSync ( );
}
dbDeleteObject ( 1 );
dbDeleteObject ( 2 );
return;
}
Happy New Year