void LevelScene::initPauseMenu3()
{
    m_pauseMenu_opened=false;
    m_pauseMenuID=3;
    m_pauseMenu.setParentScene(this);
    m_pauseMenu.construct(
                //% "Pause"
                qtTrId("LVL_MENU_PAUSE_TTL"),
                PGE_MenuBox::msg_info, PGE_Point(-1,-1),
                ConfigManager::setup_menu_box.box_padding,
                ConfigManager::setup_menu_box.sprite);
    m_pauseMenu.clearMenu();

    std::vector<std::string> items;
    //% "Continue"
    items.push_back(qtTrId("LVL_MENU_PAUSE_CONTINUE"));
    //% "Replay level"
    items.push_back(qtTrId("LVL_MENU_PAUSE_REPLAY"));
    //% "Quit"
    items.push_back(qtTrId("LVL_MENU_PAUSE_EXIT"));

    m_pauseMenu.addMenuItems(items);
    m_pauseMenu.setRejectSnd(obj_sound_role::MenuPause);
    m_pauseMenu.setMaxMenuItems(3);
    m_isPauseMenu=false;
    m_isTimeStopped=false;
}
int GameOverScene::exec()
{
    PGE_QuestionBox continueOrQuit(this, "Game Over!", PGE_MenuBox::msg_info, PGE_Point(-1,-1),
                                   ConfigManager::setup_menu_box.box_padding,
                                   ConfigManager::setup_message_box.sprite);
    QStringList items;
    items<<"Continue";
    items<<"Quit";
    continueOrQuit.addMenuItems(items);
    continueOrQuit.setRejectSnd(obj_sound_role::BlockSmashed);
    continueOrQuit.exec();

    if (items[continueOrQuit.answer()] == "Continue")
        return GameOverSceneResult::CONTINUE;

    return GameOverSceneResult::QUIT;
}
Example #3
0
void TitleScene::processMenu()
{
    if(doExit) return;
    if(!menu.isSelected()) return;

    if(menu.isAccepted())
    {
        menustates[_currentMenu].first = menu.currentItemI();
        menustates[_currentMenu].second = menu.offset();

        QString value = menu.currentItem().value;
        switch(_currentMenu)
        {
            case menu_main:
                if(value=="game1p")
                {
                    numOfPlayers=1;
                    menuChain.push(_currentMenu);
                    setMenu(menu_playepisode);
                }
                else
                if(value=="game2p")
                {
                    numOfPlayers=2;
                    menuChain.push(_currentMenu);
                    setMenu(menu_playepisode);
                }
                else
                if(value=="gamebt")
                {
                    menuChain.push(_currentMenu);
                    setMenu(menu_playlevel);
                }
                else
                if(value=="Options")
                {
                    menuChain.push(_currentMenu);
                    setMenu(menu_options);
                }
                else
                if(value=="Exit")
                {
                    ret = ANSWER_EXIT;
                    fader.setNull();
                    doExit=true;
                }
                else
                {
                    PGE_MsgBox msgBox(this, QString("Sorry, is not implemented yet..."),
                                      PGE_MsgBox::msg_warn);
                    fader.setRatio(0.5);
                    PGE_Window::setCursorVisibly(true);
                    msgBox.exec();
                    PGE_Window::setCursorVisibly(false);
                    fader.setNull();
                    menu.resetState();
                }
            break;
            case menu_playepisode:
                {
                    if(value=="noworlds")
                    {
                        //do nothing!
                        menu.resetState();
                    }
                    else
                    {
                        result_episode.worldfile = value;
                        result_episode.character = 0;
                        result_episode.savefile = "save1.savx";
                        if(numOfPlayers>1)
                            ret = ANSWER_PLAYEPISODE_2P;
                        else
                            ret = ANSWER_PLAYEPISODE;
                        fader.setFade(10, 1.0f, 0.06f);
                        doExit=true;
                        menu.resetState();
                    }
                }
            break;
            case menu_playlevel:
                if(value=="nolevel")
                {
                    //do nothing!
                    menu.resetState();
                }
                else
                {
                    result_level.levelfile = value;
                    ret = ANSWER_PLAYLEVEL;
                    fader.setFade(10, 1.0f, 0.06f);
                    doExit=true;
                    menu.resetState();
                }
            break;
            case menu_options:
                if(value=="tests")
                {
                    menuChain.push(_currentMenu);
                    setMenu(menu_tests);
                }
                else
                if(value=="testboxes")
                {
                    menuChain.push(_currentMenu);
                    setMenu(menu_testboxes);
                }
                else
                if(value=="controls")
                {
                    menuChain.push(_currentMenu);
                    setMenu(menu_controls);
                }
                else
                if(value=="videosetup")
                {
                    menuChain.push(_currentMenu);
                    setMenu(menu_videosettings);
                }
                else
                {
                    PGE_MsgBox msgBox(this, QString("Dummy"),
                                      PGE_MsgBox::msg_warn);
                    msgBox.exec();
                    menu.resetState();
                }
            break;
            case menu_controls:
                if(value=="control_plr1")
                {
                    menuChain.push(_currentMenu);
                    setMenu(menu_controls_plr1);
                }
                else
                if(value=="control_plr2")
                {
                    menuChain.push(_currentMenu);
                    setMenu(menu_controls_plr2);
                }
            break;
            case menu_controls_plr1:

            break;
            case menu_controls_plr2:

            break;
            case menu_tests:
                if(value=="credits")
                {
                    ret = ANSWER_CREDITS;
                    doExit=true;
                }
                else
                if(value=="loading")
                {
                    ret = ANSWER_LOADING;
                    doExit=true;
                }
                else
                if(value=="gameover")
                {
                    ret = ANSWER_GAMEOVER;
                    doExit=true;
                }
            break;
            case menu_testboxes:
                if(value=="messagebox")
                {
                    PGE_MsgBox msg(this, "This is a small message box without texture\nЭто маленкая коробочка-сообщение без текстуры", PGE_BoxBase::msg_info_light);
                    msg.exec();

                    PGE_MsgBox msg2(this, "This is a small message box with texture\nЭто маленкая коробочка-сообщение с текстурой", PGE_BoxBase::msg_info, PGE_Point(-1,-1),
                                    ConfigManager::setup_message_box.box_padding,
                                    ConfigManager::setup_message_box.sprite);
                    msg2.exec();
                    menu.resetState();
                }
                else
                if(value=="menubox")
                {
                    PGE_MenuBox menubox(this, "Select something", PGE_MenuBox::msg_info, PGE_Point(-1,-1),
                                         ConfigManager::setup_menu_box.box_padding,
                                         ConfigManager::setup_message_box.sprite);
                    QStringList items;
                    items<<"Menuitem 1";
                    items<<"Menuitem 2";
                    items<<"Menuitem 3";
                    items<<"Menuitem 4";
                    items<<"Menuitem 5";
                    items<<"Menuitem 6";
                    items<<"Menuitem 7";
                    items<<"Menuitem 8";
                    items<<"Menuitem 9";
                    items<<"Menuitem 10";
                    items<<"Menuitem 11";
                    menubox.addMenuItems(items);
                    menubox.setRejectSnd(obj_sound_role::MenuPause);
                    menubox.setMaxMenuItems(5);
                    menubox.exec();

                    if(menubox.answer()>=0)
                    {
                        PGE_MsgBox msg(this, "Your answer is:\n"+items[menubox.answer()], PGE_BoxBase::msg_info_light, PGE_Point(-1,-1),
                                ConfigManager::setup_message_box.box_padding,
                                ConfigManager::setup_message_box.sprite);
                        msg.exec();
                    }

                    menu.resetState();
                }
                else
                if(value=="inputbox")
                {
                    PGE_TextInputBox text(this, "Type a text", PGE_BoxBase::msg_info_light);
                    text.exec();

                    PGE_MsgBox msg(this, "Typed a text:\n"+text.inputText(), PGE_BoxBase::msg_info_light);
                    msg.exec();
                    menu.resetState();
                }
                else if (value=="questionbox")
                {
                    PGE_QuestionBox hor(this, "AHHHH?", PGE_MenuBox::msg_info, PGE_Point(-1,-1),
                                        ConfigManager::setup_menu_box.box_padding,
                                        ConfigManager::setup_message_box.sprite);
                    QStringList items;
                    items<<"One";
                    items<<"Two";
                    items<<"Three";
                    items<<"Four";
                    items<<"Five";
                    items<<"Six";
                    items<<"Seven";
                    hor.addMenuItems(items);
                    hor.setRejectSnd(obj_sound_role::BlockSmashed);
                    hor.exec();
                    if(hor.answer()>=0)
                    {
                        PGE_MsgBox msg(this, "Answer on so dumb question is:\n"+items[hor.answer()], PGE_BoxBase::msg_info_light, PGE_Point(-1,-1),
                                ConfigManager::setup_message_box.box_padding,
                                ConfigManager::setup_message_box.sprite);
                        msg.exec();
                    }
                    menu.resetState();
                }
            break;
            case menu_dummy_and_big:
                menu.resetState();
                break;
        default:
            break;

        }
    }
    else
    {
        switch(_currentMenu)
        {
            case menu_main:
                menu.reset();
                menu.setCurrentItem(4);
            break;
            case menu_options:
            AppSettings.apply();
            AppSettings.save();
            PGE_Audio::playSoundByRole(obj_sound_role::Bonus1up);
        default:
            if(menu.isKeyGrabbing())
                menu.reset();
            else
            if(menuChain.size()>0)
            {
                menu.reset();
                setMenu((CurrentMenu)menuChain.pop());
            }
            break;
        }
    }
}
Example #4
0
int main(int argc, char *argv[])
{
    std::vector<std::string> args;
    for(int i = 0; i < argc; i++)
        args.emplace_back(argv[i]);

    #ifdef __EMSCRIPTEN__
    args.emplace_back(PGE_RUN_SINGLE_LEVEL);
    #endif

    // Parse --version or --install low args
    if(!PGEEngineApp::parseLowArgs(args))
        return 0;

    // RAII for loaded/initialized libraries and modules
    PGEEngineApp  app;
    //Initialize Qt's subsystem
    AppPathManager::initAppPath();
    //Load settings
    app.loadSettings();
    //Init log writer
    app.loadLogger();
    //Initialize translation sub-system
    app.loadTr();
    // Parse high arguments
    app.parseHighArgs(args);

    // Initializing SDL
    if(app.initSDL())
    {
        //% "Unable to init SDL!"
        PGE_Window::printSDLError(qtTrId("SDL_INIT_ERROR"));
        pLogDebug("<Application closed with failure>");
        return 1;
    }

    if(g_flags.audioEnabled && app.initAudio(g_flags.audioEnabled))
    {
        std::string msg = "Unable to load audio sub-system!\n";
        msg += app.errorAudio();
        msg += "\n\nContinuing without sound...";
        pLogWarning(msg.c_str());
        SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING,
                                 "Audio subsystem Error",
                                 msg.c_str(),
                                 nullptr);
        g_flags.audioEnabled = false;
    }

    if(app.initWindow(INITIAL_WINDOW_TITLE, g_flags.rendererType))
    {
        pLogDebug("<Application closed with failure>");
        return 1;
    }

    app.loadJoysticks();
    SDL_PumpEvents();

    if(g_AppSettings.fullScreen)
        pLogDebug("Toggle fullscreen...");

    #ifdef __APPLE__
    macosReceiveOpenFile();
    #endif

    PGE_Window::setFullScreen(g_AppSettings.fullScreen);
    GlRenderer::resetViewport();
    //Init font manager
    app.initFontBasics();
    pLogDebug("Showing window...");
    SDL_ShowWindow(PGE_Window::window);
    pLogDebug("Clear screen...");
    GlRenderer::clearScreen();
    GlRenderer::flush();
    GlRenderer::repaint();
    SDL_PumpEvents();
    /************************************************
     *      Check & ask for configuration pack      *
     ************************************************/
    //Process config manager screen
    {
        // Create configs folder if not exists
        app.createConfigsDir();
        // Initialize config selection screen
        ConfigSelectScene GOScene;

        // Are any config packs exists?
        if(!GOScene.hasConfigPacks())
        {
            pLogCritical("Config packs not found");
            SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
                                     //% "Config packs not found"
                                     qtTrId("ERROR_NO_CONFIG_PACKS_TTL").c_str(),
                                     /*% "Can't start game, because available\n"
                                         "configuration packages are not found!" */
                                     qtTrId("ERROR_NO_CONFIG_PACKS_TEXT").c_str(),
                                     PGE_Window::window);
            return 2;
        }

        std::string configPath_manager = GOScene.isPreLoaded();

        if(!g_fileToOpen.empty())
        {
            //% "Choose a game to test:"
            GOScene.setLabel(qtTrId("CONFIG_SELECT_TEST"));
        }

        //If application have ran a first time or target configuration is not exist
        if(configPath_manager.empty() && g_configPackPath.empty())
        {
            //Ask for configuration
            if(GOScene.exec() == 1)
                g_configPackPath = GOScene.currentConfigPath;
            else
                return 2;
        }
        else if(!configPath_manager.empty() && g_configPackPath.empty())
            g_configPackPath = GOScene.currentConfigPath;

        pLogDebug("Opening of the configuration package...");
        ConfigManager::setConfigPath(g_configPackPath);

        pLogDebug("Initialization of basic properties...");

        if(!ConfigManager::loadBasics())
        {
            pLogDebug("<Application closed with failure>");
            return 1;
        }

        app.enableConfigManager();

        if(!ConfigManager::config_name.empty())
            PGE_Window::setWindowTitle(ConfigManager::config_name);

        pLogDebug("Current scene resolution: %d x %d", PGE_Window::Width, PGE_Window::Height);
        pLogDebug("Config pack scene resolution: %d x %d", ConfigManager::viewport_width, ConfigManager::viewport_height);

        if(ConfigManager::viewport_width != static_cast<unsigned int>(PGE_Window::Width) ||
           ConfigManager::viewport_height != static_cast<unsigned int>(PGE_Window::Height))
        {
            PGE_Window::changeViewportResolution(ConfigManager::viewport_width, ConfigManager::viewport_height);
            pLogDebug("Using scene resolution: %d x %d", ConfigManager::viewport_width, ConfigManager::viewport_height);
        }

        pLogDebug("Configuration package successfully loaded!");

        if(g_flags.audioEnabled)
        {
            PGE_MusPlayer::setVolume(g_AppSettings.volume_music);
            pLogDebug("Build SFX index cache...");
            ConfigManager::buildSoundIndex(); //Load all sound effects into memory
        }

        //Init font manager
        app.initFontFull();
    }

    if(!g_fileToOpen.empty())
    {
        g_GameState.reset();
        //Apply custom game parameters from command line
        g_flags.applyTestSettings(g_GameState);

        if(Files::hasSuffix(g_fileToOpen, ".lvl") || Files::hasSuffix(g_fileToOpen, ".lvlx"))
        {
            g_GameState.LevelFile = g_fileToOpen;
            g_GameState.isEpisode = false;
            g_GameState.isTestingModeL = true;
            g_GameState.isTestingModeW = false;
            g_flags.testLevel = true;
            g_flags.testWorld = false;
            goto PlayLevel;
        }
        else if(Files::hasSuffix(g_fileToOpen, ".wld") || Files::hasSuffix(g_fileToOpen, ".wldx"))
        {
            g_Episode.character = 1;
            g_Episode.savefile = "save1.savx";
            g_Episode.worldfile = g_fileToOpen;
            g_GameState._episodePath = DirMan(Files::dirname(g_fileToOpen)).absolutePath() + "/";
            g_GameState.saveFileName = g_Episode.savefile;
            g_GameState.isEpisode = true;
            g_GameState.WorldFile = g_fileToOpen;
            g_GameState.isTestingModeL = false;
            g_GameState.isTestingModeW = true;
            g_flags.testLevel = false;
            g_flags.testWorld = true;
            goto PlayWorldMap;
        }
    }

    if(g_AppSettings.interprocessing)
    {
        //Apply custom game parameters from command line
        g_flags.applyTestSettings(g_GameState);
        goto PlayLevel;
    }

