The return keyword in this block:
{
if(g_eMenuMode == eMenuMain)
{
////////////////////////////////////////////
dbSprite(2, 0, 0, 2);
dbSizeSprite(2, (dbScreenWidth()),(dbScreenHeight()));
dbSetSprite(2, 1, 0);
///////////////////////////////////////
MakeButton(3, 3, 4, 4, (dbScreenWidth()/2-100), (dbScreenHeight()/2+200), 0);
////////////////////////////////
if(GetButtonStatus(3)==1&&dbMouseClick()==1)
{
return;
}
///////////////////////////////
}
}
Will only return out of that function. What it does is just exit out of that function wherever it is called, but it doesn't exit the program. Right after it exits out of that function, it will go back to the function it came from, and everything is running from while(LoopGDK()). You need some way to communicate (perhaps a bool) with 'while(LoopGDK())', so that if the bool is true, the while loop breaks.
Try this:
#include "DarkGDK.h"
#include "Main.h"
bool g_exit; // variable that is set to true to exit
/////////////////////////////////////////////////////////////////////////////////
enum eMode {
eGameSetup ,
eGameIntro,
eGameMenu,
eGameLoadingMap,
eGamePlayingSP,
eGamePlayingMP,
eGameSelectingWeapon,
eGameSpectating,
eGameWin,
eGameOver,
eGameReset};
eMode g_eGameMode = eGameSetup;
enum eMenu{
eMenuMain,
eMenuOptions,
};
eMenu g_eMenuMode = eMenuMain;
void GameSetup(void);
void GameIntro(void);
void GameMenu(void);
void GameLoadingMap(void);
void GamePlayingSP(void);
void GamePlayingMP(void);
void GameSelectingWeapon(void);
void GameSpectating(void);
void GameWin(void);
void GameOver(void);
void GameReset(void);
///////////////////////////////////////////////////////////////////////////////////
void LoadMenuFiles(void);
////////////////////////
#define ESCAPE_KEY 1
int IntroTime = 100;
////////////////////////
///////////////////////////////////////////////////////////////////////////////////
void MainGame(void);
void DarkGDK ( void )
{
dbSyncOn();
dbSyncRate(60);
g_exit = false;
while ( LoopGDK ( ) )
{
dbSync();
MainGame();
if(g_exit)
return;
}
return;
}
void MainGame ( void )
{
switch ( g_eGameMode )
{
case eGameSetup:
GameSetup(); break;
case eGameIntro:
GameIntro(); break;
case eGameMenu:
GameMenu(); break;
case eGameLoadingMap:
GameLoadingMap(); break;
case eGamePlayingSP:
GamePlayingSP(); break;
case eGamePlayingMP:
GamePlayingMP(); break;
case eGameSelectingWeapon:
GameSelectingWeapon(); break;
case eGameSpectating:
GameSpectating(); break;
case eGameWin:
GameWin(); break;
case eGameOver:
GameOver(); break;
case eGameReset:
GameReset(); break;
}
}
///////////////////////////////////////////////////////////////////////////////
void GameSetup(void)
{
dbSetWindowOff();
dbSetWindowTitle("Global Warning");
dbSetDisplayMode(1024,768,32);
dbDisableEscapeKey();
LoadMenuFiles();
g_eGameMode = eGameIntro;
}
void GameIntro(void)
{
dbSprite(1, 0, 0, 1);
dbSizeSprite( 1, (dbScreenWidth()),(dbScreenHeight()));
dbSetSprite(1, 1, 0);
IntroTime = IntroTime - 1;
/////////////////////////////////////////////////////////////////
if(dbKeyState(ESCAPE_KEY)||dbMouseClick()==1)
{
dbDeleteSprite(1);
g_eGameMode = eGameMenu;
}
if(IntroTime == 0)
{
dbDeleteSprite(1);
g_eGameMode = eGameMenu;
}
///////////////////////////////////////////////////////////////////
}
void GameMenu(void)
{
if(g_eMenuMode == eMenuMain)
{
////////////////////////////////////////////
dbSprite(2, 0, 0, 2);
dbSizeSprite(2, (dbScreenWidth()),(dbScreenHeight()));
dbSetSprite(2, 1, 0);
///////////////////////////////////////
MakeButton(3, 3, 4, 4, (dbScreenWidth()/2-100), (dbScreenHeight()/2+200), 0);
////////////////////////////////
if(GetButtonStatus(3)==1&&dbMouseClick()==1)
{
//return;
g_exit = true; // Setting g_exit to true should break the while loop in the main function
}
///////////////////////////////
}
}
void GameLoadingMap(void)
{
}
void GamePlayingSP(void)
{
}
void GamePlayingMP(void)
{
}
void GameSelectingWeapon(void)
{
}
void GameSpectating(void)
{
}
void GameWin(void)
{
}
void GameOver(void)
{
}
void GameReset(void)
{
}
////////////////////////////////////////////////////////////////////////////////
void LoadMenuFiles(void)
{
dbLoadImage("Media\\Images\\IntroPic.jpg", 1);
dbLoadImage("Media\\Images\\MenuBG.jpg",2);
dbLoadImage("Media\\Images\\Buttons\\BlackExit.png", 3);
dbLoadImage("Media\\Images\\Buttons\\GreyExit.png", 4);
}
But I didn't test it, so there could be a typo.
#ifdef _DEBUG
FixBugs(All);
#endif