// 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"
#include "multisync.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;
// Core prototypes
bool NetHost(int playerAmount);
bool NetHost_IP(int playerAmount, char * ipAddress);
bool NetConnect(char * ipAddress);
void NetDisconnect();
void NetSend(int player);
void NetSendAll();
bool NetGetMessage();
unsigned long NetGetMessageSize();
unsigned long NetGetMessageRemainder();
int NetMessageFrom();
int NetPlayerJoined();
int NetPlayerLeft();
int NetGetPlayerAmount();
bool NetPlayerConnected(int player);
void NetKick(int player);
bool NetConnected();
void NetGetError(char * outBuffer, unsigned long outBufferSize);
void NetSetPort(unsigned short port);
void NetSetOption(int option, int value);
int NetGetOption(int option);
void NetGetPlayerIP(int player, char * outBuffer, unsigned long outBufferSize);
unsigned short NetGetPlayerPort(int player);
bool NetFirewallEnabled();
bool NetFirewallApplicationEnabled(char * appPath);
bool NetFirewallEnableApplication(char * appPath, char * appName);
// Message prototypes
void NetPutByte(unsigned char data);
void NetPutWord(unsigned short data);
void NetPutLong(unsigned long data);
void NetPutInt(int data);
void NetPutFloat(float data);
void NetPutString(char * stringData);
void NetPutData(const char * buffer, int sizeInBytes);
unsigned char NetGetByte();
unsigned short NetGetWord();
unsigned long NetGetLong();
int NetGetInt();
float NetGetFloat();
void NetGetString(char * outBuffer, unsigned long outBufferSize);
void NetGetData(char * buffer, int sizeInBytes);
void DarkGDK ( void )
{
dbSyncRate(60);
dbSetWindowPosition (112,84);
dbSetWindowOn();
dbSetWindowSize (800,600);
dbSetDisplayMode( 800,600,32 );
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,0,0,-10);
dbRotateObject(9,-106,0,167);
dbScaleObject(9,450,450,450);
dbHideObject(9);
dbSetShadowShadingOn(9);
dbShowObject(9);
//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);
dbSetObjectSpeed(1,180);
dbObjectCollision(1,5);
//Camera Options
dbPositionCamera(dbObjectPositionX(3),dbObjectPositionY(3),dbObjectPositionZ(3));
dbSetCameraRange ( 1, 1000);
dbLoadImage("AKfire.png",18,0);
dbMakeObjectBox( 17, 4 , 4, 0 );//First make a box
dbTextureObject( 17 , 18 );
dbFadeObject( 17, 8000 );
dbSetObjectTransparency( 17 , 1 );
dbHideObject( 11 );//Hide it when not in use
dbSetObjectCollisionOff( 17 );//No need for collision
//This basically handles the positioning of the muzzleflash
dbRotateObject(17,5,5,5);
dbPositionObject(17,0,0,-10);
dbScaleObject(17,50,50,50);
dbLockObjectOn(17);
//second muzzle
dbLoadImage("SCflash.png", 20);
dbSprite(20, 0, 0, 20);
dbSetSpriteAlpha(20, 0);
dbHideSprite(20);
dbOffsetSprite( 20,-238,-165);
//lights(60's)
dbMakeLight(60);
dbPositionLight(60,5,50,50);
//sounds
dbLoadSound("AK.wav",211);//Load a gun sound, id is 21
dbSetSoundSpeed(211,21000);
//Crosshair image
dbLoadImage("crosshair.png",100);
dbPasteImage ( 100 , ( dbScreenWidth( ) / 2 ) - 16 , ( dbScreenHeight( ) / 2 ) - 16 , 1 );
// our main loop
while ( LoopGDK ( ) )
{
dbHideObject(17);
dbHideObject(18);
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);
dbPositionObject(31,8,0,0);
dbGlueObjectToLimb (31,1,25);
dbFixObjectPivot(31);
}
//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 ();
//recoil
//SOME TRIGONOMETRY IS INVOLVED, but just know what the code is about and you're fine
dbMoveObjectRight( 9 , 0 + sin ( gunWaggle2 / 2.0f ) / 2.0f ); //move object right by sine
dbMoveObject( 9 , 0.0f );//move object in depth
dbMoveObjectDown( 9 , 0.0f + cos ( gunWaggle / 2.0f ) / 2.0f );//move down by cosine
gunWaggle += 0.2f;
dbMoveObjectRight( 31 , 0 + sin ( gunWaggle2 / 2.0f ) / 2.0f ); //move object right by sine
dbMoveObject( 31 , 0.0f );//move object in depth
dbMoveObjectDown( 31 , 0.0f + cos ( gunWaggle / 2.0f ) / 2.0f );//move down by cosine
static int trans = 0;
static int iter = 0;
if(dbMouseClick() == 1) // this is the code that needs to be change
{
dbSetCameraFOV( 0 , 57.0f) ; //zoom Camera
dbPasteImage ( 100 , ( dbScreenWidth( ) / 2 ) - 16 , ( dbScreenHeight( ) / 2 ) - 16 , 1 );
dbLoadImage("crosshairzoom.png",101);
dbPasteImage ( 101 , ( dbScreenWidth( ) / 2 ) - 16 , ( dbScreenHeight( ) / 2 ) - 16 , 1 );
dbShowObject(17);//show muzzleflash
dbPlaySound(211);//Play gun sound
dbLoopSound(211,0,1,0);//Loop it again and
gunWaggle2 += 170.55f;
if(trans < 256 && iter != -95)
iter = 100;
else if(trans > -1)
iter = -70;
else
iter = 70;
trans += iter;
dbSetSpriteAlpha(20, trans);
}
else
{
if(trans != 0) {
trans = (trans < 0) ? 0 : trans - 12;
dbSetSpriteAlpha(20, trans);
}
dbPauseSound(211);//pause gun sound
}
dbSetCameraFOV( 0 , 43.0f) ; // default Camera
dbSprite(20, 0, 0, 20);
dbText(0, 0, dbStr(trans));
if(dbMouseClick() == 2)//right click
{
dbPasteImage ( 100 , ( dbScreenWidth( ) / 2 ) - 16 , ( dbScreenHeight( ) / 2 ) - 16 , 1 );
dbLoadImage("crosshairzoom.png",101);
}
else
{
dbPasteImage ( 100 , ( dbScreenWidth( ) / 2 ) - 16 , ( dbScreenHeight( ) / 2 ) - 16 , 1 );
}
if(dbKeyState(42))
{
dbLoadImage("SC.png",50);
dbPasteImage ( 50 , ( dbScreenWidth( ) / 2 ) - 160 , ( dbScreenHeight( ) / 2 )
-135 , 1 );
dbSetCameraFOV( 0 , 43.0f) ;
dbHideObject(1);
dbHideObject(9);
dbHideObject(100);
dbPitchCameraDown(16.5);
dbTurnObjectLeft(50,20);
dbShowSprite(20);
dbHideObject(31);
}
else
{
dbSetAlphaMappingOn(100,0);
dbShowObject(1);
dbShowObject(100);
dbHideSprite(20);
dbShowObject(9);
}
//Player Controls
if (dbKeyState(31))
// W Move Forward
{
dbMoveObject (1,.57);
gunWaggle += 0.55f;
gunWaggle2 += 0.25;
}
if (dbKeyState(32)) // A straffe left
dbMoveObjectLeft(1,0.50);
if (dbKeyState(30)) // D straffe Right
dbMoveObjectRight(1,.50);
if (dbKeyState(17)) // S Move Back
{
dbMoveObject(1,-.57);
gunWaggle += 0.55f;
gunWaggle2 += 0.25;
}
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);
//dbText( 0,0,"Use W/A/S/D to move, Shift to run and Zoom into ironsights" );
//dbText( 0,20,"Right click for regular zoom and shoot, left click to return to normal and shoot" );
//dbText( 0,40,"no collision,bullets,muzzle flashes,or strafing animation yet" );
//dbText( 0,60,"SimHood Productions" );
//dbText( 0,80,"press escape to quit" );
// update the screen
dbSync ( );
}
// return back to windows
return;
}