LoadingScreen:
    {
        LoadingScene ttl;
        ttl.setWaitTime(15000);
        ttl.init();
        ttl.m_fader.setFade(10, 0.0, 0.01);
        int ret = ttl.exec();

        if(ttl.doShutDown())
            ret = -1;

        if(ret == -1)
            goto ExitFromApplication;

        goto MainMenu;
    }
CreditsScreen:
    {
        CreditsScene ttl;
        ttl.setWaitTime(30000);
        ttl.init();
        ttl.m_fader.setFade(10, 0.0, 0.01);
        int ret = ttl.exec();

        if(ttl.doShutDown())
            ret = -1;

        if(ret == -1) goto ExitFromApplication;

        if(g_flags.testWorld)
            goto ExitFromApplication;

        goto MainMenu;
    }
GameOverScreen:
    {
        GameOverScene GOScene;
        int result = GOScene.exec();

        if(result == GameOverSceneResult::CONTINUE)
        {
            if(g_GameState.isHubLevel)
                goto PlayLevel;
            else
                goto PlayWorldMap;
        }

        if(g_flags.testWorld)
            goto ExitFromApplication;

        goto MainMenu;
    }
MainMenu:
    {
        g_GameState.reset();
        std::shared_ptr<TitleScene> iScene(new TitleScene());
        iScene->init();
        iScene->m_fader.setFade(10, 0.0, 0.02);
        int answer = iScene->exec();
        PlayLevelResult   res_level   = iScene->m_result_level;
        PlayEpisodeResult res_episode = iScene->m_result_episode;

        if(iScene->doShutDown())
            answer = TitleScene::ANSWER_EXIT;

        switch(answer)
        {
        case TitleScene::ANSWER_EXIT:
            goto ExitFromApplication;

        case TitleScene::ANSWER_CREDITS:
            goto CreditsScreen;

        case TitleScene::ANSWER_LOADING:
            goto LoadingScreen;

        case TitleScene::ANSWER_GAMEOVER:
            goto GameOverScreen;

        case TitleScene::ANSWER_PLAYLEVEL:
        {
            g_jumpOnLevelEndTo = RETURN_TO_MAIN_MENU;
            g_GameState.isEpisode = false;
            g_GameState.numOfPlayers = 1;
            g_GameState.LevelFile = res_level.levelfile;
            g_GameState._episodePath.clear();
            g_GameState.saveFileName.clear();
            g_GameState.isTestingModeL = true;
            goto PlayLevel;
        }

        case TitleScene::ANSWER_PLAYEPISODE:
        case TitleScene::ANSWER_PLAYEPISODE_2P:
        {
            g_jumpOnLevelEndTo = RETURN_TO_WORLDMAP;
            g_GameState.numOfPlayers = (answer == TitleScene::ANSWER_PLAYEPISODE_2P) ? 2 : 1;
            PlayerState plr;
            plr._chsetup = FileFormats::CreateSavCharacterState();
            plr.characterID = 1;
            plr.stateID = 1;
            plr._chsetup.id = 1;
            plr._chsetup.state = 1;
            g_GameState.setPlayerState(1, plr);
            plr.characterID = 2;
            plr.stateID = 1;
            plr._chsetup.id = 2;
            plr._chsetup.state = 1;
            g_GameState.setPlayerState(2, plr);
            g_GameState.isEpisode = true;
            g_Episode = res_episode;
            g_GameState._episodePath = DirMan(Files::dirname(g_Episode.worldfile)).absolutePath() + "/";
            g_GameState.saveFileName = g_Episode.savefile;
            g_GameState.load();
            goto PlayWorldMap;
        }

        default:
            goto PlayWorldMap;
        }

        //goto PlayLevel;
    }
