topical media & game development
lib-game-darkgdk-samples-Sphere-Mapping-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 ( 60 );
// switch backdrop off
dbBackdropOff ( );
// copy our backdrop
dbLoadBitmap ( "media\\gfx\\backdrop.jpg",1 );
dbCopyBitmap ( 1,0,0,640,480,0,0,0,dbScreenWidth(),dbScreenHeight() );
dbSync ( );
dbDeleteBitmap ( 1 );
// load objects
dbLoadObject ( "media\\scout\\scout2.x",1 );
dbLoadImage ( "media\\sky\\space.jpg",1 );
dbSetSphereMappingOn ( 1,1 );
dbSetObjectSpecular ( 1,0 );
// make box
dbMakeObjectBox ( 2,1100,1000,1000 );
dbTextureObject ( 2,1 );
dbSetObjectCull ( 2,0 );
dbSetObjectLight ( 2,0 );
// sort camera
dbPositionCamera ( 0,0,-120 );
dbRotateCamera ( 0,0,0 );
float x = 0;
float y = -100;
float z = 0;
dbPositionObject ( 1,x,y,z );
dbLoadImage ( "media\\gfx\\prompt.jpg",2 );
dbLoadImage ( "media\\gfx\\strapblank.jpg",3 );
int strapx1 = 0;
dbSprite ( 1,strapx1,480-63,2 );
int strapx2=1024;
dbSprite ( 2,strapx2,480-63,2 );
dbSetSpriteAlpha ( 1,196 );
dbSetSpriteAlpha ( 2,196 );
dbLoadImage ( "media\\gfx\\fire.jpg",4 );
dbMakeParticles ( 1,4,40,100.0 );
dbPositionParticles ( 1,0,-500,0 );
dbSetParticleSpeed ( 1,0.2f );
dbSetParticleSpeed ( 1,0.004f );
dbSetParticleGravity ( 1,-3 );
dbSetParticleLife ( 1,2 );
dbLoadSound ( "media\\sounds\\space.wav",1 );
dbSetSoundVolume ( 1,80 );
dbLoopSound ( 1 );
dbLoad3DSound ( "media\\sounds\\jet.wav",2 );
dbSetSoundVolume ( 2,0 );
float roll = 0.0f;
float turn = 0.0f;
while ( LoopGDK ( ) )
{
if ( dbEscapeKey ( ) )
return;
roll = dbWrapValue ( roll + 0.5f );
turn = dbWrapValue ( turn + 0.1f );
y = 0 - ( dbCos ( roll ) * 100 );
x = dbCos ( turn ) * 50;
z = 50 + ( dbSin ( roll ) * 100 );
dbPositionObject ( 1,x,115 + y, z );
dbXRotateObject ( 1,dbWrapValue(90+roll) );
dbYRotateObject ( 1,dbWrapValue(180) );
dbZRotateObject ( 1,0 );
strapx1--;
if ( strapx1 <= -1024 )
strapx1 = strapx2 + 1023;
strapx2--;
if ( strapx2 <= -1023 )
strapx2 = strapx1 + 1024;
dbSprite ( 1,strapx1,dbScreenHeight()-63,2 );
dbSprite ( 2,strapx2,dbScreenHeight()-63,3 );
dbPositionCamera ( 0,135+(y/1.1f),-100 );
dbZRotateCamera ( dbWrapValue(((dbCos(turn)*5))) );
dbPositionParticles ( 1,x,(115+y)-(dbSin(roll)*58),z-(dbCos(roll)*58) );
dbRotateParticles ( 1,dbWrapValue((0-roll)-90),0,0 );
dbPositionSound ( 2,x,115+y,z );
dbPositionListener ( 0,115,-100 );
dbScaleListener ( 0.5 );
if ( dbSoundPlaying(2)==0 )
dbLoopSound ( 2 );
int vol = dbSoundVolume(2);
if ( vol < 100 )
dbSetSoundVolume ( 2,vol+1 );
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.