void intro_tick() { if (blanktimer > 0) { ClearScreen(BLACK); if (--blanktimer == 0) game.setmode(GM_TITLE); return; } game_tick_normal(); player->y = 0; // when script ends with WAI9999, detect it and move on to title screen ScriptInstance *script = GetCurrentScriptInstance(); if ((script && script->delaytimer == 9999) || buttonjustpushed() || VJoy::ModeAware::wasTap()) { StopScripts(); blanktimer = EXIT_DELAY; } // lower time for startup if (script && script->delaytimer && script->ip == 5) { game.showmapnametime = 0; if (script->delaytimer > 20) script->delaytimer = 20; } }
void Game::reset() { memset(inputs, 0, sizeof(inputs)); StopLoopSounds(); StopScripts(); Replay::end_record(); Replay::end_playback(); game.pause(false); game.setmode(GM_INTRO, 0, true); console.SetVisible(false); }
int main(int argc, char *argv[]) { bool inhibit_loadfade = false; bool error = false; bool freshstart; SetLogFilename("debug.txt"); if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) { staterr("ack, sdl_init failed: %s.", SDL_GetError()); return 1; } atexit(SDL_Quit); // start up inputs first thing because settings_load may remap them input_init(); // load settings, or at least get the defaults, // so we know the initial screen resolution. settings_load(); if (Graphics::init(settings->resolution)) { staterr("Failed to initialize graphics."); return 1; } if (font_init()) { staterr("Failed to load font."); return 1; } //speed_test(); //return 1; #ifdef CONFIG_DATA_EXTRACTOR if (!settings->files_extracted) { if (extract_main()) { Graphics::close(); font_close(); return 0; } else { settings->files_extracted = true; settings_save(); } } #endif if (check_data_exists()) { return 1; } Graphics::ShowLoadingScreen(); if (sound_init()) { fatal("Failed to initialize sound."); return 1; } if (trig_init()) { fatal("Failed trig module init."); return 1; } if (tsc_init()) { fatal("Failed to initialize script engine."); return 1; } if (textbox.Init()) { fatal("Failed to initialize textboxes."); return 1; } if (Carets::init()) { fatal("Failed to initialize carets."); return 1; } if (game.init()) return 1; game.setmode(GM_NORMAL); // set null stage just to have something to do while we go to intro game.switchstage.mapno = 0; //#define REPLAY #ifdef REPLAY game.switchstage.mapno = START_REPLAY; //Replay::set_ffwd(6000); //Replay::set_stopat(3500); game.switchstage.param = 1; #else //game.switchstage.mapno = LOAD_GAME; //game.pause(GP_OPTIONS); if (settings->skip_intro && file_exists(GetProfileName(settings->last_save_slot))) game.switchstage.mapno = LOAD_GAME; else game.setmode(GM_INTRO); #endif // for debug if (game.paused) { game.switchstage.mapno = 0; game.switchstage.eventonentry = 0; } if (game.switchstage.mapno == LOAD_GAME) inhibit_loadfade = true; game.running = true; freshstart = true; stat("Entering main loop..."); #ifdef __SDLSHIM__ set_console_visible(false); #endif //speed_test(); //return 1; while(game.running) { // SSS/SPS persists across stage transitions until explicitly // stopped, or you die & reload. It seems a bit risky to me, // but that's the spec. if (game.switchstage.mapno >= MAPNO_SPECIALS) { StopLoopSounds(); } // enter next stage, whatever it may be if (game.switchstage.mapno == LOAD_GAME || \ game.switchstage.mapno == LOAD_GAME_FROM_MENU) { if (game.switchstage.mapno == LOAD_GAME_FROM_MENU) freshstart = true; stat("= Loading game ="); if (game_load(settings->last_save_slot)) { fatal("savefile error"); goto ingame_error; } Replay::OnGameStarting(); if (!inhibit_loadfade) fade.Start(FADE_IN, FADE_CENTER); else inhibit_loadfade = false; } else if (game.switchstage.mapno == START_REPLAY) { stat(">> beginning replay '%s'", GetReplayName(game.switchstage.param)); StopScripts(); if (Replay::begin_playback(GetReplayName(game.switchstage.param))) { fatal("error starting playback"); goto ingame_error; } } else { if (game.switchstage.mapno == NEW_GAME || \ game.switchstage.mapno == NEW_GAME_FROM_MENU) { bool show_intro = (game.switchstage.mapno == NEW_GAME_FROM_MENU); InitNewGame(show_intro); } // slide weapon bar on first intro to Start Point if (game.switchstage.mapno == STAGE_START_POINT && \ game.switchstage.eventonentry == 91) { freshstart = true; } // switch maps if (load_stage(game.switchstage.mapno)) goto ingame_error; player->x = (game.switchstage.playerx * TILE_W) << CSF; player->y = (game.switchstage.playery * TILE_H) << CSF; } // start the level if (game.initlevel()) return 1; if (freshstart) weapon_introslide(); gameloop(); game.stageboss.OnMapExit(); freshstart = false; } shutdown: ; Replay::close(); game.close(); Carets::close(); Graphics::close(); input_close(); font_close(); sound_close(); tsc_close(); textbox.Deinit(); return error; ingame_error: ; stat(""); stat(" ************************************************"); stat(" * An in-game error occurred. Game shutting down."); stat(" ************************************************"); error = true; goto shutdown; }
void TB_StageSelect::HandleInput() { bool button_down = false; if (textbox.YesNoPrompt.IsVisible() || fMadeSelection) return; #ifdef CONFIG_USE_TAPS // taps control { int nslots = CountActiveSlots(); int total_spacing = ((nslots - 1) * LOCS_SPACING); int total_width = total_spacing + (nslots * sprites[SPR_STAGEIMAGE].w); int x = (Graphics::SCREEN_WIDTH / 2) - (total_width / 2); for (int i = 0; i < nslots; ++i) { RectI rect = Sprites::get_sprite_rect(x, LOCS_Y, SPR_STAGEIMAGE); if (VJoy::ModeAware::wasTap(rect)) { if (fSelectionIndex == i) { button_down = true; fLastButtonDown = false; VJoy::ModeAware::specScreenChanged(VJoy::ModeAware::EStageSelect1, false); VJoy::ModeAware::specScreenChanged(VJoy::ModeAware::EStageSelect2, true); } else { fSelectionIndex = i; sound(SND_MENU_MOVE); UpdateText(); } break; } x += (sprites[SPR_STAGEIMAGE].w + LOCS_SPACING); } } #endif // pad control { if (justpushed(LEFTKEY)) { MoveSelection(LEFT); } else if (justpushed(RIGHTKEY)) { MoveSelection(RIGHT); } // when user picks a location return the new script to execute button_down = button_down || buttondown(); } if (button_down && !fLastButtonDown) { int scriptno; if (!GetSlotByIndex(fSelectionIndex, NULL, &scriptno)) { stat("StageSelect: starting activation script %d", scriptno); JumpScript(scriptno, SP_MAP); } else { // dismiss "no permission to teleport" StopScripts(); } fMadeSelection = true; } fLastButtonDown = button_down; }
bool run_main(void) { if (in_gameloop) goto loop; // SSS/SPS persists across stage transitions until explicitly // stopped, or you die & reload. It seems a bit risky to me, // but that's the spec. if (game.switchstage.mapno >= MAPNO_SPECIALS) { StopLoopSounds(); } // enter next stage, whatever it may be if (game.switchstage.mapno == LOAD_GAME || \ game.switchstage.mapno == LOAD_GAME_FROM_MENU) { if (game.switchstage.mapno == LOAD_GAME_FROM_MENU) freshstart = true; NX_LOG("= Loading game =\n"); if (game_load(settings->last_save_slot)) { fatal("savefile error"); game.running = false; error = 1; return false; } Replay::OnGameStarting(); if (!inhibit_loadfade) fade.Start(FADE_IN, FADE_CENTER); else inhibit_loadfade = false; } else if (game.switchstage.mapno == START_REPLAY) { NX_LOG(">> beginning replay '%s'\n", GetReplayName(game.switchstage.param)); StopScripts(); if (Replay::begin_playback(GetReplayName(game.switchstage.param))) { fatal("error starting playback"); game.running = false; error = 1; return false; } } else { if (game.switchstage.mapno == NEW_GAME || \ game.switchstage.mapno == NEW_GAME_FROM_MENU) { static bool show_intro = (game.switchstage.mapno == NEW_GAME_FROM_MENU); InitNewGame(show_intro); } // slide weapon bar on first intro to Start Point if (game.switchstage.mapno == STAGE_START_POINT && \ game.switchstage.eventonentry == 91) { freshstart = true; } // switch maps if (load_stage(game.switchstage.mapno)) { game.running = false; error = 1; return false; } player->x = (game.switchstage.playerx * TILE_W) << CSF; player->y = (game.switchstage.playery * TILE_H) << CSF; } // start the level if (game.initlevel()) { game.running = false; error = 1; return false; } if (freshstart) weapon_introslide(); game.switchstage.mapno = -1; loop: in_gameloop = true; if (gameloop()) return true; in_gameloop = false; game.stageboss.OnMapExit(); freshstart = false; }
static void ExitInventory(void) { StopScripts(); game.setmode(GM_NORMAL); memset(inputs, 0, sizeof(inputs)); }