PlayWorldMap:
    {
        WldExit::ExitWorldCodes wldExitCode = WldExit::EXIT_close;
        std::shared_ptr<WorldScene> wScene;
        wScene.reset(new WorldScene());
        bool sceneResult = true;

        if(g_Episode.worldfile.empty())
        {
            sceneResult = false;
            //% "No opened files"
            PGE_MsgBox::warn(qtTrId("ERROR_NO_OPEN_FILES_MSG"));

            if(g_AppSettings.debugMode || g_flags.testWorld)
                goto ExitFromApplication;
            else
                goto MainMenu;
        }
        else
        {
            sceneResult = wScene->loadFile(g_Episode.worldfile);
            wScene->setGameState(&g_GameState); //Load game state to the world map

            if(!sceneResult)
            {
                //% "ERROR:\nFail to start world map\n\n%1"
                PGE_MsgBox::error( fmt::qformat(qtTrId("ERROR_FAIL_START_WLD"), wScene->getLastError()) );
                wldExitCode = WldExit::EXIT_error;
            }
        }

        if(sceneResult)
            sceneResult = wScene->init();

        if(sceneResult)
            wScene->m_fader.setFade(10, 0.0, 0.02);

        if(sceneResult)
            wldExitCode = (WldExit::ExitWorldCodes)wScene->exec();

        if(!sceneResult)
        {
            wldExitCode = WldExit::EXIT_error;
            //% "World map was closed with error.\n%1"
            PGE_MsgBox::error( fmt::qformat(qtTrId("WLD_ERROR_LVLCLOSED"), wScene->errorString()) );
        }

        g_GameState._recent_ExitCode_world = (int)wldExitCode;

        if(wScene->doShutDown())
        {
            wScene.reset();
            goto ExitFromApplication;
        }

        if(g_AppSettings.debugMode)
        {
            if(wldExitCode == WldExit::EXIT_beginLevel)
            {
                std::string msg;
                //% "Start level\n%1"
                msg += fmt::qformat(qtTrId("MSG_START_LEVEL"), g_GameState.LevelFile) + "\n\n";
                //% "Type an exit code (signed integer)"
                msg += qtTrId("MSG_WLDTEST_EXIT_CODE");
                PGE_TextInputBox text(nullptr, msg, PGE_BoxBase::msg_info_light,
                                      PGE_Point(-1, -1),
                                      ConfigManager::setup_message_box.box_padding,
                                      ConfigManager::setup_message_box.sprite);
                text.exec();
                g_GameState._recent_ExitCode_level  = LvlExit::EXIT_Neutral;

                if(PGEFile::IsIntS(text.inputText()))
                    g_GameState._recent_ExitCode_level = SDL_atoi(text.inputText().c_str());

                if(g_GameState.isHubLevel)
                    goto ExitFromApplication;

                goto PlayWorldMap;
            }
            else
                goto ExitFromApplication;
        }

        switch(wldExitCode)
        {
        case WldExit::EXIT_beginLevel:
            goto PlayLevel;

        case WldExit::EXIT_close:
            break;

        case WldExit::EXIT_error:
            break;

        case WldExit::EXIT_exitNoSave:
            break;

        case WldExit::EXIT_exitWithSave:
            break;

        default:
            break;
        }

        if(g_flags.testWorld)
            goto ExitFromApplication;

        goto MainMenu;
    }
