/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Patrick Boenzli co-programmer: ... */ #include "game_loader.h" #include "campaign.h" #include "world.h" #include "player.h" #include "orxonox.h" #include "camera.h" #include "command_node.h" #include "vector.h" #include "track.h" #include using namespace std; GameLoader* GameLoader::singletonRef = 0; GameLoader::GameLoader () {} GameLoader::~GameLoader () {} GameLoader* GameLoader::getInstance() { if(singletonRef == NULL) singletonRef = new GameLoader(); return singletonRef; } ErrorMessage GameLoader::init() { if(this->currentCampaign != NULL) this->currentCampaign->init(); } ErrorMessage GameLoader::loadCampaign(char* name) { ErrorMessage errorCode; this->currentCampaign = this->fileToCampaign(name); } ErrorMessage GameLoader::loadDebugCampaign(Uint32 campaignID) { switch(campaignID) { // Debug Level 0: Debug level used to test the base frame work. case DEBUG_CAMPAIGN_0: { Campaign* debugCampaign = new Campaign(); World* world0 = new World(DEBUG_WORLD_0); world0->setNextStoryID(WORLD_ID_1); debugCampaign->addEntity(world0, WORLD_ID_0); World* world1 = new World(DEBUG_WORLD_1); world1->setNextStoryID(WORLD_ID_GAMEEND); debugCampaign->addEntity(world1, WORLD_ID_1); this->currentCampaign = debugCampaign; break; } } } ErrorMessage GameLoader::start() { if(this->currentCampaign != NULL) this->currentCampaign->start(); } ErrorMessage GameLoader::stop() { if(this->currentCampaign != NULL) this->currentCampaign->stop(); this->currentCampaign = NULL; } ErrorMessage GameLoader::pause() { this->isPaused = true; if(this->currentCampaign != NULL) this->currentCampaign->pause(); } ErrorMessage GameLoader::resume() { this->isPaused = false; if(this->currentCampaign != NULL) this->currentCampaign->resume(); } ErrorMessage GameLoader::free() {} Campaign* GameLoader::fileToCampaign(char *name) { /* do not entirely load the campaign. just the current world before start of each world, it has to be initialized so it can load everything it needs into memory then. */ } /** \brief handle keyboard commands \param cmd: the command to handle \return true if the command was handled by the system */ bool GameLoader::worldCommand (Command* cmd) { if( !strcmp( cmd->cmd, "up_world")) { if( !cmd->bUp) { this->nextLevel(); } return true; } else if( !strcmp( cmd->cmd, "down_world")) { if( !cmd->bUp) { this->previousLevel(); } return true; } else if( !strcmp( cmd->cmd, "pause")) { if( !cmd->bUp) { if(this->isPaused) this->resume(); else this->pause(); } return true; } else if( !strcmp( cmd->cmd, "quit")) { if( !cmd->bUp) this->stop(); return true; } return false; } void GameLoader::nextLevel() { if(this->currentCampaign != NULL) this->currentCampaign->nextLevel(); } void GameLoader::previousLevel() { if(this->currentCampaign != NULL) this->currentCampaign->previousLevel(); }