now i have added the gun, and sounds and as usual, there is a problem, the sound and muzzel flash(which i need help on making transparent) only plays when you right click the mouse, i want it to play wen you left click the mouse also.
// Dark GDK - The Game Creators - www.thegamecreators.com
// the wizard has created a very simple project that uses Dark GDK
// it contains the basic code for a GDK application
// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
// the main entry point for the application is this function
float gunWaggle = 0.0f;
float gunWaggle2 = 0.0f;
int fCameraAngleX;
int fCameraAngleY;
float Max;
float XAngleCamera;
bool gun_pickup = false;
void DarkGDK ( void )
{
dbAutoCamOff();
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
//Make world Objects
dbLoadObject("gign.x",1);
dbPositionObject(1,0,0,0);
dbMakeMatrix(2,75,75,75,75);
dbScaleObject(1,13,13,13);
dbRotateObject(1,0,0,0);
dbSetObjectCollisionOn(1);
dbSetShadowShadingOn(1);
dbColorObject(2,000);
DWORD color = dbRGB(0, 0, 000); //Blue
dbMakeObjectPlane(6,1000,1000);
dbSetObjectSmoothing(1,100);
dbRotateObject(6,90,0,0);
//gun
dbLoadObject("AK47.x",9);
dbPositionObject(9,35,0,-10);
dbRotateObject(9,-106,0,167);
dbScaleObject(9,450,450,450);
//snow world
dbLoadObject("fy_snow.x",5);
dbPositionObject(5,0,0,0);
dbScaleObject(5,10,10,10);
dbSetObjectCollisionOn(5);
//Makes the camera rotation mount above the player
dbMakeObjectSphere(3,1);
dbPositionObject(3,10,0,0);
dbScaleObject(3,10,10,10);
dbHideObject(3);
//Camera Options
dbPositionCamera(dbObjectPositionX(3),dbObjectPositionY(3),dbObjectPositionZ(3));
dbSetCameraRange ( 1, 1000);
dbLoadImage("muzzelAK.png",10);
dbMakeObjectBox( 11, 1 , 1, 0 );//First make a box
dbTextureObject( 11 , 10 );
dbFadeObject( 11, 8000 );
dbSetObjectTransparency( 11 , 10 );
dbHideObject( 11 );//Hide it when not in use
//This basically handles the positioning of the muzzleflash
dbMoveObjectRight( 11 , 1.85f);
dbMoveObject( 11 , 8 );
dbMoveObjectDown( 11 , 1.30f);
dbLockObjectOn( 11 );//Always lock it on
//sound
dbLoadSound("AK.wav",21);//Load a gun sound, id is 21
dbSetSoundSpeed(21,88000);
// our main loop
while ( LoopGDK ( ) )
{
float xdist, ydist, zdist;
int differences;
xdist = dbCameraPositionX() - dbObjectPositionX(9);
ydist = dbCameraPositionY() - dbObjectPositionY(9);
zdist = dbCameraPositionZ() - dbObjectPositionZ(9);
differences = sqrt((xdist*xdist) + (ydist*ydist) + (zdist*zdist));
if (differences < 20)
{
gun_pickup = true;
}
else
{
gun_pickup = false;
}
if (gun_pickup == true)
{
dbPositionObject(9,8,0,0);
dbGlueObjectToLimb (9,1,25);
dbFixObjectPivot(9);
}
//Camera Loop Options
//This Positions the camera so its always at the camera mount.
dbPositionCamera(dbObjectPositionX(3),dbObjectPositionY(3),dbObjectPositionZ(3));
//Positions The camera mount so its always above the player
dbPositionObject(3,dbObjectPositionX(1)+.5,dbObjectPositionY(1) +10.8,dbObjectPositionZ(1));
//Makes float XAngleCamera always = the camera mount's X angle
XAngleCamera = dbObjectAngleX(3);
//Makes float Max = the camera mount's object X angle + or minus mouse up and down movement.
Max = dbObjectAngleX(3) + dbMouseMoveY() / 2;
//Rotates the camera mount's X angle to equal Max
dbXRotateObject(3,Max);
//Sets the camera's X and Z angle to the same as the camera mount and sets it's Y angle to the same as the player.
dbRotateCamera(dbObjectAngleX(3),dbObjectAngleY(1)+180,dbObjectAngleZ(3));
//Rotates the player model left and right based on the mouse
dbRotateObject( 1, 0, dbObjectAngleY(1) + dbMouseMoveX() / 2, dbObjectAngleZ(1) ) ;
//Sets the camera to always be behind the camera mount
dbMoveCamera( -10 );
dbSetCameraFOV( 1 , 57.0f) ;
//Hide The Mouse and has the mouse always at the middle of the screen
dbPositionMouse (dbScreenWidth() /2, dbScreenHeight() /2);
dbHideMouse ();
if(dbMouseClick() == 1) // this is the code that needs to be change
{
dbSetCameraFOV( 0 , 57.0f) ; //zoom Camera
dbPlaySound(21);//Play gun sound
dbLoopSound(21,0,10000,0);//Loop it again and again
dbShowObject(11);//show muzzleflash
dbRollObjectLeft ( 11 , (float)(rand() % 360) );
}
if(dbMouseClick() == 2)//right click
{
dbSetCameraFOV( 0 , 45.0f) ; // default Camera
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
{
dbPauseSound(21);//pause gun sound
dbHideObject(11);//hide muzzleflash
}
//Player Controls
if (dbKeyState(31))
// W Move Forward
dbMoveObject (1,.37);
if (dbKeyState(32)) // A straffe left
dbMoveObjectLeft(1,.27);
if (dbKeyState(30)) // D straffe Right
dbMoveObjectRight(1,.27);
if (dbKeyState(17)) // S Move Back
dbMoveObject(1,-.37);
if(dbKeyState(17) == 0 )//stand still
dbLoopObject(1,0,0);
if(dbKeyState(17) == 1 )//walk forward
dbLoopObject(1,92,128);
if(dbKeyState(30) == 1 && dbKeyState(17) == 0 )//move sideways-left
dbLoopObject(1,92,128);
// update the screen
dbSync ( );
}
// return back to windows
return;
}