topical media & game development

talk show tell print

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



  
  // Dark GDK - The Game Creators - www.thegamecreators.com
  
  // include Dark GDK header file
  include <DarkGDK.h>
  
  // main entry point for program
  void DarkGDK ( void )
  {
          // switch to media directory
          dbSetDir ( "media\\" );
  
          // set sync rate
          dbSyncOn   ( );
          dbSyncRate ( 0 );
  
          int ImageNumber  = 1;
          int        ImageNumberB = 2;
  
          // load images
          dbLoadImage ( "fire.bmp", ImageNumber );
          dbLoadImage ( "sky\\spacesphere.jpg", ImageNumberB );
  
          // load sky box
          dbLoadObject ( "sky\\ss.x", 1 );
          dbScaleObject ( 1,150,150,150 );
          dbSetObject ( 1,1,1,1,1,0,0,0 );
          dbSetObjectTexture ( 1,2,1 );
  
          // set camera properties
          dbSetCameraRange ( 1,10000 );
          dbPositionObject ( 1, 0, 3, 0 );
          dbYRotateObject ( 1,180 );
  
          // make a new box
          dbMakeObjectBox ( 2,100,20,50 );
          dbPositionObject ( 2,0,-25,50 );
          dbTextureObject ( 2,ImageNumberB );
          dbGhostObjectOn ( 2,2 );
  
          // create particles
          int ParticleNumber = 1;
          dbMakeParticles ( ParticleNumber, ImageNumber, 50, 20.0f );
          dbPositionParticles ( ParticleNumber, 0, -58, 0 );
          dbColorParticles ( ParticleNumber, 255, 128, 0 );
          dbSetParticleEmissions ( ParticleNumber, 10 );
          dbSetParticleSpeed ( ParticleNumber, 0.01f );
          dbSetParticleGravity ( ParticleNumber, 2 );
  
          // position camera
          dbPositionCamera ( 0,3,0 );
          dbPointCamera ( 0,3,400 );
          
          // main loop
          while ( LoopGDK ( ) )
          {
                  // quit on escape key
                  if ( dbEscapeKey ( ) )
                          return;
  
                  // adjust particle positions
                  dbPositionParticleEmissions ( ParticleNumber, ( dbMouseX ( ) - 320 ) / 40.0f * 20, ( 360 - dbMouseY ( ) ) / 40.0f * 20, 10 * 20 );
  
                  // change colours on mouse click
                  if ( dbMouseClick ( ) )
                  {
                          dbColorParticles ( ParticleNumber, dbRnd ( 255 ), dbRnd ( 255 ), dbRnd ( 255 ) );
                  }
  
                  // update screen
                  dbSync ( );
          }
  }
  


(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.