int ApokalypseApp::run(){ LogDebug("Hallo Welt"); SDL_Surface *img = IMG_Load(TStringEntry(application->getDataConfig().getEntry("","backgroundimg")).getString().text()); screen->setBackground(img); if (!img){ LogWarning("Could not load image: %s",SDL_GetError()); }else{ SDL_FreeSurface(img); } Intro *intro = new Intro(screen); intro->run(); delete intro; MenuScreen *menu = new MenuScreen(screen); int menuresult = menu->run(); switch (menuresult){ case 0: break; default: {LogWarning("invalid menuresult, bailing out"); return 0; }break; }; delete menu; return 0; }
void Pi::Start() { Intro *intro = new Intro(Pi::renderer, Graphics::GetScreenWidth(), Graphics::GetScreenHeight()); ui->SetInnerWidget(ui->CallTemplate("MainMenu")); //XXX global ambient colour hack to make explicit the old default ambient colour dependency // for some models Pi::renderer->SetAmbientColor(Color(0.2f, 0.2f, 0.2f, 1.f)); ui->Layout(); Uint32 last_time = SDL_GetTicks(); float _time = 0; while (!Pi::game) { SDL_Event event; while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) Pi::Quit(); else ui->DispatchSDLEvent(event); // XXX hack // if we hit our exit conditions then ignore further queued events // protects against eg double-click during game generation if (Pi::game) while (SDL_PollEvent(&event)) {} } Pi::renderer->BeginFrame(); Pi::renderer->SetPerspectiveProjection(75, Pi::GetScrAspect(), 1.f, 10000.f); Pi::renderer->SetTransform(matrix4x4f::Identity()); intro->Draw(_time); Pi::renderer->EndFrame(); ui->Update(); ui->Draw(); Pi::renderer->SwapBuffers(); Pi::frameTime = 0.001f*(SDL_GetTicks() - last_time); _time += Pi::frameTime; last_time = SDL_GetTicks(); } ui->RemoveInnerWidget(); ui->Layout(); // UI does important things on layout, like updating keyboard shortcuts InitGame(); StartGame(); MainLoop(); }
void Event(SDL_Event* Event) { if (Event->type == SDL_QUIT) { Running = false; } switch (Current) { case Structure::STORY: story->CheckEvent(Event); break; case Structure::INTRO: intro->CheckEvent(Event); break; case Structure::MENU: menu->CheckEvent(Event); break; case Structure::INGAME: ingame->CheckEvent(Event); break; case Structure::HELP: help->CheckEvent(Event); break; } }
bool Init() { Current = Structure::INTRO; //Inicializacion de SDL if (SDL_Init(SDL_INIT_EVERYTHING) < 0) return false; //Inicializacion de Display if ((Display = SDL_SetVideoMode(1024, 768, 32, SDL_HWSURFACE | SDL_DOUBLEBUF)) == NULL) return false; //Inicializacion de ventanas if (!intro->Init()) return false; if (!menu->Init()) return false; if (!help->Init()) return false; if (!ingame->Init()) return false; if (!story->Init()) return false; return true; }
void Render(SDL_Surface* display, float camera = 0) { switch (Current) { case Structure::STORY: story->Render(display); break; case Structure::INTRO: intro->Render(display); break; case Structure::MENU: menu->Render(display); break; case Structure::INGAME: ingame->Render(display); break; case Structure::HELP: help->Render(display); break; } SDL_Flip(display); }
void render(MASTERSCREEN screen) { mxhwnd.SetTimeFlag();// set the time flag switch(screen) { case ID_INTRO: intro.update(); break; case ID_START: start.update(); break; case ID_GAME: game.update(); break; case ID_GAMEOVER: over.update(); break; case ID_LAUNCH: launch.update(); break; } if(mxhwnd.media.poistion () >= 303439-100) { mxhwnd.media.seekto(0); } }
int Loop() { switch (Current) { case Structure::STORY: Current = story->Loop(); break; case Structure::INTRO: Current = intro->Loop(); break; case Structure::MENU: Current = menu->Loop(); break; case Structure::INGAME: Current = ingame->Loop(); break; case Structure::HELP: Current = help->Loop(); break; } return Current; }
///////////////////////////////////////////////// // StageManager impl ///////////////////////////////////////////////// StageManager::StageManager(HWND hWnd) : hOwner(hWnd) { Intro* pIntro = new Intro; pIntro->SetOwnerLink(hOwner); AddEntry(INTRO, pIntro); Ingame* pIngame = new Ingame; pIngame->SetOwnerLink(hOwner); AddEntry(INGAME, pIngame); Ending* pEnding = new Ending; pEnding->SetOwnerLink(hOwner); AddEntry(ENDING, pEnding); transition(INTRO); }
void Cleanup() const { story->Cleanup(); intro->Cleanup(); menu->Cleanup(); help->Cleanup(); ingame->Cleanup(); SDL_Quit(); }
void update(MASTERSCREEN screen) { mxhwnd.SetTimeFlag(); switch(screen) { case ID_INTRO: intro.update(); break; case ID_START: start.update(); break; case ID_GAME: game.update(); break; case ID_SCORES: break; } }
inline void init() { intro.load(); start.load(); game.load(); over.load(); launch.load(); mxhwnd.HideCursor(); #ifndef WIN2K mxhwnd.InitTimer(1,1); #else mxhwnd.InitTimer(1,50); #endif mxhwnd.SetScreen(ID_INTRO); mxhwnd.media.openmp3("theme.mp3"); mxhwnd.media.play(); // 303439 }
// on load, initilization function void onload() { // load up the font table mfonts[0] = MakeFont("Verdana",14); mfonts[1] = MakeFont("Verdana",20); //mxhwnd.HideCursor(); intro.load(); start.load(); game.load(); shandle.load(); // possibly read in timer speed, to set the timer on #ifndef WIN2K mxhwnd.InitTimer(1,2); #else mxhwnd.InitTimer(1,50); #endif mxhwnd.SetScreen(ID_INTRO); }
int main(int argc, char ** argv) { GameState *st; UIUpdate *ui; GameManager* gm; // Redirect stdout and stderr to files in the user directory #ifdef _WIN32 string datadir = getUserDataDir(); string nameOut = datadir + "stdout.txt"; string nameErr = datadir + "stderr.txt"; ofstream fileOut(nameOut.c_str()); ofstream fileErr(nameErr.c_str()); StreamRedirector redirOut(cout, fileOut.rdbuf()); StreamRedirector redirErr(cerr, fileErr.rdbuf()); #endif chdirToDataDir(); SDL_Init(0); seedRandom(); new GameEngine(); st = new GameState(); // Parse command line args GEng()->cmdline = new CommandLineArgs(argc, argv); GEng()->cmdline->process(); // Load render, audio, etc according to config GEng()->cconf = new ClientConfig(); GEng()->cconf->initRender(st); GEng()->cconf->initAudio(st); GEng()->cconf->initPhysics(st); GEng()->cconf->initMods(st); loadLang(GEng()->cconf->lang.c_str()); #ifdef RELEASE // This has to be after the OpenGL init sendClientStats(); #endif // Intro if (GEng()->render->is3D()) { Intro *i = new Intro(st); i->doit(); ui = i; } else { ui = new UIUpdateNull(); } // Load the mods if (!loadMods(st, ui)) { reportFatalError("Module loading failed"); } delete(ui); ui = NULL; // Load rendering data used by all games and maps GEng()->render->loadCommonData(); gm = new GameManager(st); // For now, Emscripten doesn't have a menu #if defined(__EMSCRIPTEN__) gm->loadModBits(NULL); GameSettings *gs = new GameSettings(); gm->startGame(gm->getMapRegistry()->get("therlor_valley"), "zombies", "robot", GameSettings::behindPlayer, 1, false, gs); delete(gs); exit(0); #endif // List of mods if (GEng()->cmdline->modlist) { cout << "Available mods:\n"; vector<string>* modnames = GEng()->mm->getAvailMods(); for (vector<string>::iterator it = modnames->begin(); it != modnames->end(); ++it) { cout << " " << (*it) << "\n"; } delete(modnames); // Campaign } else if (GEng()->cmdline->campaign != "") { gm->loadModBits(NULL); Campaign *c = GEng()->mm->getSupplOrBase()->getCampaign(GEng()->cmdline->campaign); if (c == NULL) { displayMessageBox("Campaign not found: " + GEng()->cmdline->campaign); } else { gm->startCampaign(c, "robot", GameSettings::behindPlayer, 1); } // Arcade game } else if (GEng()->cmdline->map != "" && GEng()->cmdline->gametype != "" && GEng()->cmdline->unittype != "") { gm->loadModBits(NULL); GameSettings *gs = new GameSettings(); MapReg* map = gm->getMapRegistry()->get(GEng()->cmdline->map); if (map == NULL) { displayMessageBox("Map not found: " + GEng()->cmdline->map); } else { gm->startGame(map, GEng()->cmdline->gametype, GEng()->cmdline->unittype, GameSettings::behindPlayer, 1, GEng()->cmdline->host, gs); } delete(gs); // Network join } else if (GEng()->cmdline->join != "") { gm->loadModBits(NULL); gm->networkJoin(GEng()->cmdline->join, NULL); // Regular menu } else if (GEng()->render->is3D()) { Menu *m = new Menu(st, gm); m->doit(NULL); delete(m); } else { displayMessageBox("Non-interactive usage requires --campaign, --arcade or --join to be specified"); } delete(st); delete(gm); delete(GEng()->render); delete(GEng()->audio); delete(GEng()->cmdline); delete(GEng()->mm); delete(GEng()->cconf); exit(0); }
int main(int argc, char *argv[]) { // init fnkdat if(fnkdat(NULL, NULL, 0, FNKDAT_INIT) < 0) { perror("Could not initialize fnkdat"); exit(EXIT_FAILURE); } bool bShowDebug = false; for(int i=1; i < argc; i++) { //check for overiding params std::string parameter(argv[i]); if(parameter == "--showlog") { // special parameter which does not overwrite settings bShowDebug = true; } else if((parameter == "-f") || (parameter == "--fullscreen") || (parameter == "-w") || (parameter == "--window") || (parameter.find("--PlayerName=") == 0) || (parameter.find("--ServerPort=") == 0)) { // normal parameter for overwriting settings // handle later } else { printUsage(); exit(EXIT_FAILURE); } } if(bShowDebug == false) { // get utf8-encoded log file path std::string logfilePath = getLogFilepath(); const char* pLogfilePath = logfilePath.c_str(); #if defined (_WIN32) // on win32 we need an ansi-encoded filepath WCHAR szwLogPath[MAX_PATH]; char szLogPath[MAX_PATH]; if(MultiByteToWideChar(CP_UTF8, 0, pLogfilePath, -1, szwLogPath, MAX_PATH) == 0) { fprintf(stderr, "Conversion of logfile path from utf-8 to utf-16 failed\n"); exit(EXIT_FAILURE); } if(WideCharToMultiByte(CP_ACP, 0, szwLogPath, -1, szLogPath, MAX_PATH, NULL, NULL) == 0) { fprintf(stderr, "Conversion of logfile path from utf-16 to ansi failed\n"); exit(EXIT_FAILURE); } pLogfilePath = szLogPath; #endif int d = open(pLogfilePath, O_WRONLY | O_CREAT | O_TRUNC, 0644); if(d < 0) { fprintf(stderr, "Opening logfile '%s' failed\n", pLogfilePath); exit(EXIT_FAILURE); } // Hint: fileno(stdout) != STDOUT_FILENO on Win32 (see SDL_win32_main.c) if(dup2(d, fileno(stdout)) < 0) { fprintf(stderr, "Redirecting stdout failed\n"); exit(EXIT_FAILURE); } // Hint: fileno(stderr) != STDERR_FILENO on Win32 (see SDL_win32_main.c) if(dup2(d, fileno(stderr)) < 0) { fprintf(stderr, "Redirecting stderr failed\n"); exit(EXIT_FAILURE); } } fprintf(stdout, "Starting Dune Legacy " VERSION " ...\n"); fflush(stdout); if(checkForExcessPrecision() == true) { fprintf(stdout, "WARNING: Floating point operations are internally calculated with higher precision. Network game might get async. Are you using x87-FPU? Check your compile settings!\n"); fflush(stdout); } // First check for missing files std::vector<std::string> missingFiles = FileManager::getMissingFiles(); if(missingFiles.empty() == false) { // create data directory inside config directory char tmp[FILENAME_MAX]; fnkdat("data/", tmp, FILENAME_MAX, FNKDAT_USER | FNKDAT_CREAT); bool cannotShowMissingScreen = false; fprintf(stderr,"The following files are missing:\n"); std::vector<std::string>::const_iterator iter; for(iter = missingFiles.begin() ; iter != missingFiles.end(); ++iter) { fprintf(stderr," %s\n",iter->c_str()); if(iter->find("LEGACY.PAK") != std::string::npos) { cannotShowMissingScreen = true; } } fprintf(stderr,"Put them in one of the following directories:\n"); std::vector<std::string> searchPath = FileManager::getSearchPath(); std::vector<std::string>::const_iterator searchPathIter; for(searchPathIter = searchPath.begin(); searchPathIter != searchPath.end(); ++searchPathIter) { fprintf(stderr," %s\n",searchPathIter->c_str()); } if(cannotShowMissingScreen == true) { return EXIT_FAILURE; } } bool bExitGame = false; bool bFirstInit = true; bool bFirstGamestart = false; debug = false; cursorFrame = UI_CursorNormal; do { int seed = time(NULL); srand(seed); // check if configfile exists std::string configfilepath = getConfigFilepath(); if(existsFile(configfilepath) == false) { std::string userLanguage = getUserLanguage(); if(userLanguage.empty()) { userLanguage = "en"; } if(missingFiles.empty() == true) { // if all pak files were found we can create the ini file bFirstGamestart = true; createDefaultConfigFile(configfilepath, userLanguage); } } INIFile myINIFile(configfilepath); settings.general.playIntro = myINIFile.getBoolValue("General","Play Intro",false); settings.general.playerName = myINIFile.getStringValue("General","Player Name","Player"); settings.video.width = myINIFile.getIntValue("Video","Width",640); settings.video.height = myINIFile.getIntValue("Video","Height",480); settings.video.fullscreen = myINIFile.getBoolValue("Video","Fullscreen",true); settings.video.doubleBuffering = myINIFile.getBoolValue("Video","Double Buffering",true); settings.video.frameLimit = myINIFile.getBoolValue("Video","FrameLimit",true); settings.video.preferredZoomLevel = myINIFile.getIntValue("Video","Preferred Zoom Level", 0); settings.video.scaler = myINIFile.getStringValue("Video","Scaler", "scale2x"); settings.audio.musicType = myINIFile.getStringValue("Audio","Music Type","adl"); settings.audio.playMusic = myINIFile.getBoolValue("Audio","Play Music", true); settings.audio.playSFX = myINIFile.getBoolValue("Audio","Play SFX", true); settings.audio.frequency = myINIFile.getIntValue("Audio","Audio Frequency", 22050); settings.general.language = myINIFile.getStringValue("General","Language","en"); settings.network.serverPort = myINIFile.getIntValue("Network","ServerPort",DEFAULT_PORT); settings.network.metaServer = myINIFile.getStringValue("Network","MetaServer",DEFAULT_METASERVER); settings.network.debugNetwork = myINIFile.getBoolValue("Network","Debug Network",false); settings.ai.campaignAI = myINIFile.getStringValue("AI","Campaign AI",DEFAULTAIPLAYERCLASS); settings.gameOptions.gameSpeed = myINIFile.getIntValue("Game Options","Game Speed",GAMESPEED_DEFAULT); settings.gameOptions.concreteRequired = myINIFile.getBoolValue("Game Options","Concrete Required",true); settings.gameOptions.structuresDegradeOnConcrete = myINIFile.getBoolValue("Game Options","Structures Degrade On Concrete",true); settings.gameOptions.fogOfWar = myINIFile.getBoolValue("Game Options","Fog of War",false); settings.gameOptions.startWithExploredMap = myINIFile.getBoolValue("Game Options","Start with Explored Map",false); settings.gameOptions.instantBuild = myINIFile.getBoolValue("Game Options","Instant Build",false); settings.gameOptions.onlyOnePalace = myINIFile.getBoolValue("Game Options","Only One Palace",false); settings.gameOptions.rocketTurretsNeedPower = myINIFile.getBoolValue("Game Options","Rocket-Turrets Need Power",false); settings.gameOptions.sandwormsRespawn = myINIFile.getBoolValue("Game Options","Sandworms Respawn",false); settings.gameOptions.killedSandwormsDropSpice = myINIFile.getBoolValue("Game Options","Killed Sandworms Drop Spice",false); fprintf(stdout, "loading texts....."); fflush(stdout); pTextManager = new TextManager(); fprintf(stdout, "\t\tfinished\n"); fflush(stdout); if(FileManager::getMissingFiles().size() > 0) { // set back to english std::vector<std::string> missingFiles = FileManager::getMissingFiles(); fprintf(stderr,"The following files are missing for language \"%s\":\n",_("LanguageFileExtension").c_str()); std::vector<std::string>::const_iterator iter; for(iter = missingFiles.begin(); iter != missingFiles.end(); ++iter) { fprintf(stderr," %s\n",iter->c_str()); } fprintf(stderr,"Language is changed to English!\n"); settings.general.language = "en"; } for(int i=1; i < argc; i++) { //check for overiding params std::string parameter(argv[i]); if((parameter == "-f") || (parameter == "--fullscreen")) { settings.video.fullscreen = true; } else if((parameter == "-w") || (parameter == "--window")) { settings.video.fullscreen = false; } else if(parameter.find("--PlayerName=") == 0) { settings.general.playerName = parameter.substr(strlen("--PlayerName=")); } else if(parameter.find("--ServerPort=") == 0) { settings.network.serverPort = atol(argv[i] + strlen("--ServerPort=")); } } if(bFirstInit == true) { fprintf(stdout, "initializing SDL..... \t\t"); fflush(stdout); if(SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO) < 0) { fprintf(stderr, "ERROR: Couldn't initialise SDL: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } fprintf(stdout, "finished\n"); fflush(stdout); } if(bFirstGamestart == true && bFirstInit == true) { // detect 800x600 screen resolution if(SDL_VideoModeOK(800, 600, 8, SDL_HWSURFACE | SDL_FULLSCREEN) > 0) { settings.video.width = 800; settings.video.height = 600; settings.video.preferredZoomLevel = 1; myINIFile.setIntValue("Video","Width",settings.video.width); myINIFile.setIntValue("Video","Height",settings.video.height); myINIFile.setIntValue("Video","Preferred Zoom Level",1); myINIFile.saveChangesTo(getConfigFilepath()); } } Scaler::setDefaultScaler(Scaler::getScalerByName(settings.video.scaler)); SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); char strenv[] = "SDL_VIDEO_CENTERED=center"; SDL_putenv(strenv); SDL_WM_SetCaption("Dune Legacy", "Dune Legacy"); if(bFirstInit == true) { fprintf(stdout, "initializing sound..... \t");fflush(stdout); if( Mix_OpenAudio(settings.audio.frequency, AUDIO_S16SYS, 2, 1024) < 0 ) { SDL_Quit(); fprintf(stderr,"Warning: Couldn't set %d Hz 16-bit audio\n- Reason: %s\n",settings.audio.frequency,SDL_GetError()); exit(EXIT_FAILURE); } else { fprintf(stdout, "allocated %d channels.\n", Mix_AllocateChannels(6)); fflush(stdout); } } pFileManager = new FileManager( !missingFiles.empty() ); // now we can finish loading texts if(missingFiles.empty()) { pTextManager->loadData(); } if(pFileManager->exists("IBM.PAL") == true) { palette = LoadPalette_RW(pFileManager->openFile("IBM.PAL"), true); } else { // create dummy palette for showing missing files info palette = Palette(256); palette[115].r = 202; palette[115].g = 141; palette[115].b = 16; palette[255].r = 255; palette[255].g = 255; palette[255].b = 255; } screen = NULL; setVideoMode(); fprintf(stdout, "loading fonts...");fflush(stdout); pFontManager = new FontManager(); fprintf(stdout, "\t\tfinished\n"); fflush(stdout); if(!missingFiles.empty()) { // some files are missing bExitGame = true; printMissingFilesToScreen(); fprintf(stdout, "Deinitialize....."); fflush(stdout); } else { // everything is just fine and we can start the game fprintf(stdout, "loading graphics..."); fflush(stdout); pGFXManager = new GFXManager(); fprintf(stdout, "\t\tfinished\n"); fflush(stdout); fprintf(stdout, "loading sounds..."); fflush(stdout); pSFXManager = new SFXManager(); fprintf(stdout, "\t\tfinished\n"); fflush(stdout); GUIStyle::setGUIStyle(new DuneStyle); if(bFirstInit == true) { fprintf(stdout, "starting sound player..."); fflush(stdout); soundPlayer = new SoundPlayer(); fprintf(stdout, "\tfinished\n"); fprintf(stdout, "starting music player...\t"); fflush(stdout); if(settings.audio.musicType == "directory") { fprintf(stdout, "playing from music directory\n"); fflush(stdout); musicPlayer = new DirectoryPlayer(); } else if(settings.audio.musicType == "adl") { fprintf(stdout, "playing ADL files\n"); fflush(stdout); musicPlayer = new ADLPlayer(); } else if(settings.audio.musicType == "xmi") { fprintf(stdout, "playing XMI files\n"); fflush(stdout); musicPlayer = new XMIPlayer(); } else { fprintf(stdout, "failed\n"); fflush(stdout); exit(EXIT_FAILURE); } //musicPlayer->changeMusic(MUSIC_INTRO); } // Playing intro if(((bFirstGamestart == true) || (settings.general.playIntro == true)) && (bFirstInit==true)) { fprintf(stdout, "playing intro.....");fflush(stdout); Intro* pIntro = new Intro(); pIntro->run(); delete pIntro; fprintf(stdout, "\t\tfinished\n"); fflush(stdout); } bFirstInit = false; fprintf(stdout, "starting main menu...");fflush(stdout); MainMenu * myMenu = new MainMenu(); fprintf(stdout, "\t\tfinished\n"); fflush(stdout); if(myMenu->showMenu() == MENU_QUIT_DEFAULT) { bExitGame = true; } delete myMenu; fprintf(stdout, "Deinitialize....."); fflush(stdout); GUIStyle::destroyGUIStyle(); // clear everything if(bExitGame == true) { delete musicPlayer; delete soundPlayer; Mix_HaltMusic(); Mix_CloseAudio(); } delete pTextManager; delete pSFXManager; delete pGFXManager; } delete pFontManager; delete pFileManager; if(bExitGame == true) { SDL_Quit(); } fprintf(stdout, "\t\tfinished\n"); fflush(stdout); } while(bExitGame == false); // deinit fnkdat if(fnkdat(NULL, NULL, 0, FNKDAT_UNINIT) < 0) { perror("Could not uninitialize fnkdat"); exit(EXIT_FAILURE); } return EXIT_SUCCESS; }
Common::Error SkyEngine::go() { _keyPressed.reset(); uint16 result = 0; if (ConfMan.hasKey("save_slot")) { int saveSlot = ConfMan.getInt("save_slot"); if (saveSlot >= 0 && saveSlot <= 999) result = _skyControl->quickXRestore(ConfMan.getInt("save_slot")); } if (result != GAME_RESTORED) { bool introSkipped = false; if (_systemVars.gameVersion > 272) { // don't do intro for floppydemos Intro *skyIntro = new Intro(_skyDisk, _skyScreen, _skyMusic, _skySound, _skyText, _mixer, _system); bool floppyIntro = ConfMan.getBool("alt_intro"); introSkipped = !skyIntro->doIntro(floppyIntro); delete skyIntro; } if (!shouldQuit()) { _skyLogic->initScreen0(); if (introSkipped) _skyControl->restartGame(); } } _lastSaveTime = _system->getMillis(); uint32 delayCount = _system->getMillis(); while (!shouldQuit()) { _debugger->onFrame(); if (shouldPerformAutoSave(_lastSaveTime)) { if (_skyControl->loadSaveAllowed()) { _lastSaveTime = _system->getMillis(); _skyControl->doAutoSave(); } else _lastSaveTime += 30 * 1000; // try again in 30 secs } _skySound->checkFxQueue(); _skyMouse->mouseEngine(); handleKey(); if (_systemVars.paused) { do { _system->updateScreen(); delay(50); handleKey(); } while (_systemVars.paused); delayCount = _system->getMillis(); } _skyLogic->engine(); _skyScreen->processSequence(); _skyScreen->recreate(); _skyScreen->spriteEngine(); if (_debugger->showGrid()) { uint8 *grid = _skyLogic->_skyGrid->giveGrid(Logic::_scriptVariables[SCREEN]); if (grid) { _skyScreen->showGrid(grid); _skyScreen->forceRefresh(); } } _skyScreen->flip(); if (_fastMode & 2) delay(0); else if (_fastMode & 1) delay(10); else { delayCount += _systemVars.gameSpeed; int needDelay = delayCount - (int)_system->getMillis(); if ((needDelay < 0) || (needDelay > _systemVars.gameSpeed)) { needDelay = 0; delayCount = _system->getMillis(); } delay(needDelay); } } _skyControl->showGameQuitMsg(); _skyMusic->stopMusic(); ConfMan.flushToDisk(); delay(1500); return Common::kNoError; }
int main() { bool MainLoop = true; while (MainLoop){ bool GameLoop = true; Intro newIntro; if(newIntro.mShowWelcome() == 1) return 0; //Display Background newIntro.clearScreen(); newIntro.mShowBackground(); int x,y; string xCoord; string yCoord; //creates map objects. Map youMap; Map enemyMap; //sets map objects. youMap.SetMap(); enemyMap.SetMap(); //draws maps to screen for first time youMap.pDrawMap(); enemyMap.eDrawMap(); //creates all ship objects. Ship Cruiser("Cruiser",3); Ship AircraftCarrier("AircraftCarrier", 5); Ship Submarine("Submarine", 3); Ship BattleShip("BattleShip", 4); Ship Destroyer("Destroyer", 2); //Program lets player place their ships youMap.placeShips(Cruiser, youMap); youMap.placeShips(AircraftCarrier, youMap); youMap.placeShips(Submarine, youMap); youMap.placeShips(BattleShip, youMap); youMap.placeShips(Destroyer, youMap); youMap.Loading(); //draws loading bar, this next part takes a while. //Program stores enemy ships. enemyMap.rndShips(Cruiser); enemyMap.rndShips(AircraftCarrier); enemyMap.rndShips(Submarine); enemyMap.rndShips(BattleShip); enemyMap.rndShips(Destroyer); youMap.unLoading(); //Sets random shot type. youMap.shotType = 'r'; youMap.nextShot = 'w'; //sets how default ship hits and how many squares must be hit for victory. youMap.ShipNumber = 17; youMap.NumOfHits = 0; enemyMap.ShipNumber = 17; enemyMap.NumOfHits = 0; youMap.pSuc = false; enemyMap.hSuc = false; while (GameLoop){ //Main game loop youMap.pDrawMap(); enemyMap.eDrawMap(); //while player hasn't had a succesful attack it prompts him to pick a spot. while (enemyMap.hSuc == false){ enemyMap.OpenFire(); enemyMap.eDrawMap(); } enemyMap.hSuc = false; //Checks if player won and will end the game loop. if(enemyMap.NumOfHits == enemyMap.ShipNumber){ cout << "You Win!" << endl; cout << "Press any key to go back to Main." << endl; GameLoop = false; youMap.shotType = 'n'; } //Checks to see if computer fires randomly. if(youMap.shotType == 'r'){ youMap.eRndShot(); } //Checks to see if computer fires precisley. else if (youMap.shotType == 'p'){ while (youMap.pSuc == false){ youMap.nextShot = youMap.ePreciseShot(youMap.nextShot); } youMap.pSuc = false; } //checks if computer wins, it it does, ends game loop. if(youMap.NumOfHits == youMap.ShipNumber){ cout << "You Lose" << endl; cout << "Press any key to go back to Main." << endl; GameLoop = false; } }//end of while } return 0; }
int main(int argc, char *argv[]) { // init fnkdat if(fnkdat(NULL, NULL, 0, FNKDAT_INIT) < 0) { perror("Could not initialize fnkdat"); exit(EXIT_FAILURE); } bool bShowDebug = false; for(int i=1; i < argc; i++) { //check for overiding params if (strcmp(argv[i], "--showlog") == 0) bShowDebug = true; } if(bShowDebug == false) { int d = open(GetLogFilepath().c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644); if(d < 0) { perror("Opening logfile failed"); exit(EXIT_FAILURE); } if(dup2(d, STDOUT_FILENO) < 0) { perror("Redirecting stdout failed"); exit(EXIT_FAILURE); } if(dup2(d, STDERR_FILENO) < 0) { perror("Redirecting stderr failed"); exit(EXIT_FAILURE); } } // First check for missing files std::vector<std::string> MissingFiles = FileManager::getMissingFiles(LNG_ENG); if(MissingFiles.size() > 0) { // create data directory inside config directory char tmp[FILENAME_MAX]; fnkdat("data/", tmp, FILENAME_MAX, FNKDAT_USER | FNKDAT_CREAT); bool cannotShowMissingScreen = false; fprintf(stderr,"The following files are missing:\n"); std::vector<std::string>::const_iterator iter; for(iter = MissingFiles.begin() ; iter != MissingFiles.end(); ++iter) { fprintf(stderr," %s\n",iter->c_str()); if(iter->find("LEGACY.PAK") != std::string::npos) { cannotShowMissingScreen = true; } } fprintf(stderr,"Put them in one of the following directories:\n"); std::vector<std::string> searchPath = FileManager::getSearchPath(); std::vector<std::string>::const_iterator searchPathIter; for(searchPathIter = searchPath.begin(); searchPathIter != searchPath.end(); ++searchPathIter) { fprintf(stderr," %s\n",searchPathIter->c_str()); } if(cannotShowMissingScreen == true) { return EXIT_FAILURE; } } bool ExitGame = false; bool FirstInit = true; bool FirstGamestart = false; debug = false; cursorFrame = UI_CursorNormal; do { int seed = time(NULL); srand(seed); // check if configfile exists std::string configfilepath = GetConfigFilepath(); if(ExistsFile(configfilepath) == false) { int UserLanguage = GetUserLanguage(); if(UserLanguage == LNG_UNKNOWN) { UserLanguage = LNG_ENG; } if(MissingFiles.empty() == true) { // if all pak files were found we can create the ini file FirstGamestart = true; CreateDefaultConfigFile(configfilepath, UserLanguage); } } INIFile myINIFile(configfilepath); settings.General.PlayIntro = myINIFile.getBoolValue("General","Play Intro",false); settings.General.ConcreteRequired = myINIFile.getBoolValue("General","Concrete Required",true); settings.General.FogOfWar = myINIFile.getBoolValue("General","Fog of War",false); settings.General.PlayerName = myINIFile.getStringValue("General","Player Name","Player"); settings.Video.Width = myINIFile.getIntValue("Video","Width",640); settings.Video.Height = myINIFile.getIntValue("Video","Height",480); settings.Video.Fullscreen = myINIFile.getBoolValue("Video","Fullscreen",true); settings.Video.DoubleBuffering = myINIFile.getBoolValue("Video","Double Buffering",true); settings.Video.FrameLimit = myINIFile.getBoolValue("Video","FrameLimit",true); settings.Audio.MusicType = myINIFile.getStringValue("Audio","Music Type","adl"); std::string Lng = myINIFile.getStringValue("General","Language","en"); if(Lng == "en") { settings.General.setLanguage(LNG_ENG); } else if (Lng == "fr") { settings.General.setLanguage(LNG_FRE); } else if (Lng == "de") { settings.General.setLanguage(LNG_GER); } else { fprintf(stderr,"INI-File: Invalid Language \"%s\"! Default Language (en) is used.\n",Lng.c_str()); settings.General.setLanguage(LNG_ENG); } if(FileManager::getMissingFiles(settings.General.Language).size() > 0) { // set back to english std::vector<std::string> MissingFiles = FileManager::getMissingFiles(settings.General.Language); fprintf(stderr,"The following files are missing for language \"%s\":\n",settings.General.LanguageExt.c_str()); std::vector<std::string>::const_iterator iter; for(iter = MissingFiles.begin() ; iter != MissingFiles.end(); ++iter) { fprintf(stderr," %s\n",iter->c_str()); } fprintf(stderr,"Language is changed to English!\n"); settings.General.setLanguage(LNG_ENG); } lookDist[0] = 10;lookDist[1] = 10;lookDist[2] = 9;lookDist[3] = 9;lookDist[4] = 9;lookDist[5] = 8;lookDist[6] = 8;lookDist[7] = 7;lookDist[8] = 6;lookDist[9] = 4;lookDist[10] = 1; for(int i=1; i < argc; i++) { //check for overiding params if((strcmp(argv[i], "-f") == 0) || (strcmp(argv[i], "--fullscreen") == 0)) settings.Video.Fullscreen = true; else if((strcmp(argv[i], "-w") == 0) || (strcmp(argv[i], "--window") == 0)) settings.Video.Fullscreen = false; } if(SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO) < 0) { fprintf(stderr, "ERROR: Couldn't initialise SDL: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } if(FirstGamestart == true && FirstInit == true) { // detect 800x600 screen resolution if(SDL_VideoModeOK(800, 600, 8, SDL_HWSURFACE | SDL_FULLSCREEN) > 0) { settings.Video.Width = 800; settings.Video.Height = 600; myINIFile.setIntValue("Video","Width",settings.Video.Width); myINIFile.setIntValue("Video","Height",settings.Video.Height); myINIFile.SaveChangesTo(GetConfigFilepath()); } } SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); char strenv[] = "SDL_VIDEO_CENTERED=center"; SDL_putenv(strenv); SDL_WM_SetCaption("Dune Legacy", "Dune Legacy"); if(FirstInit == true) { fprintf(stdout, "initialising sound..... \t");fflush(stdout); if( Mix_OpenAudio(22050, AUDIO_S16SYS, 2, 1024) < 0 ) { SDL_Quit(); fprintf(stderr,"Warning: Couldn't set 22050 Hz 16-bit audio\n- Reason: %s\n",SDL_GetError()); exit(EXIT_FAILURE); } else { fprintf(stdout, "allocated %d channels.\n", Mix_AllocateChannels(4)); fflush(stdout); } } pFileManager = new FileManager( (MissingFiles.size() > 0) ); if(pFileManager->exists("IBM.PAL") == true) { palette = LoadPalette_RW(pFileManager->OpenFile("IBM.PAL"), true); } else { // create dummy palette for showing missing files info palette = Palette(256); palette[255].r = 255; palette[255].g = 255; palette[255].b = 255; } screen = NULL; setVideoMode(); fprintf(stdout, "loading fonts.....");fflush(stdout); pFontManager = new FontManager(); fprintf(stdout, "\t\tfinished\n"); fflush(stdout); if(MissingFiles.size() > 0) { // some files are missing ExitGame = true; PrintMissingFilesToScreen(); fprintf(stdout, "Deinitialize....."); fflush(stdout); } else { // everything is just fine and we can start the game //get the house palettes houseColor[HOUSE_ATREIDES] = COLOR_ATREIDES; houseColor[HOUSE_ORDOS] = COLOR_ORDOS; houseColor[HOUSE_HARKONNEN] = COLOR_HARKONNEN; houseColor[HOUSE_SARDAUKAR] = COLOR_SARDAUKAR; houseColor[HOUSE_FREMEN] = COLOR_FREMEN; houseColor[HOUSE_MERCENARY] = COLOR_MERCENARY; fprintf(stdout, "loading graphics....."); fflush(stdout); if((pGFXManager = new GFXManager()) == NULL) { fprintf(stderr,"main: Cannot create GFXManager!\n"); exit(EXIT_FAILURE); } fprintf(stdout, "\t\tfinished\n"); fflush(stdout); fprintf(stdout, "loading sounds....."); fflush(stdout); if((pSFXManager = new SFXManager()) == NULL) { fprintf(stderr,"main: Cannot create SFXManager!\n"); exit(EXIT_FAILURE); } fprintf(stdout, "\t\tfinished\n"); fflush(stdout); fprintf(stdout, "loading texts....."); fflush(stdout); if((pTextManager = new TextManager()) == NULL) { fprintf(stderr,"main: Cannot create TextManager!\n"); exit(EXIT_FAILURE); } fprintf(stdout, "\t\tfinished\n"); fflush(stdout); GUIStyle::SetGUIStyle(new DuneStyle); if(FirstInit == true) { fprintf(stdout, "starting sound player..."); fflush(stdout); soundPlayer = new SoundPlayer(); fprintf(stdout, "\tfinished\n"); fprintf(stdout, "starting music player...\t"); fflush(stdout); if(settings.Audio.MusicType == "directory") { fprintf(stdout, "playing from music directory\n"); fflush(stdout); musicPlayer = new DirectoryPlayer(); } else if(settings.Audio.MusicType == "adl") { fprintf(stdout, "playing ADL files\n"); fflush(stdout); musicPlayer = new ADLPlayer(); } else if(settings.Audio.MusicType == "xmi") { fprintf(stdout, "playing XMI files\n"); fflush(stdout); musicPlayer = new XMIPlayer(); } else { fprintf(stdout, "failed\n"); fflush(stdout); exit(EXIT_FAILURE); } //musicPlayer->changeMusic(MUSIC_INTRO); } // Playing intro if(((FirstGamestart == true) || (settings.General.PlayIntro == true)) && (FirstInit==true)) { fprintf(stdout, "playing intro.....");fflush(stdout); Intro* pIntro = new Intro(); pIntro->run(); delete pIntro; fprintf(stdout, "\t\tfinished\n"); fflush(stdout); } FirstInit = false; fprintf(stdout, "starting main menu.......");fflush(stdout); MainMenu * myMenu = new MainMenu(); fprintf(stdout, "\tfinished\n"); fflush(stdout); if(myMenu->showMenu() == -1) { ExitGame = true; } delete myMenu; fprintf(stdout, "Deinitialize....."); fflush(stdout); GUIStyle::DestroyGUIStyle(); // clear everything if(ExitGame == true) { delete musicPlayer; delete soundPlayer; Mix_HaltMusic(); Mix_CloseAudio(); } delete pTextManager; delete pSFXManager; delete pGFXManager; } delete pFontManager; delete pFileManager; if(ExitGame == true) { SDL_Quit(); } fprintf(stdout, "\t\tfinished\n"); fflush(stdout); } while(ExitGame == false); // deinit fnkdat if(fnkdat(NULL, NULL, 0, FNKDAT_UNINIT) < 0) { perror("Could not uninitialize fnkdat"); exit(EXIT_FAILURE); } return EXIT_SUCCESS; }