PlayLevel:
    {
        bool playAgain = true;
        unsigned long entranceID = 0;
        std::shared_ptr<LevelScene> lScene(nullptr);

        while(playAgain)
        {
            entranceID = g_GameState.LevelTargetWarp;

            if(g_GameState.LevelFile_hub == g_GameState.LevelFile)
            {
                g_GameState.isHubLevel = true;
                entranceID = g_GameState.game_state.last_hub_warp;
            }

            int levelExitCode = 0;
            lScene.reset(new LevelScene());

            if(g_AppSettings.interprocessing)
                g_GameState.isTestingModeL = true;

            lScene->setGameState(&g_GameState);
            bool sceneResult = true;

            if(g_GameState.LevelFile.empty())
            {
                if(g_AppSettings.interprocessing && IntProc::isEnabled())
                {
                    sceneResult = lScene->loadFileIP();

                    if((!sceneResult) && (!lScene->isExiting()))
                    {
                        //SDL_Delay(50);
                        levelExitCode = LvlExit::EXIT_Error;
                        PGE_MsgBox msgBox(nullptr, fmt::format_ne("ERROR:\nFail to start level\n\n{0}",
                                                lScene->getLastError()),
                                                PGE_MsgBox::msg_error);
                        msgBox.exec();
                    }
                }
                else
                {
                    sceneResult = false;
                    levelExitCode = LvlExit::EXIT_Error;
                    //% "No opened files"
                    PGE_MsgBox::warn(qtTrId("ERROR_NO_OPEN_FILES_MSG"));
                }
            }
            else
            {
                sceneResult = lScene->loadFile(g_GameState.LevelFile);

                if(!sceneResult)
                {
                    SDL_Delay(50);
                    PGE_MsgBox msgBox(nullptr,
                                      fmt::format_ne("ERROR:\nFail to start level\n\n"
                                                     "{0}", lScene->getLastError()),
                                      PGE_MsgBox::msg_error);
                    msgBox.exec();
                }
            }

            if(sceneResult)
                sceneResult = lScene->setEntrance(entranceID);

            if(sceneResult)
                sceneResult = lScene->init();

            if(sceneResult)
            {
                lScene->m_fader.setFade(10, 0.0, 0.02);
                levelExitCode = lScene->exec();
                g_GameState._recent_ExitCode_level = levelExitCode;
            }

            if(!sceneResult)
                levelExitCode = LvlExit::EXIT_Error;

            switch(levelExitCode)
            {
            case LvlExit::EXIT_Warp:
            {
                if(lScene->m_warpToWorld)
                {
                    g_GameState.game_state.worldPosX = lScene->toWorldXY().x();
                    g_GameState.game_state.worldPosY = lScene->toWorldXY().y();
                    g_GameState.LevelFile.clear();
                    entranceID = 0;
                    g_jumpOnLevelEndTo = g_GameState.isEpisode ? RETURN_TO_WORLDMAP : RETURN_TO_MAIN_MENU;
                }
                else
                {
                    g_GameState.LevelFile = lScene->toAnotherLevel();
                    g_GameState.LevelTargetWarp = lScene->toAnotherEntrance();
                    entranceID = g_GameState.LevelTargetWarp;

                    if(g_GameState.isHubLevel)
                    {
                        g_GameState.isHubLevel = false;
                        g_GameState.game_state.last_hub_warp = lScene->m_lastWarpID;
                    }
                }

                if(g_GameState.LevelFile.empty())
                    playAgain = false;

                if(g_AppSettings.debugMode)
                {
                    std::string target;

                    if(lScene->m_warpToWorld)
                    {
                        target = fmt::format_ne("X={0}, Y={1}",
                                 g_GameState.game_state.worldPosX,
                                 g_GameState.game_state.worldPosY);
                    }
                    else
                        target = g_GameState.LevelFile;

                    if(!target.empty())
                    {
                        //% "Warp exit\n\nExit into:\n%1\n\nEntrance point: %2"
                        PGE_MsgBox::warn( fmt::qformat(qtTrId("LVL_EXIT_WARP_INFO"), target, entranceID) );
                    }

                    playAgain = false;
                }
            }
            break;

            case LvlExit::EXIT_Closed:
            {
                g_jumpOnLevelEndTo = RETURN_TO_EXIT;
                playAgain = false;
            }
            break;

            case LvlExit::EXIT_ReplayRequest:
            {
                playAgain = true;
            }
            break;

            case LvlExit::EXIT_MenuExit:
            {
                g_jumpOnLevelEndTo = g_GameState.isEpisode ? RETURN_TO_WORLDMAP : RETURN_TO_MAIN_MENU;

                if(g_GameState.isHubLevel)
                    g_jumpOnLevelEndTo = g_flags.testLevel ? RETURN_TO_EXIT : RETURN_TO_MAIN_MENU;

                playAgain = false;
            }
            break;

            case LvlExit::EXIT_PlayerDeath:
            {
                playAgain = g_GameState.isEpisode ? g_GameState.replay_on_fail : true;
                g_jumpOnLevelEndTo = g_GameState.isEpisode ? RETURN_TO_WORLDMAP : RETURN_TO_MAIN_MENU;

                //check the number of player lives here and decided to return worldmap or gameover
                if(g_GameState.isEpisode)
                {
                    g_GameState.game_state.lives--;

                    if(g_GameState.game_state.lives < 0)
                    {
                        playAgain = false;
                        g_GameState.game_state.coins = 0;
                        g_GameState.game_state.points = 0;
                        g_GameState.game_state.lives = 3;
                        g_jumpOnLevelEndTo = RETURN_TO_GAMEOVER_SCREEN;
                    }
                }
            }
            break;

            case LvlExit::EXIT_Error:
            {
                g_jumpOnLevelEndTo = (g_GameState.isEpisode) ? RETURN_TO_WORLDMAP : RETURN_TO_MAIN_MENU;
                playAgain = false;
                //% "Level was closed with error.\n%1"
                PGE_MsgBox::error( fmt::qformat(qtTrId("LVL_ERROR_LVLCLOSED"), lScene->errorString()) );
            }
            break;

            default:
                g_jumpOnLevelEndTo = g_GameState.isEpisode ? RETURN_TO_WORLDMAP : RETURN_TO_MAIN_MENU;
                playAgain = false;
            }

            if(g_flags.testLevel || g_AppSettings.debugMode)
                g_jumpOnLevelEndTo = RETURN_TO_EXIT;

            ConfigManager::unloadLevelConfigs();
            lScene.reset();
        }

        if(g_AppSettings.interprocessing)
            goto ExitFromApplication;

        switch(g_jumpOnLevelEndTo)
        {
        case RETURN_TO_WORLDMAP:
            goto PlayWorldMap;

        case RETURN_TO_MAIN_MENU:
            goto MainMenu;

        case RETURN_TO_EXIT:
            goto ExitFromApplication;

        case RETURN_TO_GAMEOVER_SCREEN:
            goto GameOverScreen;

        case RETURN_TO_CREDITS_SCREEN:
            goto CreditsScreen;
        }
    }
