Exemplo n.º 1
0
GameSwitcher::GameSwitcher()
	: background(NULL)
	, background_image(NULL)
	, background_filename("")
	, fps_ticks(0)
	, last_fps(0)
{

	// The initial state is the intro cutscene and then title screen
	GameStateTitle *title=new GameStateTitle();
	GameStateCutscene *intro = new GameStateCutscene(title);

	currentState = intro;

	if (!intro->load("cutscenes/intro.txt")) {
		delete intro;
		currentState = title;
	}

	label_fps = new WidgetLabel();
	done = false;
	loadMusic();
	loadFPS();

	loadBackgroundList();

	if (currentState->has_background)
		loadBackgroundImage();
}
Exemplo n.º 2
0
void GameSwitcher::logic() {
	// reset the mouse cursor
	curs->logic();

	// Check if a the game state is to be changed and change it if necessary, deleting the old state
	GameState* newState = currentState->getRequestedGameState();
	if (newState != NULL) {
		if (currentState->reload_backgrounds || render_device->reloadGraphics())
			loadBackgroundList();

		delete currentState;
		currentState = newState;
		currentState->load_counter++;

		// reload the fps meter position
		loadFPS();

		// if this game state does not provide music, use the title theme
		if (!currentState->hasMusic)
			if (!snd->isPlayingMusic())
				loadMusic();

		// if this game state shows a background image, load it here
		if (currentState->has_background)
			loadBackgroundImage();
		else
			freeBackground();
	}

	// resize background image when window is resized
	if (inpt->window_resized && currentState->has_background) {
		refreshBackground();
	}

	currentState->logic();

	// Check if the GameState wants to quit the application
	done = currentState->isExitRequested();

	if (currentState->reload_music) {
		loadMusic();
		currentState->reload_music = false;
	}
}
Exemplo n.º 3
0
bool DataLoader::load(std::string fileName) {

    FILE *fp;
    fp = fopen(fileName.c_str(), "rb");

    /* lendo o numero magico e verificando se de fato é um número mágico */
    int magic_number;
    fread(&magic_number, 1, sizeof(int), fp);

    if(magic_number != gameData->MAGIC_NUMBER) {
        return false;
    }

    fread(&gameData->version, 1, sizeof(int), fp);

    gameData->filePath = fileName;

    /* lê o nome do jogo */
    /*
    char *nome_jogo;
    int tamanho_nome_jogo;

    fread(&tamanho_nome_jogo, 1, sizeof(int), fp);
    nome_jogo = (char*) calloc(tamanho_nome_jogo + 1, sizeof(char));
    nome_jogo[tamanho_nome_jogo] = '\0';

    fread(nome_jogo, sizeof(char), tamanho_nome_jogo, fp);
    */

    char *nome_jogo;
    nome_jogo = loadString(fp);

    gameData->gameName = new std::string(nome_jogo);

    /* lê a resolução do jogo */
    fread(&gameData->resWidth, 1, sizeof(int), fp);
    fread(&gameData->resHeight, 1, sizeof(int), fp);

    fread(&gameData->deathAction, 1, sizeof(int), fp);
    fread(&gameData->gameOverAction, 1, sizeof(int), fp);
    fread(&gameData->looseLifes, 1, sizeof(bool), fp);
    fread(&gameData->totalLives, 1, sizeof(int), fp);

    loadTilesetList(fp);

    /* inicio das adicoes - 12 de março - PENDENTES NO RUNTIME -- OK*/
    loadAnimationDataList(fp);
    /* fim */

    loadObjectList(fp);
    loadNpcObjectsToBounce(fp);
    loadObjectSkills(fp);

    loadBackgroundList(fp);

    gameData->mapList = loadMapList(fp);

    loadAllVariableLists(fp);

    loadAllEvents(fp);


    /*  lendo os nomes das imagens das telas principais */
    gameData->titleScreenData.backgroundFile = std::string(loadString(fp));
    gameData->optionsScreenFile = std::string(loadString(fp));
    gameData->gameoverScreenFile = std::string(loadString(fp));

    /* lendo os nomes das musicas das telas principais */
    gameData->titleScreenMusic = std::string(loadString(fp));
    gameData->optionsScreenMusic = std::string(loadString(fp));
    gameData->gameOverScreenMusic = std::string(loadString(fp));

    /* lendo a id do mapa inicial */
    fread(&gameData->idFirstMap, 1, sizeof(int), fp);

    fclose(fp);

    return true;
}