예제 #1
0
void Player::loadFromConfig(const std::string& prefix, bool initInput)
{
	UserConfig gameConfig;
	gameConfig.loadFile("config.xml");

	// init local input
	if(initInput){
		if (gameConfig.getBool(prefix + "_player_human")) {
			mInputSource = new LocalInputSource(mPlayerSide);
		} else {
			mInputSource = new ScriptedInputSource("scripts/" +
				gameConfig.getString(prefix + "_script_name"), mPlayerSide, gameConfig.getInteger(prefix + "_script_strength"));
		}
	
		mName = gameConfig.getBool(prefix + "_player_human") ?
			gameConfig.getString(prefix + "_player_name") :
			gameConfig.getString(prefix + "_script_name");
	}else{
		// input is set externally (network)
		// so we need not to create any input source
		mInputSource = 0;
		// don't use bot name if extern input is used
		mName = gameConfig.getString(prefix + "_player_name");
	}
	mInitialised = true;
	
	mStaticColor = Color(
		gameConfig.getInteger(prefix + "_blobby_color_r"),
		gameConfig.getInteger(prefix + "_blobby_color_g"),
		gameConfig.getInteger(prefix + "_blobby_color_b"));


	mOscillating = gameConfig.getBool(prefix + "_blobby_oscillate");

	mInitialised = true;
}
예제 #2
0
int main(int argc, char* argv[])
{
    PHYSFS_init(argv[0]);
    setupPHYSFS();
    
    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
    SDL_EnableUNICODE(1);
    atexit(SDL_Quit);
    srand(SDL_GetTicks());
    // Default is OpenGL and false
    // choose renderer
    RenderManager *rmanager = 0;
    SoundManager *smanager = 0;

    try
    {
        UserConfig gameConfig;
        gameConfig.loadFile("config.xml");
        
        TextManager::createTextManager(gameConfig.getString("language"));
        
        if(gameConfig.getString("device") == "SDL")
            rmanager = RenderManager::createRenderManagerSDL();
        else if (gameConfig.getString("device") == "GP2X")
            rmanager = RenderManager::createRenderManagerGP2X();
        else if (gameConfig.getString("device") == "OpenGL")
            rmanager = RenderManager::createRenderManagerGL2D();
        else
        {
            std::cerr << "Warning: Unknown renderer selected!";
            std::cerr << "Falling back to OpenGL" << std::endl;
            rmanager = RenderManager::createRenderManagerGL2D();
        }

        // fullscreen?
        if(gameConfig.getString("fullscreen") == "true")
            rmanager->init(800, 600, true);
        else
            rmanager->init(800, 600, false);

        if(gameConfig.getString("show_shadow") == "true")
            rmanager->showShadow(true);
        else
            rmanager->showShadow(false);

        SpeedController scontroller(gameConfig.getFloat("gamefps"));
        SpeedController::setMainInstance(&scontroller);
        scontroller.setDrawFPS(gameConfig.getBool("showfps"));

        smanager = SoundManager::createSoundManager();
        smanager->init();
        smanager->setVolume(gameConfig.getFloat("global_volume"));
        smanager->setMute(gameConfig.getBool("mute"));
        smanager->playSound("sounds/bums.wav", 0.0);
        smanager->playSound("sounds/pfiff.wav", 0.0);

        std::string bg = std::string("backgrounds/") + gameConfig.getString("background");
        if (PHYSFS_exists(bg.c_str()))
            rmanager->setBackground(bg);

        InputManager* inputmgr = InputManager::createInputManager();

        if (argc == 3)
        {
            if (strstr(argv[1], ".lua"))
            {
                gameConfig.setString("left_player_human", "false");
                gameConfig.setString("left_script_name", argv[1]);
            }
            else
            {
                gameConfig.setString("left_player_human", "true");
                gameConfig.setString("left_player_name", argv[1]);
            }
            if (strstr(argv[2], ".lua"))
            {
                gameConfig.setString("right_player_human", "false");
                gameConfig.setString("right_script_name", argv[2]);
            }
            else
            {
                gameConfig.setString("right_player_human", "true");
                gameConfig.setString("right_player_name", argv[2]);
            }
            gameConfig.saveFile("config.xml");
            State::setCurrentState(new LocalGameState(), true);
        }

        int running = 1;
        while (running)
        {
            inputmgr->updateInput();
            running = inputmgr->running();

            // This is true by default for compatibility, GUI states may
            // disable it if necessary
            rmanager->drawGame(true);
            IMGUI::getSingleton().begin();
                State::getCurrentState()->step();
            rmanager = &RenderManager::getSingleton(); //RenderManager may change
            //draw FPS:
            if (scontroller.getDrawFPS())
            {
                // We need to ensure that the title bar is only set
                // when the framerate changed, because setting the
                // title can ne quite resource intensive on some
                // windows manager, like for example metacity.
                static int lastfps = 0;
                int newfps = scontroller.getFPS();
                if (newfps != lastfps)
                {
                    std::stringstream tmp;
                    tmp << AppTitle << "    FPS: " << newfps;
                    rmanager->setTitle(tmp.str());
                }
                lastfps = newfps;
            }

            if (!scontroller.doFramedrop())
            {
                rmanager->draw();
                IMGUI::getSingleton().end();
                BloodManager::getSingleton().step();
                rmanager->refresh();
            }
            scontroller.update();
        }
    }
    catch (std::exception& e)
    {
        std::cerr << e.what() << std::endl;
        if (rmanager)
            rmanager->deinit();
        if (smanager)
            smanager->deinit();
        SDL_Quit();
        PHYSFS_deinit();
        exit (EXIT_FAILURE);
    }

    deinit();
    exit(EXIT_SUCCESS);
}