topical media & game development

talk show tell print

lib-game-darkgdk-samples-World-Main.cpp / cpp



  
  // Dark GDK - The Game Creators - www.thegamecreators.com
  
  // include Dark GDK header file
  include <DarkGDK.h>
  
  float g_fSpeed = 0.1f;
  float g_fTurn = 0.03f;
  float OldCamAngleY;
  float OldCamAngleX;
  float CameraAngleY;
  float CameraAngleX;
  
  void userInput ( void );
  
  void DarkGDK ( void )
  {
          // entry point for the application
  
          dbSetDir ( "media\\" );
  
          dbAutoCamOff     ( );
          dbSyncOn         ( );
          dbSyncRate       ( 60 );
          dbBackdropOff    ( );
          dbSetCameraRange ( 0.05f, 30000 );
  
          dbLoadBSP ( "ikzdm1.pk3", "ikzdm1.bsp" );
          dbSetBSPCameraCollision (  1, 0, 0.75, 0 );
          
          dbLoadObject ( "media\\sky\\skybox2.x", 200 );
          dbSetObjectLight ( 200, 0 );
          dbSetObjectTexture ( 200, 3, 1 );
          dbPositionObject ( 200, 1000, 2000, 4000 );
          dbScaleObject ( 200, 30000, 30000, 30000 );
          
          dbPositionCamera ( 0.0f, 0.5f, 0.0f );
          
          while ( LoopGDK ( ) )
          {
                  if ( dbEscapeKey ( ) )
                          return;
  
                  char szFPS [ 256 ] = "";
                  strcpy ( szFPS, "fps = " );
                  strcat ( szFPS, dbStr ( dbScreenFPS ( ) ) );
                  dbText ( dbScreenWidth ( ) - 20 - dbTextWidth ( szFPS ), dbScreenHeight ( ) - 40, szFPS );
  
                  userInput ( );
  
                  dbSync ( );
          }
  }
  
  void userInput ( void )
  {
          dbControlCameraUsingArrowKeys ( 0, g_fSpeed, g_fTurn );
  
          OldCamAngleY = CameraAngleY;
          OldCamAngleX = CameraAngleX;
  
          CameraAngleY = dbWrapValue ( CameraAngleY + dbMouseMoveX ( ) * 0.4f );
          CameraAngleX = dbWrapValue ( CameraAngleX + dbMouseMoveY ( ) * 0.4f );
  
          dbYRotateCamera ( dbCurveAngle ( CameraAngleY, OldCamAngleY, 24 ) );
          dbXRotateCamera ( dbCurveAngle ( CameraAngleX, OldCamAngleX, 24 ) );
  
          char* szKey = dbInKey ( );
  
          if ( strcmp ( szKey, "+" ) == 0 )
          {
                  if ( g_fSpeed < 1000 )
                          g_fSpeed = g_fSpeed + 0.01f;
          }
  
          if ( strcmp ( szKey, "-" ) == 0 )
          {
                  if ( g_fSpeed > 0.02f )
                          g_fSpeed = g_fSpeed - 0.01f;
          }
  }
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.