[Add] New & Load in main menu now functioning properly.

This commit is contained in:
Tamir Atias 2012-02-03 01:43:47 +02:00
parent db79f97f31
commit 9a23bd1547
3 changed files with 42 additions and 11 deletions

View File

@ -17,12 +17,19 @@ Game::~Game(void) {
//delete _player; //delete _player;
} }
gameNavVal_t Game::Run(const string savegameIDArg) { void Game::New(const string& savegameIDArg) {
NewSavegame(savegameIDArg);
_map.Load("map");
}
void Game::Load(const string& savegameIDArg) {
LoadSavegame(savegameIDArg);
}
gameNavVal_t Game::Run(void) {
_player->SetXY(400, 400); _player->SetXY(400, 400);
_player->LoadSprites("../Data/Media/Images/Characters/Player.png", 40, 45); _player->LoadSprites("../Data/Media/Images/Characters/Player.png", 40, 45);
LoadSavegame(savegameIDArg);
int fps = 0; int fps = 0;
int frame = 0; int frame = 0;
int nextGameTick = SDL_GetTicks(); int nextGameTick = SDL_GetTicks();
@ -307,8 +314,7 @@ void Game::LoadSavegame(const string savegameIDArg) {
// Create new save if can't load file. // Create new save if can't load file.
if(!mapFile.LoadFile()) { if(!mapFile.LoadFile()) {
NewSavegame(savegameIDArg); New(savegameIDArg);
_map.Load("map");
return; return;
} }

View File

@ -25,8 +25,11 @@ class Game {
public: public:
Game(void); Game(void);
~Game(void); ~Game(void);
void New(const string& savegameIDArg);
void Load(const string& savegameIDArg);
gameNavVal_t Run(const string savegameIDArg); gameNavVal_t Run(void);
private: private:
void HandleInput(void); void HandleInput(void);

View File

@ -24,6 +24,23 @@
#endif #endif
#endif #endif
static gameNavVal_t RunGame(bool load) {
Debug::logger->message("Entering game state..");
Game* game = new Game;
if(load) {
game->Load("save");
} else {
game->New("save");
}
gameNavVal_t ret = game->Run();
delete game;
return ret;
}
#if !defined(_WIN32) || defined(_DEBUG) #if !defined(_WIN32) || defined(_DEBUG)
int main() { int main() {
#else #else
@ -78,10 +95,7 @@ int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int) {
switch(menu->Run()) { switch(menu->Run()) {
case mainMenuNewGame: case mainMenuNewGame:
delete menu; delete menu;
Debug::logger->message("Entering game state.."); switch(RunGame(false)) {
game = new Game;
switch(game->Run("save")) {
case gameMainMenu: case gameMainMenu:
menu = new MainMenu; menu = new MainMenu;
break; break;
@ -89,9 +103,17 @@ int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int) {
menuRunning = false; menuRunning = false;
break; break;
} }
delete game;
break; break;
case mainMenuLoadGame: case mainMenuLoadGame:
delete menu;
switch(RunGame(true)) {
case gameMainMenu:
menu = new MainMenu;
break;
case gameQuitGame:
menuRunning = false;
break;
}
break; break;
case mainMenuOptions: case mainMenuOptions:
break; break;