ExitFromApplication:
    return 0;
}
void LVL_EventEngine::addSMBX64Event(LevelSMBX64Event &evt)
{
    LVL_EventAction evntAct;
        evntAct.eventName=evt.name;
        evntAct.timeDelayLeft=0;

        EventQueueEntry<LVL_EventAction> hideLayers;
        hideLayers.makeCaller([this,evt]()->void{
                               foreach(QString ly, evt.layers_hide)
                                   _scene->layers.hide(ly, !evt.nosmoke);
                           }, 0);
        evntAct.action.events.push_back(hideLayers);

        EventQueueEntry<LVL_EventAction> showLayers;
        showLayers.makeCaller([this,evt]()->void{
                               foreach(QString ly, evt.layers_show)
                                   _scene->layers.show(ly, !evt.nosmoke);
                           }, 0);
        evntAct.action.events.push_back(showLayers);

        EventQueueEntry<LVL_EventAction> toggleLayers;
        toggleLayers.makeCaller([this,evt]()->void{
                               foreach(QString ly, evt.layers_toggle)
                                   _scene->layers.toggle(ly, !evt.nosmoke);
                           }, 0);
        evntAct.action.events.push_back(toggleLayers);

        if(evt.sound_id>0)
        {
            EventQueueEntry<LVL_EventAction> playsnd;
            playsnd.makeCaller([this,evt]()->void{
                                       PGE_Audio::playSound(evt.sound_id);
                               }, 0);
            evntAct.action.events.push_back(playsnd);
        }

        for(int i=0;i<evt.sets.size(); i++)
        {
            if(evt.sets[i].background_id!=-1)
            {
                EventQueueEntry<LVL_EventAction> bgToggle;
                if(evt.sets[i].background_id<0)
                {
                    bgToggle.makeCaller([this,evt,i]()->void{
                        if(i<_scene->sections.size())
                        {
                            _scene->sections[i].resetBG();
                            for(int j=0;j<_scene->cameras.size();j++)
                            {
                                if(_scene->cameras[j].cur_section==&_scene->sections[i])
                                {
                                    _scene->sections[i].initBG();
                                }
                            }
                        }

                    }, 0);
                } else {
                    bgToggle.makeCaller([this,evt,i]()->void{
                        if(i<_scene->sections.size())
                        {
                            _scene->sections[i].setBG(evt.sets[i].background_id);
                            for(int j=0;j<_scene->cameras.size();j++)
                            {
                                if(_scene->cameras[j].cur_section==&_scene->sections[i])
                                {
                                    _scene->sections[i].initBG();
                                }
                            }
                        }
                    }, 0);
                }
                evntAct.action.events.push_back(bgToggle);
            }
            if(evt.sets[i].music_id!=-1)
            {
                EventQueueEntry<LVL_EventAction> musToggle;
                if(evt.sets[i].music_id<0)
                {
                    musToggle.makeCaller([this,evt,i]()->void{
                        if(i<_scene->sections.size())
                        {
                            _scene->sections[i].resetMusic();
                            for(int j=0;j<_scene->cameras.size();j++)
                            {
                                if(_scene->cameras[j].cur_section==&_scene->sections[i])
                                {
                                    _scene->sections[i].playMusic();
                                }
                            }
                        }
                    }, 0);
                } else {
                    musToggle.makeCaller([this,evt, i]()->void{
                        if(i<_scene->sections.size())
                        {
                            _scene->sections[i].setMusic(evt.sets[i].music_id);
                            for(int j=0;j<_scene->cameras.size();j++)
                            {
                                if(_scene->cameras[j].cur_section==&_scene->sections[i])
                                {
                                    _scene->sections[i].playMusic();
                                }
                            }
                        }
                    }, 0);
                }
                evntAct.action.events.push_back(musToggle);
            }
            if(evt.sets[i].position_left!=-1)
            {
                EventQueueEntry<LVL_EventAction> bordersToggle;
                if(evt.sets[i].position_left==-2)
                {
                    bordersToggle.makeCaller([this,evt,i]()->void{
                        if(i<_scene->sections.size())
                        {
                            _scene->sections[i].resetLimits();
                        }
                    }, 0);
                } else {
                    bordersToggle.makeCaller([this,evt, i]()->void{
                        if(i<_scene->sections.size())
                        {
                            _scene->sections[i].changeLimitBorders(
                                        evt.sets[i].position_left,
                                        evt.sets[i].position_top,
                                        evt.sets[i].position_right,
                                        evt.sets[i].position_bottom);
                        }
                    }, 0);
                }
                evntAct.action.events.push_back(bordersToggle);
            }
        }

        if((evt.scroll_section<_scene->sections.size())&&((evt.move_camera_x!=0.0f)||(evt.move_camera_y!=0.0f)))
        {
            EventQueueEntry<LVL_EventAction> installAutoscroll;
            installAutoscroll.makeCaller([this,evt]()->void{
                                       _scene->sections[evt.scroll_section].isAutoscroll=true;
                                       _scene->sections[evt.scroll_section]._autoscrollVelocityX=evt.move_camera_x;
                                       _scene->sections[evt.scroll_section]._autoscrollVelocityY=evt.move_camera_y;
                                       for(int j=0;j<_scene->cameras.size();j++)
                                       {
                                           if(_scene->cameras[j].cur_section==&_scene->sections[evt.scroll_section])
                                           {
                                               _scene->cameras[j].isAutoscroll=true;
                                               _scene->cameras[j].resetAutoscroll();
                                           }
                                       }
                               }, 0);
            evntAct.action.events.push_back(installAutoscroll);
        }

        if(!evt.msg.isEmpty())
        {
            EventQueueEntry<LVL_EventAction> message;
            message.makeCaller([this,evt]()->void{
                EventQueueEntry<LevelScene > msgBox;
                msgBox.makeCaller(
                            [this,evt]()->void{

                                   PGE_MsgBox box(_scene, evt.msg,
                                   PGE_MsgBox::msg_info, PGE_Point(-1,-1), -1,
                                   ConfigManager::setup_message_box.sprite);
                                   box.exec();
                                }, 0);
                _scene->system_events.events.push_back(msgBox);
                               }, 0);
            evntAct.action.events.push_back(message);
        }

        if(!evt.movelayer.isEmpty())
        {
            EventQueueEntry<LVL_EventAction> movelayer;
            movelayer.makeCaller([this,evt]()->void{
                                       _scene->layers.installLayerMotion(evt.movelayer, evt.layer_speed_x, evt.layer_speed_y);
                               }, 0);
            evntAct.action.events.push_back(movelayer);
        }

    events[evt.name].push_back(evntAct);

    if(!evt.trigger.isEmpty())
    {
        LVL_EventAction trigger;
        trigger.eventName=evt.name;
        trigger.timeDelayLeft=0;
        EventQueueEntry<LVL_EventAction> triggerEvent;
        triggerEvent.makeCaller([this,evt]()->void{
                                _scene->events.triggerEvent(evt.trigger);
                               }, evt.trigger_timer*100);
        trigger.action.events.push_back(triggerEvent);
        events[evt.name].push_back(trigger);
    }

    //Automatically trigger events
    if( (evt.name=="Level - Start") || evt.autostart==LevelSMBX64Event::AUTO_LevelStart )
        workingEvents.push_back(events[evt.name]);
}
Example #6
0
PGE_Point Render_SW_SDL::MapToScr(int x, int y)
{
    return PGE_Point(((float(x))/viewport_scale_x)-offset_x, ((float(y))/viewport_scale_y)-offset_y);
}
Example #7
0
PGE_Point Render_OpenGL31::MapToScr(int x, int y)
{
    return PGE_Point(
               static_cast<int>(((static_cast<float>(x)) / viewport_scale_x) - offset_x),
               static_cast<int>(((static_cast<float>(y)) / viewport_scale_y) - offset_y));
}