kod.cpp:
//====================================================================================================================================//
//===========================================KK======KK=======OO==========DDDD========================================================//
//===========================================KK====KK======OO====OO=======DD===DD=====================================================//
//===========================================KK==KK=======OO======OO======DD====DD====================================================//
//===========================================KKKK========OO========OO=====DD======DD==================================================//
//===========================================KKKK========OO========OO=====DD======DD==================================================//
//===========================================KK==KK=======OO======OO======DD=====DD===================================================//
//===========================================KK====KK======OO====OO=======DD===DD=====================================================//
//===========================================KK======KK=======OO==========DDDD========================================================//
//====================================================================================================================================//
//--------------------------------------------------------INCLUDES--------------------------------------------------------------------//
#include "DarkGDK.h"
#include "direct.h"
#include "windows.h"
#include "stdio.h"
#include "KoD.h"
#include "spells.h"
#include <vector>
//---------------------------------------------------------USING---------------------------------------------------------------------//
using std::vector;
using std::string;
//--------------------------------------------------------DEFINES--------------------------------------------------------------------//
#define DEBUG_MODE
//------------------------------------------------------STRUCTURES-------------------------------------------------------------------//
enum _gamemode { eMainMenu, eLoad, ePlay, eLose, eWin } eGameMode;
enum _playerstate {eStop, eRunning, eLeftspin, eRightspin, eLeftmove, eRightmove, eJump, eAttack1, eAttack2, eAttack3} ePlayerState;
_player player;
typedef struct _creature
{
int ID;
char path[80];
int health;
struct
{
int X;
int Y;
int Z;
} position;
int ori;
int scale;
int loopit;
bool killable;
int speed;
int hit_timer;
char displaypic[80];
int dpi;
bool deathwave_hited_me;
int lootTable;
bool allow_loot;
} creature;
struct coord
{
int x;
int y;
};
typedef struct _item
{
int ID;
int spellID;
char icon[200];
}item;
//---------------------------------------------------FUNCTION PROTOTYPES--------------------------------------------------------------//
void ReadMode(void);
void game (void);
void MainMenu (void);
void LoadGame (void);
void Play (void);
void GameLose (void);
void GameWin (void);
void DisplayPlayerHealth (void);
void UpdatePlayerHealth (void);
void DisplayEnergy (void);
void UpdatePlayerCamera (void);
void MovePlayer (void);
void CheckMainMenu (void);
void LoadData (void);
void SaveData (void);
bool PlayerInRange ( int x1, int z1, int x2, int z2);
void ApplyGlobalScripts (void);
void DisplayActionBar (void);
void UpdateActionBar (void);
void DisplayCooldowns (void);
void CreateCreature (int ID, int health, int scale, int X, int Z,int YOffset, int ori, char path[80], int loopit, bool killable, int speed, char displaypic[80], int loot_table);
void ReduceObjectHealth(int ID, int ammount);
void DrawObjects (void);
void CheckCreaturesLife (void);
void ApplyGlobalScripts (void);
void UpdateLeftMouseKey (void);
void UpdateCreatureHealth (int ID);
int GetCreatureHealth (int ID);
void UpdateAutoAttack ( void );
void UpdateEnergy ( void );
void ReduceEnergyBy ( int iVal );
void UpdateBag (void);
void Bag ( bool state );
void LoadCursors ( void );
void Cursor ( char STYLE[20] );
void UpdateCreatureLoot (void);
void AddLootsToTable (int iTable);
//---------------------------------------------------GLOBAL VARIABLES----------------------------------------------------------------//
int CURSOR = 10001;
int CURSOR_HANDLER = 999999;
int CURSOR_HOVER = 6;
int iTime = 0;
int inventory_slot_counter = 1;
int swidth, shight, sdepth;
int firetimer = 0;
float OldObjAngleY;
float ObjectAngleY;
float OldCamAngleX;
float CameraAngleX;
int loadX = 200;
int loadZ = 200;
int continued = 0;
int colonelfiretimer = 0;
int scroll_value = -28;
bool deathwave_shooted = false;
int deathwave_timer = 0;
int deathwave_cooldown = -2001;
bool deathwave_allowloop = true;
bool irightclicked = false;
int pic_ID_generator = 9000; // id generator must increase on each call.
bool ihaveatarget = false;
bool PlayerAutoAttackOn = false;
int autoattacktimer = 0;
bool clickedautoattack = false;
int deathstrikebonus = 0;
bool clickeddeathstrike = false;
int energytimer = 0;
bool mouseclicked = false;
bool bagtoggled = false;
bool pressedB = false;
bool mouseloot = false;
int lootpick;
bool looting = false;
int oldX_loot, oldY_loot, oldZ_loot;
vector<creature> creatV(0);
vector<item> inventory_itemV(0);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void DarkGDK (void)
{
dbSyncOn();
dbSyncRate(60);
failedmode:
#ifndef DEBUG_MODE
ReadMode();
if(!dbCheckDisplayMode(swidth, shight, sdepth) )
{
perror ("Wrong display mode, please try again.");
goto failedmode;
}
#endif
#ifdef DEBUG_MODE
swidth = 1366;
shight = 768;
sdepth = 32;
#endif
dbSetWindowLayout(0,0,2);
dbSetDisplayMode ( swidth , shight , sdepth );
dbMaximiseWindow();
dbDisableEscapeKey();
while(1)
{
game();
dbUpdateTerrain();
dbSync();
}
}
void game (void)
{
switch (eGameMode)
{
case eMainMenu:
MainMenu();
break;
case eLoad:
LoadGame();
break;
case ePlay:
Play();
break;
case eLose:
GameLose();
break;
case eWin:
GameWin();
break;
}
}
void MainMenu (void)
{
LoadCursors();
dbHideMouse();
dbLoadImage("data\\images\\start screen.jpg" , 1);
dbLoadImage("data\\images\\start screen-continue.jpg" , 2);
dbLoadImage("data\\images\\start screen-new game.jpg" , 3);
dbLoadImage("data\\images\\start screen-exit game.jpg" , 4);
dbLoadImage("data\\images\\hidden cursor.tga" , CURSOR_HOVER);
dbLoadImage("data\\images\\glow2.tga" , 7);
dbLoadImage("data\\images\\usage.tga" , 8);
dbLoadImage("data\\images\\continue - info.tga" , 9);
dbLoadImage("data\\images\\new game - info.tga" , 10);
dbLoadImage("data\\images\\exit game - info.tga" , 11);
dbSprite(1,0,0 , 1);
dbSetSprite(1, 1, 0);
dbSizeSprite(1, swidth, shight);
dbSprite(2,50,(dbScreenHeight()/2)+100 , 2);
dbSprite(3,50,(dbScreenHeight()/2)+160, 3);
dbSprite(4,50,(dbScreenHeight()/2)+220, 4);
dbSprite(12,dbScreenWidth()-510,dbScreenHeight() - 310, 8);
while(1)
{
failedclick:
dbSprite(CURSOR_HANDLER,dbMouseX(),dbMouseY() , CURSOR);
dbSetSpritePriority(CURSOR_HANDLER, 1000);
dbSprite( CURSOR_HOVER ,dbMouseX(),dbMouseY() , CURSOR_HOVER);
dbSync();
if(dbEscapeKey() == 1)
{
while(dbEscapeKey() == 1)
{}
exit(0);
}
while(dbSpriteCollision(CURSOR_HOVER,2)) //continue
{
dbSprite(CURSOR_HANDLER,dbMouseX(),dbMouseY() , CURSOR);
dbSetSpritePriority(CURSOR,2);
dbSprite(CURSOR_HOVER,dbMouseX(),dbMouseY() , CURSOR_HOVER);
dbSprite(7,40,(dbScreenHeight()/2)+90,7);
dbSprite(11,dbScreenWidth()-510,dbScreenHeight() - 310, 9);
dbSetSpritePriority(11,2);
dbSync();
if(dbMouseClick() == 1)
{
while(dbMouseClick() == 1)
{
dbSprite(CURSOR_HANDLER,dbMouseX(),dbMouseY() , CURSOR);
dbSetSpritePriority(CURSOR,2);
dbSprite(CURSOR_HOVER,dbMouseX(),dbMouseY() , CURSOR_HOVER);
if(!dbSpriteCollision(CURSOR_HOVER,2))
goto failedclick;
dbSync();
}
LoadData();
continued = 1;
goto choosen;
}
}
dbDeleteSprite(7);
dbDeleteSprite(9);
while(dbSpriteCollision(CURSOR_HOVER,3))
{
dbSprite(CURSOR_HANDLER,dbMouseX(),dbMouseY() , CURSOR);
dbSetSpritePriority(CURSOR,2);
dbSprite(CURSOR_HOVER,dbMouseX(),dbMouseY() , CURSOR_HOVER);
dbSprite(7,40,(dbScreenHeight()/2)+150,7);
dbSprite(11,dbScreenWidth()-510,dbScreenHeight() - 310, 10);
dbSetSpritePriority(11,2);
dbSync();
if(dbMouseClick() == 1)
{
while(dbMouseClick() == 1)
{
dbSprite(CURSOR_HANDLER,dbMouseX(),dbMouseY() , CURSOR);
dbSetSpritePriority(CURSOR,2);
dbSprite(CURSOR_HOVER,dbMouseX(),dbMouseY() , CURSOR_HOVER);
if(!dbSpriteCollision(CURSOR_HOVER,3))
goto failedclick;
dbSync();
}
goto choosen;
}
}
dbDeleteSprite(7);
dbDeleteSprite(10);
while(dbSpriteCollision(CURSOR_HOVER,4))
{
dbSprite(CURSOR_HANDLER,dbMouseX(),dbMouseY() , CURSOR);
dbSetSpritePriority(CURSOR,2);
dbSprite(CURSOR_HOVER,dbMouseX(),dbMouseY() , CURSOR_HOVER);
dbSprite(7,40,(dbScreenHeight()/2)+210,7);
dbSetSpritePriority(11,2);
dbSprite(11,dbScreenWidth()-510,dbScreenHeight() - 310, 11);
dbSync();
if(dbMouseClick() == 1)
{
while(dbMouseClick() == 1)
{
dbSprite(CURSOR_HANDLER,dbMouseX(),dbMouseY() , CURSOR);
dbSetSpritePriority(CURSOR,2);
dbSprite(CURSOR_HOVER,dbMouseX(),dbMouseY() , CURSOR_HOVER);
if(!dbSpriteCollision(CURSOR_HOVER,4))
goto failedclick;
dbSync();
}
exit(0);
}
}
dbDeleteSprite(7);
dbDeleteSprite(11);
}
choosen:
dbDeleteSprite(2);
dbDeleteSprite(3);
dbDeleteSprite(4);
dbDeleteSprite(CURSOR_HANDLER);
dbDeleteSprite(CURSOR_HOVER);
dbDeleteSprite(7);
dbDeleteSprite(8);
dbDeleteSprite(9);
dbDeleteSprite(10);
dbDeleteSprite(11);
eGameMode=eLoad;
}
void LoadGame (void)
{
dbLoadImage("data\\images\\Detail Image.jpg",101);
dbLoadImage("data\\images\\level 1 texture.jpg",102);
dbLoadImage("data\\images\\healthx1.tga",1001);
dbLoadImage("data\\images\\healthx2.tga",1000);
dbLoadSound("data\\sounds\\shoot.wav", 1);
dbLoadSound("data\\sounds\\boss_colonel.wav",2);
dbSetCameraRange (0, 1.0f, 5000.0f );
dbSetupTerrain ( );
dbMakeObjectTerrain ( 1 );
dbSetTerrainHeightMap ( 1, "data\\images\\level 1 heights.jpg" );
dbSetTerrainScale ( 1, 5.0f, 0.8f, 5.0f );
dbSetTerrainLight ( 1, 1.0f, -0.25f, 0.0f, 1.0f, 1.0f, 0.78f, 0.5f );
dbSetTerrainTexture ( 1, 102,101);
dbBuildTerrain ( 1 );
dbLoadObject("Data\\Objects\\yellowbox.X", 2);
dbPositionObject(2, loadX, dbGetTerrainGroundHeight(1,loadX,loadZ),loadZ);
dbScaleObject(2,15,15,15);
////==================================================Create Creatures=======================================================
CreateCreature(1100,-99,300,849,1023, 0 , 200, "Data\\Objects\\Flames.X",1, false, 2, " ",1);//0
dbHideObject(1100);
//CreateCreature(1126,-99,10,200,200, 0 , 200, "Data\\Objects\\Cone of Flames.X",1, false, 2, NULL);//1
//CreateCreature(1101,100,50,849,1023, 0 , 200, "Data\\Objects\\Flame Lord.X",0, true, 1, " ");//2 -- the boss
//CreateCreature(1127,-99,10,953,205, 0 , 200, "Data\\Objects\\Teleporter.X",0, false, 2, NULL);//3
CreateCreature (1128, -99, 50,0,0,5,0,"data\\objects\\Death Wave.X",0,false,5, " ",1);
CreateCreature(1130,150,20,953,205, 0 , 300, "Data\\Objects\\teleporter.X",0, true, 1, "data\\images\\yellowbox2d.jpg", 1);//4
CreateCreature(1102,20,20,500,130, 0 , 300, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//4
CreateCreature(1103,20,20,522,406, 0 , 228, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//5
CreateCreature(1104,20,20,500,501, 0 , 40, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//6
CreateCreature(1105,20,20,525,679, 0 , 151, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//7
CreateCreature(1106,20,20,566,683, 0 , 175, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//8
CreateCreature(1107,20,20,800,1061, 0 , 300, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//9
CreateCreature(1108,20,20,781,991, 0 , 247, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//10
CreateCreature(1109,20,20,823,955, 0 , 208, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//11
CreateCreature(1110,20,20,900,949, 0 , 124, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//12
CreateCreature(1111,20,20,915,991, 0 , 61, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//13
CreateCreature(1112,20,20,902,1096, 0 , 39, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//14
CreateCreature(1113,20,20,838,1083, 0 , 350, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//15
CreateCreature(1114,20,20,1071,905, 0 , 324, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//16
CreateCreature(1115,20,20,1103,928, 0 , 324, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//17
CreateCreature(1116,20,20,1147,624, 0 , 0, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//18
CreateCreature(1117,20,20,1077,388, 0 , 21, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//19
CreateCreature(1118,20,20,889,528, 0 , 351, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//20
CreateCreature(1119,20,20,842,572, 0 , 339, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//21
CreateCreature(1120,20,20,758,835, 0 , 344, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//22
CreateCreature(1121,20,20,523,1039, 0 , 254, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//23
CreateCreature(1122,20,20,324,955, 0 , 305, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//24
CreateCreature(1123,20,20,233,800, 0 , 248, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//25
CreateCreature(1124,20,20,262,747, 0 , 206, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//26
CreateCreature(1125,20,20,85,533, 0 , 188, "Data\\Objects\\yellowbox.X",1, true, 1, "data\\images\\yellowbox2d.jpg", 1);//27
DrawObjects();
////=========================================================================================================================
dbPositionCamera(0, loadX-40,dbGetTerrainGroundHeight(1,loadX-40,loadZ-40)+40,loadZ-40);
player.maxhealth = 10;
if(continued == 0)
{
player.Energy = 99;
player.maxEnergy = 99;
player.curhealth = 10;
}
player.base_damage = 8;
dbLoadImage("data\\images\\main menu.jpg" , 201);
dbLoadImage("data\\images\\main menu-options.jpg" , 202);
dbLoadImage("data\\images\\main menu-resume.jpg" , 203);
dbLoadImage("data\\images\\main menu-exit game.jpg" , 204);
dbSprite(201,(dbScreenWidth()/2)-100,(dbScreenHeight()/2)-150,201);
dbHideSprite(201);
dbSprite(202,(dbScreenWidth()/2)-56,(dbScreenHeight()/2)-110,202);
dbHideSprite(202);
dbSprite(203,(dbScreenWidth()/2)-56,(dbScreenHeight()/2)-22,203);
dbHideSprite(203);
dbSprite(204,(dbScreenWidth()/2)-56,(dbScreenHeight()/2)+66,204);
dbHideSprite(204);
dbDeleteSprite(12);
dbDeleteSprite(1);
DisplayPlayerHealth();
DisplayEnergy();
DisplayActionBar();
//--------bag coords
coord one; one.x = 1024; one.y = 644;
coord two; two.x = 1080; two.y = 644;
coord three; three.x = 1136; three.y = 644;
coord four; four.x = 1024; four.y = 700;
coord five; five.x = 1080; five.y = 700;
coord six; six.x = 1136; six.y = 700;
coord seven; seven.x = 1215; seven.y = 588;
coord eight; eight.x = 1286; eight.y = 588;
coord nine; nine.x = 1215; nine.y = 646;
coord ten; ten.x = 1286; ten.y = 646;
coord eleven; eleven.x = 1215; eleven.y = 705;
coord twelve; twelve.x = 1286; twelve.y = 705;
//------------------
dbSprite(CURSOR_HANDLER,dbMouseX()-10,dbMouseY()-10,CURSOR);
dbSetSpritePriority(CURSOR_HANDLER,2000);
eGameMode=ePlay;
}
void Play (void)
{
iTime=dbTimer();
#ifdef DEBUG_MODE
char str[256];
sprintf(str, "X = %d Y = %d Z = %d O = %d \nTID = %d \nmx = %d my = %d \nFPS = %d", player.Xloc, (int)dbGetTerrainGroundHeight(1,player.Xloc,player.Zloc), (int)player.Zloc, (int) dbObjectAngleY(2), (int)player.target_ID, dbMouseX(), dbMouseY(), dbScreenFPS());
dbText(10,10,str);
#endif
ApplyGlobalScripts();
UpdateAutoAttack();
CheckCreaturesLife();
UpdateLeftMouseKey();
UpdateActionBar();
UpdateBag();
DisplayCooldowns();
MovePlayer();
UpdatePlayerCamera();
UpdatePlayerHealth();
UpdateEnergy();
UpdateCreatureLoot();
CheckMainMenu();
dbSprite(CURSOR_HANDLER,dbMouseX()-10,dbMouseY()-10,CURSOR);
dbSprite(CURSOR_HOVER,dbMouseX(),dbMouseY(),CURSOR_HOVER);
}
void GameLose (void)
{
dbSetTextToBold();
char STR[200];
dbLoadImage("BlackScreen.jpg", 9998);
dbSprite(9998,-1,-1,9998);
dbSetSprite(9998,1,0);
sprintf(STR, "YOU LOSE!");
dbText((dbScreenWidth()/2)-4,(dbScreenHeight()/2)-1,STR);
if(dbEscapeKey())
exit(0);
}
void GameWin (void)
{
}
void DisplayPlayerHealth (void)
{
int PMH;
int PCH;
int countX=(dbScreenWidth()/2)-170;
int countX2=(dbScreenWidth()/2)-170;
int multiply=10;
PMH=10;
PCH=player.curhealth;
for(int count=1000;count<(PMH*multiply)+1000;count++) //print max health
{
dbSprite(count,countX,10,1000);
dbSetSpritePriority(count,2);
countX++;
}
for(int count2=1200;count2<(PCH*multiply)+1200;count2++) //current health
{
dbSprite(count2,countX2,10,1001);
dbSetSpritePriority(count2,3);
countX2++;
}
dbSync();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void UpdatePlayerHealth (void)
{
int PCH;
int countX=(dbScreenWidth()/2)-170;
int multiply=10;
PCH=player.curhealth;
for(int count3=1200;count3< 1300;count3++) //current health
{
dbDeleteSprite(count3);
}
for(int count2=1200;count2<(PCH*multiply)+1200;count2++) //current health
{
dbSprite(count2,countX,10,1001);
dbSetSpritePriority(count2,3);
countX++;
}
dbSync();
if(player.curhealth <= 0)
eGameMode=eLose;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void DisplayEnergy (void)
{
int countX=(dbScreenWidth()/2)-170;
for(int count = 1500;count < 1600;count++)
dbDeleteSprite(count);
for(int count = 1500; count < 1500+player.Energy; count++) //cur Energy
{
dbSprite(count,countX,50,1001);
dbSetSpritePriority(count,5);
countX++;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
float GetCurrentY (void)
{
return dbObjectPositionY(2);
}
float GetCurrentX (void)
{
return dbObjectPositionX(2);
}
float GetCurrentZ (void)
{
return dbObjectPositionZ(2);
}
void UpdatePlayerCamera (void)
{
scroll_value += dbMouseMoveZ()/30;
if (scroll_value > 20) scroll_value = 20;
if (scroll_value < -40) scroll_value = -50;
dbYRotateCamera(0,dbObjectAngleY(2));
dbPositionCamera(0,dbObjectPositionX(2),dbGetTerrainGroundHeight(1,dbObjectPositionX(2),dbObjectPositionZ(2))+(12-(scroll_value/6)),dbObjectPositionZ(2));
dbMoveCamera(0,scroll_value+(scroll_value/2));
dbYRotateCamera(0, 60);
dbYRotateCamera(0,dbObjectAngleY(2));
if (dbMouseClick() == 2 && !dbSpriteCollision(CURSOR_HOVER,2004) && !dbSpriteCollision(CURSOR_HOVER,2003) && !dbSpriteCollision(CURSOR_HOVER,2002))
{
float OldCamAngleX = dbCameraAngleX ( 0 );
CameraAngleX = dbWrapValue ( ( dbCameraAngleX ( 0 ) + dbMouseMoveY ( ) * 0.3f ) );
dbPitchCameraDown(dbMouseMoveY()/15);
if ( CameraAngleX > 80 && CameraAngleX <180 ) CameraAngleX = 80;
if ( CameraAngleX < 320 && CameraAngleX > 180 ) CameraAngleX = 320;
dbXRotateCamera ( 0 , dbCurveAngle ( CameraAngleX , OldCamAngleX , 6 ) );
}
if(dbCameraPositionY(0) <= dbGetTerrainGroundHeight(1, dbCameraPositionX(0), dbCameraPositionZ(0)) + 5) dbPositionCamera(0, dbCameraPositionX(0),dbGetTerrainGroundHeight(1, dbCameraPositionX(0),dbCameraPositionZ(0))+5, dbCameraPositionZ(0));
}
void MovePlayer (void)
{
int oldY = GetCurrentY();
int oldX = GetCurrentX();
int oldZ = GetCurrentZ();
if ( dbUpKey() || dbKeyState( 17 ) == 1 ) //forward
{
dbMoveObject(2,1);
}
if ( dbDownKey() || dbKeyState( 31 ) == 1 ) //backward
{
dbMoveObject(2,-1);
}
if (dbKeyState( 16 ) == 1 ) //Q
{
dbYRotateObject(2,dbObjectAngleY(2)-90);
dbMoveObject ( 2 , 1 );
dbYRotateObject ( 2 , dbObjectAngleY( 2 ) +90 );
}
if ( dbKeyState( 18 ) == 1 )//E
{
dbYRotateObject(2,dbObjectAngleY(2)+90);
dbMoveObject ( 2 , 1 );
dbYRotateObject ( 2 , dbObjectAngleY( 2 ) -90 );
}
if ( dbKeyState( 32 ) == 1 || dbKeyState(89) == 1)//Right
{
dbYRotateObject ( 2 , dbObjectAngleY( 2 ) +3 );
}
if ( dbKeyState( 30 ) == 1 || dbKeyState(79) == 1)//left
{
dbYRotateObject ( 2 , dbObjectAngleY( 2 ) -3 );
}
if (dbMouseClick() == 2 && !dbSpriteCollision(CURSOR_HOVER,2004) && !dbSpriteCollision(CURSOR_HOVER,2003) && !dbSpriteCollision(CURSOR_HOVER,2002))
{
int mx = dbMouseX();
int my = dbMouseY();
float OldObjAngleY = dbObjectAngleY ( 2 );
ObjectAngleY = dbWrapValue ( ( dbObjectAngleY ( 2 ) + dbMouseMoveX ( ) * 0.4f ) );
dbYRotateObject ( 2 , dbCurveAngle ( ObjectAngleY , OldObjAngleY , 6 ) );
dbPositionMouse(mx,my);
}
dbPositionObject(2, dbObjectPositionX(2),dbGetTerrainGroundHeight(1,dbObjectPositionX(2),dbObjectPositionZ(2)),dbObjectPositionZ(2));
if(dbObjectPositionY(2) > oldY + 2) dbPositionObject(2,oldX,oldY,oldZ);
player.Xloc = dbObjectPositionX(2);
player.Zloc = dbObjectPositionZ(2);
}
void CheckMainMenu (void)
{
if(dbEscapeKey())
{
while(dbEscapeKey()) {}
int Options = 0;
dbHideSprite(103);
dbShowSprite(201);
dbSetSprite(201, 1, 0);
dbShowSprite(202);
dbShowSprite(203);
dbShowSprite(204);
dbSync();
while(1)
{
failedtoclick:
dbSprite(CURSOR_HANDLER,dbMouseX()-50,dbMouseY()-50,CURSOR);
dbSprite(CURSOR_HOVER,dbMouseX()-50,dbMouseY()-50,CURSOR_HOVER);
dbSync();
if(dbEscapeKey())
{
while(dbEscapeKey()) {}
goto choosen2;
}
while(dbSpriteCollision(CURSOR_HOVER,202)) // options
{
dbSprite(CURSOR_HANDLER,dbMouseX()-50,dbMouseY()-50,CURSOR);
dbSprite(CURSOR_HOVER,dbMouseX()-50,dbMouseY()-50,CURSOR_HOVER);
dbSetSpritePriority(CURSOR,2);
dbSprite(7,(dbScreenWidth()/2)-66,(dbScreenHeight()/2)-120,7);
dbSync();
if(dbMouseClick() == 1)
{
while(dbMouseClick() == 1 && dbSpriteCollision (CURSOR_HOVER,202))
{
if(dbEscapeKey())
{
while(dbEscapeKey()) {}
goto choosen2;
}
dbSprite(CURSOR_HANDLER,dbMouseX()-50,dbMouseY()-50,CURSOR);
dbSprite(CURSOR_HOVER,dbMouseX()-50,dbMouseY()-50,CURSOR_HOVER);
dbSetSpritePriority(CURSOR,2);
dbSync();
}
if(!dbSpriteCollision(CURSOR_HOVER,202))
goto failedtoclick;
Options = 1;
goto choosen2;
}
if(dbEscapeKey())
{
while(dbEscapeKey()) {}
goto choosen2;
}
}
dbDeleteSprite(7);
while(dbSpriteCollision(CURSOR_HOVER,203)) // resume
{
dbSprite(CURSOR_HANDLER,dbMouseX()-50,dbMouseY()-50,CURSOR);
dbSprite(CURSOR_HOVER,dbMouseX()-50,dbMouseY()-50,CURSOR_HOVER);
dbSetSpritePriority(CURSOR,2);
dbSprite(7,(dbScreenWidth()/2)-66,(dbScreenHeight()/2)-32,7);
dbSync();
if(dbMouseClick() == 1)
{
while(dbMouseClick() == 1 && dbSpriteCollision (CURSOR_HOVER,203))
{
if(dbEscapeKey())
{
while(dbEscapeKey()) {}
goto choosen2;
}
dbSprite(CURSOR_HANDLER,dbMouseX()-50,dbMouseY()-50,CURSOR);
dbSprite(CURSOR_HOVER,dbMouseX()-50,dbMouseY()-50,CURSOR_HOVER);
dbSetSpritePriority(CURSOR,2);
dbSync();
}
if(!dbSpriteCollision(CURSOR_HOVER,203))
goto failedtoclick;
goto choosen2;
}
if(dbEscapeKey())
{
while(dbEscapeKey()) {}
goto choosen2;
}
}
dbDeleteSprite(7);
while(dbSpriteCollision(CURSOR_HOVER,204)) // exit game
{
dbSprite(CURSOR_HANDLER,dbMouseX()-50,dbMouseY()-50,CURSOR);
dbSprite(CURSOR_HOVER,dbMouseX()-50,dbMouseY()-50,CURSOR_HOVER);
dbSetSpritePriority(CURSOR,2);
dbSprite(7,(dbScreenWidth()/2)-66,(dbScreenHeight()/2)+56,7);
dbSync();
if(dbMouseClick() == 1)
{
while(dbMouseClick() == 1 && dbSpriteCollision (CURSOR_HOVER,204))
{
if(dbEscapeKey())
{
while(dbEscapeKey()) {}
goto choosen2;
}
dbSprite(CURSOR_HANDLER,dbMouseX()-50,dbMouseY()-50,CURSOR);
dbSprite(CURSOR_HOVER,dbMouseX()-50,dbMouseY()-50,CURSOR_HOVER);
dbSetSpritePriority(CURSOR,2);
dbSync();
}
if(!dbSpriteCollision(CURSOR_HOVER,204))
goto failedtoclick;
SaveData();
exit(0);
}
if(dbEscapeKey())
{
while(dbEscapeKey()) {}
goto choosen2;
}
}
dbDeleteSprite(7);
}
choosen2:
dbHideSprite(201);
dbHideSprite(202);
dbHideSprite(203);
dbHideSprite(204);
dbDeleteSprite(CURSOR_HANDLER);
dbDeleteSprite(CURSOR_HOVER);
dbDeleteSprite(7);
dbShowSprite(103);
}
}
void SaveData (void)
{
FILE *X;
FILE *Z;
FILE *Energy;
FILE *maxEnergy;
FILE *health;
X = fopen("Data\\cache\\X.txt","w");
fprintf(X,"%d",player.Xloc);
fclose (X);
Z = fopen("Data\\cache\\Z.txt","w");
fprintf(Z,"%d",player.Zloc);
fclose (Z);
Energy = fopen("data\\cache\\Energy.txt","w");
fprintf(Energy,"%d",player.Energy);
fclose (Energy);
maxEnergy = fopen("data\\cache\\maxEnergy.txt","w");
fprintf(maxEnergy,"%d",player.maxEnergy);
fclose(maxEnergy);
health = fopen("data\\cache\\health.txt","w");
fprintf(health,"%d",player.curhealth);
fclose(health);
}
void LoadData (void)
{
FILE *X;
char Xbuff[30];
FILE *Z;
char Zbuff[30];
FILE *Energy;
char Energybuff[30];
FILE *maxEnergy;
char maxEnergybuff[30];
FILE *health;
char healthbuff[30];
int result;
X = fopen("Data\\cache\\X.txt","r");
while(1)
{
fgets(Xbuff,30,X);
result=feof(X);
if(result != 0 )
break;
}
loadX = atoi(Xbuff);
fclose (X);
result=0;
Z = fopen("Data\\cache\\Z.txt","r");
while(1)
{
fgets(Zbuff,30,Z);
if(Zbuff != 0)
break;
}
loadZ = atoi(Zbuff);
fclose (Z);
result=0;
Energy = fopen("data\\cache\\Energy.txt","r");
while(1)
{
fgets(Energybuff,30,Energy);
result = feof(Energy);
if(result != 0)
break;
}
player.Energy = atoi(Energybuff);
fclose (Energy);
result=0;
maxEnergy = fopen("data\\cache\\\maxEnergy.txt","r");
while(1)
{
fgets(maxEnergybuff,30,maxEnergy);
result = feof(maxEnergy);
if(result != 0 )
break;
}
player.maxEnergy = atoi(maxEnergybuff);
fclose(maxEnergy);
result=0;
health = fopen("data\\cache\\health.txt","r");
while(1)
{
fgets(healthbuff,30,health);
result = feof(health);
if(result != 0 )
break;
}
player.curhealth = atoi(healthbuff);
fclose(health);
result = 0;
}
void ReadMode(void)
{
FILE *sw;
FILE *sh;
FILE *sd;
FILE *executedfile;
FILE *exefile;
char wbuff[20];
char dbuff[20];
char hbuff[20];
char exebuff[20];
char zero[2] = "0";
int result;
exefile = fopen ("Data\\cache\\executedfile.txt", "w");
if (exefile != NULL)
{
fputs(zero,exefile);
}
dbExecuteFile("GDM.exe",0," ");
executedfile = fopen ("Data\\cache\\executedfile.txt", "r");
if( executedfile != NULL)
{
while (1)
{
fgets(exebuff,20,executedfile);
result = atoi (exebuff);
if (result == 1)
break;
}
}
sw = fopen ("Data\\cache\\swidth.txt", "r");
if( sw != NULL )
{
fgets(wbuff, 20, sw);
swidth = atoi(wbuff);
}
sh = fopen ("Data\\cache\\shight.txt", "r");
if( sh != NULL )
{
fgets(hbuff,20,sh);
shight = atoi(hbuff);
}
sd = fopen ("Data\\Cache\\sdepth.txt", "r");
if( sd != NULL )
{
fgets(dbuff,20,sd);
sdepth = atoi (dbuff);
}
}
bool PlayerInRange ( int x1, int z1, int x2, int z2)
{
if ( player.Xloc > x1 && player.Xloc < x2 && player.Zloc > z1 && player.Zloc < z2)
return true;
else
return false;
}
void DisplayActionBar (void)
{
dbLoadImage("data\\images\\spell_glow.tga",2400);
dbLoadImage("Data\\images\\Action bar.tga", 2001);
dbSprite(2001,(dbScreenWidth()/2)-200, (dbScreenHeight() - 100),2001);
dbLoadImage("Data\\images\\auto attack.jpg", 2002);
dbSprite(2002, dbSpriteX(2001)+45, dbSpriteY(2001)+45,2002);
dbSetSprite(2002,1,0);
dbLoadImage("Data\\images\\death strike.jpg", 2003);
dbSprite(2003, dbSpriteX(2001)+115, dbSpriteY(2001)+45,2003);
dbSetSprite(2003,1,0);
dbLoadImage("Data\\images\\death wave.jpg", 2004);
dbSprite(2004, dbSpriteX(2001)+185, dbSpriteY(2001)+45,2004);
dbSetSprite(2004,1,0);
dbLoadImage("Data\\images\\health border.tga", 2005);
dbSprite(2005,(dbScreenWidth()/2)-300, -10,2005);
dbLoadImage("Data\\images\\yellowbox2d.jpg",2006);
dbSprite(2006,(dbScreenWidth()/2)-285, 31,2006);
//dbSprite(2007,(dbScreenWidth()/2)+190, 31,2006);
dbLoadImage("Data\\images\\SpellInProgress.jpg",2020);
dbLoadImage("Data\\images\\inventory icon.jpg", 2021);
dbSprite(2021, dbSpriteX(2001)+250, dbSpriteY(2001)+45, 2021);
dbSetSprite(2021,1,0);
dbLoadImage("data\\images\\inventory background.tga", 2022);
dbSprite(2022, dbScreenWidth()-375,dbScreenHeight()-248,2022);
dbHideSprite(2022);
}
void UpdateActionBar (void)
{
if (dbKeyState (2))
clickedautoattack = true;
if (clickedautoattack == true && !dbKeyState (2)) //auto attack (key:1)/////////////////////////////////////////////////////////////
{
clickedautoattack = false;
if (player.target_ID != -1)
{
if (PlayerAutoAttackOn == false)
PlayerAutoAttackOn = true;
else
PlayerAutoAttackOn = false;
}
else
PlayerAutoAttackOn = false;
}
if (player.target_ID == -1)
PlayerAutoAttackOn = false;//AUTO ATTACK DONE////////////////////////////////////////////////////////
if (dbKeyState (3)) // death strike (key:2)///////////////////////////////////////////////////
clickeddeathstrike = true;
if (!dbKeyState (3) && clickeddeathstrike == true && player.Energy >= 45 && !dbSpriteExist(1999))
{
clickeddeathstrike = false;
deathstrikebonus = player.base_damage*1.8;
ReduceEnergyBy(45);
}
if (deathstrikebonus != 0)
{
dbSprite(1999, dbSpriteX(2003),dbSpriteY(2003),2020);
dbSetSpriteAlpha(1999, 35);
}
else
dbDeleteSprite(1999);//death strike end/////////////////////////////////////////////
if (dbKeyState (4)) //death wave (key:3)/////////////////////////////////////////////////////////////////
{
deathstrike:
if ( iTime > deathwave_cooldown+20000 )
{
if ( !deathwave_shooted )
{
dbPositionObject(1128, player.Xloc, dbObjectPositionY(2), player.Zloc);
dbSetObjectToObjectOrientation(1128, 2);
deathwave_shooted = true;
deathwave_timer = dbTimer();
deathwave_cooldown = dbTimer ();
dbCreateAnimatedSprite(2500, "data\\images\\cooldownAnim.tga", 3,3,2500);
dbSprite(2500, dbSpriteX(2004),dbSpriteY(2004),2500);
dbSetSpriteAlpha(2500, 150);
player.Energy-=99;
}
}
}
if (deathwave_shooted == true)
{
dbMoveObject(1128, 5);
for (int i10 = 0; i10 < creatV.size(); i10++)
{
if (dbObjectCollision(1128, creatV[i10].ID) && creatV[i10].deathwave_hited_me == false)
{
ReduceObjectHealth(creatV[i10].ID, 40);
UpdateCreatureHealth(creatV[i10].ID);
creatV[i10].deathwave_hited_me = true;
}
}
if ( iTime > deathwave_timer+3500 )
{
deathwave_shooted = false;
dbPositionObject(1128, -200, -200, -200);
for (int i1 = 0; i1 < creatV.size(); i1++)
creatV[i1].deathwave_hited_me = false;
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////DEATH WAVE END
if ( (dbKeyState (4)) )
dbSprite ( 2400, dbSpriteX(2004)-10,dbSpriteY(2004)-10, 2400);
else
dbDeleteSprite(2400);
if ( dbKeyState (3))
dbSprite ( 2401, dbSpriteX(2003)-10,dbSpriteY(2003)-10, 2400);
else
dbDeleteSprite(2401);
if ( dbKeyState (2))
dbSprite ( 2402, dbSpriteX(2002)-10,dbSpriteY(2002)-10, 2400);
else
dbDeleteSprite(2402);
}
void DisplayCooldowns (void)
{
if (iTime > deathwave_cooldown+20000)
dbDeleteSprite(2500);
else
dbPlaySprite(2500,1,9, (20000/9));
}
void CreateCreature (int ID, int health, int scale, int X, int Z,int YOffset, int ori, char path[80], int loopit, bool killable, int speed, char displaypic[80], int loot_table)
{
creature creat;
creat.ID = ID;
creat.health = health;
creat.scale = scale;
creat.position.X = X;
creat.position.Z = Z;
creat.position.Y = dbGetTerrainGroundHeight(1,X,Z)+YOffset;
strcpy(creat.path, path);
creat.loopit = loopit;
creat.killable = killable;
creat.ori = ori;
creat.speed = speed;
creat.hit_timer = 0;
strcpy(creat.displaypic, displaypic);
creat.lootTable = loot_table;
creat.allow_loot = false;
creatV.push_back(creat); // add the new creature into the vector
}
void ReduceObjectHealth(int ID, int ammount)
{
for(int i = 0; i < creatV.size(); i++) // iterate through all creatures in vector
if(creatV[i].ID == ID) // If the creature's ID equals the ID of the one sent to the function
{
creatV[i].health -= ammount; //Accessing a creature and decreasing its health
}
}
void DrawObjects (void)
{
for(int i = 0; i < creatV.size();i++)
{
dbLoadObject(creatV[i].path,creatV[i].ID);
dbPositionObject( creatV[i].ID , creatV[i].position.X , creatV[i].position.Y , creatV[i].position.Z );
dbScaleObject(creatV[i].ID,creatV[i].scale,creatV[i].scale,creatV[i].scale);
dbYRotateObject(creatV[i].ID, creatV[i].ori);
dbLoadImage(creatV[i].displaypic, pic_ID_generator);
creatV[i].dpi = pic_ID_generator;
pic_ID_generator++;
creatV[i].deathwave_hited_me = false;
if(creatV[i].loopit == 1)
{
dbLoopObject(creatV[i].ID);
dbSetObjectSpeed(creatV[i].ID, 15000);
}
}
}
void CheckCreaturesLife (void)
{
for ( int i = 0; i < creatV.size(); i++)
{
if(creatV[i].health <= 0 && creatV[i].killable == true)
{
//dbDeleteObject(creatV[i].ID);
creatV[i].allow_loot = true;
}
}
}
void ApplyGlobalScripts (void)
{
int iTime_c = dbTimer();
for ( int i = 0; i < creatV.size(); i++ )
{
if ( creatV[i].killable == true )
{
if ( PlayerInRange(creatV[i].position.X-90,creatV[i].position.X+90,creatV[i].position.Z-90,creatV[i].position.Z+90) == true && creatV[i].health > 0)
{
dbPointObject(creatV[i].ID, player.Xloc, dbGetTerrainGroundHeight(1, player.Xloc, player.Zloc), player.Zloc);
if ( !dbObjectCollision(creatV[i].ID, 2))
dbMoveObject(creatV[i].ID, creatV[i].speed);
dbPositionObject(creatV[i].ID, dbObjectPositionX(creatV[i].ID), dbGetTerrainGroundHeight(1, dbObjectPositionX(creatV[i].ID), dbObjectPositionZ(creatV[i].ID)), dbObjectPositionZ(creatV[i].ID));
if ( dbObjectCollision(creatV[i].ID, 2) && iTime_c >= creatV[i].hit_timer + 3000) //reached the player
{
creatV[i].hit_timer = dbTimer();
player.curhealth--;
}
}
}
}
}
void UpdateLeftMouseKey (void)
{
if (dbMouseClick() == 1)
{
irightclicked = true;
}
else
{
if(irightclicked == true)
{
irightclicked = false;
int pick = dbPickObject(dbMouseX(),dbMouseY(),1000,5000);
for (int a = 0; a < creatV.size(); a++)
{
if (creatV[a].ID == pick)
{
dbSprite(2007,(dbScreenWidth()/2)+190, 31, creatV[a].dpi);
dbSetSpritePriority(2007,5);
UpdateCreatureHealth(creatV[a].ID);
ihaveatarget = true;
player.target_ID = creatV[a].ID;
goto pickedone;
}
else
{
dbDeleteSprite(2007);
UpdateCreatureHealth(-1);
player.target_ID = -1;
ihaveatarget = false;
}
}
}
}
pickedone:
dbSync();
}
void UpdateCreatureHealth (int ID)
{
int CCH = GetCreatureHealth(ID);
int countX = (dbScreenWidth()/2)+10;
for (int x = 20000; x < 21000; x++)
dbDeleteSprite(x);
if (ID != -1 && dbObjectExist(ID))
for (int x2 = 20000; x2 < CCH+20000;x2++)
{
dbSprite(x2, countX, 30, 1001);
countX++;
}
}
int GetCreatureHealth (int ID)
{
bool gotsmth = false;
for (int b = 0; b < creatV.size(); b++)
{
if (creatV[b].ID == ID)
{
return creatV[b].health;
gotsmth = true;
}
}
if ( !gotsmth )
return -1;
}
void UpdateAutoAttack ( void )
{
if (PlayerAutoAttackOn == true && player.target_ID != -1 && PlayerInRange(dbObjectPositionX(player.target_ID)-10,dbObjectPositionZ(player.target_ID)-10,dbObjectPositionX(player.target_ID)+10,dbObjectPositionZ(player.target_ID)+10))
{
if (iTime > autoattacktimer+1500)
{
ReduceObjectHealth(player.target_ID, player.base_damage+deathstrikebonus);
deathstrikebonus = 0;
autoattacktimer = dbTimer();
UpdateCreatureHealth(player.target_ID);
}
}
if (PlayerAutoAttackOn == true && player.target_ID != -1 && PlayerInRange(dbObjectPositionX(player.target_ID)-10,dbObjectPositionZ(player.target_ID)-10,dbObjectPositionX(player.target_ID)+10,dbObjectPositionZ(player.target_ID)+10))
{
dbSprite(2020,dbSpriteX(2002),dbSpriteY(2002),2020);
dbSetSpriteAlpha(2020, 35);
}
else if (PlayerAutoAttackOn == false)
dbDeleteSprite(2020);
}
void UpdateEnergy ( void )
{
int countX=(dbScreenWidth()/2)-170;
if (iTime > energytimer+200 )
{
energytimer = dbTimer();
player.Energy++;
if (player.Energy > 100)
player.Energy = 100;
}
for(int count = 1500;count < 1600;count++)
dbDeleteSprite(count);
for(int count = 1500; count < 1500+player.Energy; count++) //cur Energy
{
dbSprite(count,countX,50,1001);
dbSetSpritePriority(count,5);
countX++;
}
}
void ReduceEnergyBy ( int iVal )
{
player.Energy -= iVal;
}
void UpdateBag (void)
{
if ( dbMouseClick() == 1 && dbSpriteCollision(CURSOR_HOVER, 2021) )
mouseclicked = true;
if ( dbMouseClick() != 1 && mouseclicked == true )
{
mouseclicked = false;
goto togglebag;
}
if ( dbKeyState ( 48 ) ) // B --> toggle bag
pressedB = true;
if ( !dbKeyState ( 48 ) && pressedB == true )
{
pressedB = false;
togglebag:
if (bagtoggled == false)
{
bagtoggled = true;
Bag(true);
goto toggled;
}
else
{
bagtoggled = false;
Bag(false);
goto toggled;
}
toggled:
dbSync();
}
}
void Bag ( bool state )
{
switch (state)
{
case true:
{
dbShowSprite(2022);
for (int c = 2600; c <= 2615; c++)
if (dbSpriteExist(c))
dbShowSprite(c);
break;
}
case false:
{
dbHideSprite(2022);
for (int c = 2600; c <= 2615; c++)
if (dbSpriteExist(c))
dbHideSprite(c);
break;
}
}
}
void LoadCursors ( void )
{
dbLoadImage("data\\images\\hidden cursor.tga", 10000);
dbLoadImage("data\\images\\cursor2.tga", 10001);
dbLoadImage("Data\\images\\cursor_loot.tga", 10002);
}
void Cursor ( char STYLE[20] )
{
char LOOT[20] = "LOOT";
char NORMAL[20] = "NORMAL";
if (strcmp(STYLE, NORMAL) == 0)
CURSOR = 10001;
if (strcmp(STYLE, LOOT) == 0)
CURSOR = 10002;
}
void UpdateCreatureLoot (void)
{
int pickval = dbPickObject(dbSpriteX(CURSOR), dbSpriteY(CURSOR), 1001, 5500);
for (int i = 0; i < creatV.size(); i++)
{
if (creatV[i].ID == pickval)
{
if (creatV[i].allow_loot == true)
Cursor("LOOT");
else
{
Cursor("NORMAL");
goto no_loot_allowed;
}
}
}
no_loot_allowed:
if (!looting)
{
if (dbMouseClick() == 2)
{
mouseloot = true;
}
if (!dbMouseClick() && mouseloot == true)
{
mouseloot = false;
lootpick = dbPickObject(dbSpriteX(CURSOR),dbSpriteY(CURSOR), 1001, 5500);
for (int i = 0; i < creatV.size(); i++)
if (creatV[i].allow_loot == true)
{
looting = true;
break;
}
}
}
else
{
if (!dbSpriteExist(2501))
{
dbLoadImage("data\\images\\loot table.tga", 2501);
dbSprite(2501,0,170,2501); //draw loot table
}
oldX_loot = dbObjectPositionX(2);
oldY_loot = dbObjectPositionY(2);
oldZ_loot = dbObjectPositionZ(2);
for (int i = 0; i < creatV.size(); i++)
{
if (creatV[i].ID == lootpick)
{
AddLootsToTable(creatV[lootpick].lootTable); // add items to table
break;
}
}
}
//delete table when player move
if ((player.Xloc != oldX_loot || player.Zloc != oldZ_loot || dbObjectPositionY(2) != oldY_loot) && looting == true) //if pleayer moved
{
for (int i = 2501; i < 4001; i++)
dbDeleteSprite(i);
looting = false;
}
}
void AddLootsToTable (int iTable)
{
int Ypos = 150;
int total_items = 0;
switch (iTable)
{
case 1: // table 1
{
int chance = dbRND(100);
if (chance <= 60)
{
// add a health potion
dbLoadImage("Data\\images\\health potion.jpg", 2502);
dbSprite(2502,50,Ypos,2502);
Ypos+=60;
total_items++;
}
chance = dbRND(100);
if (chance <= 20)
{
// add an energy potion
dbLoadImage("Data\\images\\energy potion.jpg", 2503);
dbSprite(2503,50,Ypos,2503);
Ypos+=60;
total_items++;
}
break;
}
case 2: //table 2
{
break;
}
}
}
kod.h :
#pragma once;
void ReadMode(void);
void game (void);
void MainMenu (void);
void LoadGame (void);
void Play (void);
void GameLose (void);
void GameWin (void);
void DisplayPlayerHealth (void);
void UpdatePlayerHealth (void);
void DisplayEnergy (void);
void UpdatePlayerCamera (void);
void MovePlayer (void);
void CheckMainMenu (void);
void LoadData (void);
void SaveData (void);
bool PlayerInRange ( int x1, int z1, int x2, int z2);
void ApplyGlobalScripts (void);
void DisplayActionBar (void);
void UpdateActionBar (void);
void DisplayCooldowns (void);
void CreateCreature (int ID, int health, int scale, int X, int Z,int YOffset, int ori, char path[80], int loopit, bool killable, int speed, char displaypic[80]);
void ReduceObjectHealth(int ID, int ammount);
void DrawObjects (void);
void CheckCreaturesLife (void);
void ApplyGlobalScripts (void);
void UpdateLeftMouseKey (void);
void UpdateCreatureHealth (int ID);
int GetCreatureHealth (int ID);
void UpdateAutoAttack ( void );
void UpdateEnergy ( void );
void ReduceEnergyBy ( int iVal );
void UpdateBag (void);
struct _player;
extern _player player;
struct _player
{
int Energy;
int maxEnergy;
int curhealth;
int maxhealth;
int Xloc;
int Zloc;
int base_damage;
int target_ID;
};
spells.cpp:
#include "KoD.h"
void CastSpell (int ID)
{
switch ( ID )
{
case 1: // healing potion
{
player.curhealth+= 5;
if (player.curhealth > 10 )
player.curhealth = 10;
break;
}
case 2: //energy potion
{
player.Energy += 50;
if ( player.Energy > 100 )
player.Energy = 100;
break;
}
}
}
spells.h :
#pragma once
void CastSpell (int ID);
when i run it, my fps stuck on 1 while executing Play() function, why's that? i tried to remove all the functions in Play() but no use, what is the problem?
PS: data file attached 3 posts above, but the code there is incorrect i think.