Sorry for the quality, i have included source code. Add &fmt=18 for high quality.
Okay this is my first tutorial. It will tell you how to add a muzzleflash to your gun and add a gun sound, so you know if you're firing your gun. Really I try to explain how it all works. If you need help, just post a comment or pm me.
Source Code:
//Always include this file in your project
#include "DarkGDK.h"
//FCameraAngleX, FCameraAngleY both are global variables used for the mouse movement
int fCameraAngleX;
int fCameraAngleY;
//Main function in DarkGDK
void DarkGDK ( void )
{
//Always SYNC your game
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
dbMakeMatrix(1,100,100,10,10);
dbLo adObject("Atomiser.x",10);
dbDisableObje ctZDepth(10);
dbRotateObject(10,-90,0,0) ;
dbPositionObject(10,10,-15,20);
dbLock ObjectOn(10);
dbFixObjectPivot(10);//Thi s just fixes rotation issues
dbLoadImage("gunfire1.png",100,0 );
dbMakeObjectBox( 11, 4 , 4, 0 );//First make a box
dbTextureObject( 11 , 100 );
dbFadeObject( 11, 8000 );
dbSetObjectTransparency( 11 , 1 );
dbHideObject( 11 );//Hide it when not in use
dbSetObjectCollisionOff( 11 );//No need for collision
//This basically handles the positioning of the muzzleflash
dbMoveObjectRight( 11 , 1.85f);
dbMoveObject( 11 , 8 );
dbMoveObjectDown( 11 , 1.3f);
dbLockObjectOn( 11 );//Always lock it on
dbLoadSound("gun1.wav",21);//Load a gun sound, id is 21
dbSetSoundSpeed(21,88000);
// our main loop for DarkGDK
while ( LoopGDK ( ) )
{
//This handles movement for up and down keys
if (dbUpKey())
{
dbMoveCamera(2);
}
if (dbDownKey())
{
dbMoveCamera(-2);
}
//T his handles starfing for us
if (dbLeftKey())
{
dbYRotateCamera ( 0 , dbCameraAngleY( 0 ) - 90 );
dbMoveCamera(2);
}
if (dbRightKey())
{
dbYRotateCamera ( 0 , dbCameraAngleY( 0 ) + 90 );
dbMoveCamera(2);
}
//First you make the camera formula here
fCameraAngleX = dbWrapValue ( fCameraAngleX + dbMouseMoveY ( ) * 0.2f );
fCameraAngleY = dbWrapValue ( fCameraAngleY + dbMouseMoveX ( ) * 0.2f );
// rotate camera in our game
dbXRotateCamera ( fCameraAngleX );
dbYRotateCamera ( fCameraAngleY );
//Crosshair image
dbLoadImage("crosshair.png",1000);
dbPasteImage ( 1000 , ( dbScreenWidth( ) / 2 ) - 16 , ( dbScreenHeight( ) / 2 ) - 16 , 1 );
if ( dbMouseClick() == 1)//If left mouse button is pressed
{
dbPlaySound(21);//Play gun sound
dbLoopSound(21,0,10000,0);//Loop it again and again
dbShowObject(11);//show muzzleflash
dbRollObjectLeft ( 11 , (float)(rand() % 360) );
}
else//otherwise
{
dbPauseSound(21); //pause gun sound
dbHideObject(11);//hide muzzleflash
}
// update the screen
dbSync ( );//used to update
}
// return back to windows when done with program
return;
}
DarkGDK tutorial - Muzzle Flash and Gun Sound
Sorry for the quality, i have included source code. Add &fmt=18 for high quality.
Okay this is my first tutorial. It will tell you how to add a muzzleflash to your gun and add a gun sound, so you know if you're firing your gun. Really I try to explain how it all works. If you need help,...
more
|
Comments :
0
|
|
|