forked from jaildesigner-jailgames/jaildoctors_dilemma
Commit to continue on other pc
This commit is contained in:
538
source/director.cpp
Normal file
538
source/director.cpp
Normal file
@@ -0,0 +1,538 @@
|
||||
#include "const.h"
|
||||
#include "utils.h"
|
||||
#include "director.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#ifdef __MIPSEL__
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
// Constructor
|
||||
Director::Director(std::string path)
|
||||
{
|
||||
// Inicializa la ruta
|
||||
setExecutablePath(path);
|
||||
|
||||
// Establece la lista de ficheros
|
||||
setFileList();
|
||||
|
||||
// Si falta algún fichero no inicies el programa
|
||||
Uint8 section = PROG_SECTION_LOGO;
|
||||
if (!checkFileList())
|
||||
section = PROG_SECTION_QUIT;
|
||||
|
||||
// Inicializa el objeto de idioma
|
||||
mLang = new Lang(mFileList);
|
||||
|
||||
// Crea el puntero a la estructura y carga el fichero de configuración
|
||||
mOptions = new options_t;
|
||||
if (!loadConfigFile())
|
||||
{
|
||||
mOptions->fullScreenMode = 0;
|
||||
mOptions->windowSize = 3;
|
||||
mOptions->language = en_UK;
|
||||
mOptions->difficulty = DIFFICULTY_NORMAL;
|
||||
mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
|
||||
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
|
||||
mOptions->filter = FILTER_NEAREST;
|
||||
mOptions->vSync = true;
|
||||
}
|
||||
|
||||
// Crea los objetos
|
||||
mInput = new Input(mFileList[53]);
|
||||
|
||||
// Inicializa SDL
|
||||
initSDL();
|
||||
|
||||
// Inicializa JailAudio
|
||||
initJailAudio();
|
||||
|
||||
// Aplica las opciones
|
||||
SDL_SetWindowFullscreen(mWindow, mOptions->fullScreenMode);
|
||||
SDL_SetWindowSize(mWindow, SCREEN_WIDTH * mOptions->windowSize, SCREEN_HEIGHT * mOptions->windowSize);
|
||||
mLang->setLang(mOptions->language);
|
||||
|
||||
#ifdef __MIPSEL__
|
||||
DIR *dir = opendir("/media/data/local/home/.coffee_crisis");
|
||||
if (dir)
|
||||
{
|
||||
closedir(dir);
|
||||
}
|
||||
else if (ENOENT == errno)
|
||||
{
|
||||
int status = mkdir("/media/data/local/home/.coffee_crisis", 755);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Inicializa el resto de variables
|
||||
init(section);
|
||||
}
|
||||
|
||||
Director::~Director()
|
||||
{
|
||||
saveConfigFile();
|
||||
|
||||
delete mInput;
|
||||
mInput = nullptr;
|
||||
|
||||
delete mLang;
|
||||
mLang = nullptr;
|
||||
|
||||
delete mOptions;
|
||||
mOptions = nullptr;
|
||||
|
||||
SDL_DestroyRenderer(mRenderer);
|
||||
SDL_DestroyWindow(mWindow);
|
||||
mRenderer = nullptr;
|
||||
mWindow = nullptr;
|
||||
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
// Inicia las variables necesarias para arrancar el programa
|
||||
void Director::init(Uint8 name)
|
||||
{
|
||||
// Sección
|
||||
mSection.name = name;
|
||||
mSection.subsection = 0;
|
||||
|
||||
// Textos
|
||||
mLang->setLang(mOptions->language);
|
||||
|
||||
// Controles
|
||||
mInput->bindKey(INPUT_UP, SDL_SCANCODE_UP);
|
||||
mInput->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN);
|
||||
mInput->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT);
|
||||
mInput->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT);
|
||||
mInput->bindKey(INPUT_ACCEPT, SDL_SCANCODE_RETURN);
|
||||
mInput->bindKey(INPUT_CANCEL, SDL_SCANCODE_ESCAPE);
|
||||
#ifdef __MIPSEL__
|
||||
mInput->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_LSHIFT);
|
||||
mInput->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_SPACE);
|
||||
mInput->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_LCTRL);
|
||||
#else
|
||||
mInput->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_Q);
|
||||
mInput->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_W);
|
||||
mInput->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_E);
|
||||
#endif
|
||||
mInput->bindKey(INPUT_BUTTON_PAUSE, SDL_SCANCODE_ESCAPE); // PAUSE
|
||||
mInput->bindKey(INPUT_BUTTON_ESCAPE, SDL_SCANCODE_ESCAPE); // ESCAPE
|
||||
|
||||
mInput->bindGameControllerButton(INPUT_UP, SDL_CONTROLLER_BUTTON_DPAD_UP);
|
||||
mInput->bindGameControllerButton(INPUT_DOWN, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
|
||||
mInput->bindGameControllerButton(INPUT_LEFT, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
|
||||
mInput->bindGameControllerButton(INPUT_RIGHT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
|
||||
mInput->bindGameControllerButton(INPUT_ACCEPT, SDL_CONTROLLER_BUTTON_B);
|
||||
mInput->bindGameControllerButton(INPUT_CANCEL, SDL_CONTROLLER_BUTTON_A);
|
||||
mInput->bindGameControllerButton(INPUT_BUTTON_1, SDL_CONTROLLER_BUTTON_X);
|
||||
mInput->bindGameControllerButton(INPUT_BUTTON_2, SDL_CONTROLLER_BUTTON_Y);
|
||||
mInput->bindGameControllerButton(INPUT_BUTTON_3, SDL_CONTROLLER_BUTTON_B);
|
||||
mInput->bindGameControllerButton(INPUT_BUTTON_PAUSE, SDL_CONTROLLER_BUTTON_GUIDE); // PAUSE
|
||||
mInput->bindGameControllerButton(INPUT_BUTTON_ESCAPE, SDL_CONTROLLER_BUTTON_GUIDE); // ESCAPE
|
||||
}
|
||||
|
||||
// Inicializa JailAudio
|
||||
void Director::initJailAudio()
|
||||
{
|
||||
JA_Init(48000, AUDIO_S16, 2);
|
||||
}
|
||||
|
||||
// Arranca SDL y crea la ventana
|
||||
bool Director::initSDL()
|
||||
{
|
||||
// Indicador de éxito
|
||||
bool success = true;
|
||||
|
||||
// Inicializa SDL
|
||||
//if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO) < 0)
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
|
||||
{
|
||||
printf("SDL could not initialize!\nSDL Error: %s\n", SDL_GetError());
|
||||
success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Inicia el generador de numeros aleatorios
|
||||
std::srand(static_cast<unsigned int>(SDL_GetTicks()));
|
||||
|
||||
// Establece el filtro de la textura a nearest
|
||||
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(mOptions->filter).c_str()))
|
||||
{
|
||||
printf("Warning: Nearest texture filtering not enabled!\n");
|
||||
}
|
||||
|
||||
// Crea la ventana
|
||||
mWindow = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, VIEW_WIDTH, VIEW_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||
if (mWindow == NULL)
|
||||
{
|
||||
printf("Window could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||
success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Crea un renderizador para la ventana. El vsync se activa en funcion de las opciones
|
||||
if (mOptions->vSync)
|
||||
mRenderer = SDL_CreateRenderer(mWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||
else
|
||||
mRenderer = SDL_CreateRenderer(mWindow, -1, SDL_RENDERER_ACCELERATED);
|
||||
|
||||
if (mRenderer == NULL)
|
||||
{
|
||||
printf("Renderer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||
success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Inicializa el color de renderizado
|
||||
SDL_SetRenderDrawColor(mRenderer, 0x00, 0x00, 0x00, 0xFF);
|
||||
|
||||
// Establece el tamaño del buffer de renderizado
|
||||
SDL_RenderSetLogicalSize(mRenderer, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
|
||||
// Establece el modo de mezcla
|
||||
SDL_SetRenderDrawBlendMode(mRenderer, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
return success;
|
||||
}
|
||||
|
||||
// Crea el indice de ficheros
|
||||
void Director::setFileList()
|
||||
{
|
||||
// Inicializa el vector
|
||||
for (int i = 0; i < MAX_FILE_LIST; i++)
|
||||
mFileList[i] = "";
|
||||
|
||||
// Ficheros binarios
|
||||
#ifdef __MIPSEL__
|
||||
mFileList[0] = "/media/data/local/home/.coffee_crisis/score.bin";
|
||||
mFileList[1] = "/media/data/local/home/.coffee_crisis/demo.bin";
|
||||
mFileList[2] = "/media/data/local/home/.coffee_crisis/config.bin";
|
||||
#else
|
||||
mFileList[0] = mExecutablePath + "/" + "../data/score.bin";
|
||||
mFileList[1] = mExecutablePath + "/" + "../data/demo.bin";
|
||||
mFileList[2] = mExecutablePath + "/" + "../data/config.bin";
|
||||
#endif
|
||||
|
||||
// Musicas
|
||||
mFileList[3] = mExecutablePath + "/" + "../media/music/intro.ogg";
|
||||
mFileList[4] = mExecutablePath + "/" + "../media/music/playing.ogg";
|
||||
mFileList[5] = mExecutablePath + "/" + "../media/music/title.ogg";
|
||||
|
||||
// Sonidos
|
||||
mFileList[6] = mExecutablePath + "/" + "../media/sound/balloon.wav";
|
||||
mFileList[7] = mExecutablePath + "/" + "../media/sound/bubble1.wav";
|
||||
mFileList[8] = mExecutablePath + "/" + "../media/sound/bubble2.wav";
|
||||
mFileList[9] = mExecutablePath + "/" + "../media/sound/bubble3.wav";
|
||||
mFileList[10] = mExecutablePath + "/" + "../media/sound/bubble4.wav";
|
||||
mFileList[11] = mExecutablePath + "/" + "../media/sound/bullet.wav";
|
||||
mFileList[12] = mExecutablePath + "/" + "../media/sound/coffeeout.wav";
|
||||
mFileList[13] = mExecutablePath + "/" + "../media/sound/hiscore.wav";
|
||||
mFileList[14] = mExecutablePath + "/" + "../media/sound/itemdrop.wav";
|
||||
mFileList[15] = mExecutablePath + "/" + "../media/sound/itempickup.wav";
|
||||
mFileList[16] = mExecutablePath + "/" + "../media/sound/menu_cancel.wav";
|
||||
mFileList[17] = mExecutablePath + "/" + "../media/sound/menu_move.wav";
|
||||
mFileList[18] = mExecutablePath + "/" + "../media/sound/menu_select.wav";
|
||||
mFileList[19] = mExecutablePath + "/" + "../media/sound/player_collision.wav";
|
||||
mFileList[20] = mExecutablePath + "/" + "../media/sound/stage_change.wav";
|
||||
mFileList[21] = mExecutablePath + "/" + "../media/sound/title.wav";
|
||||
mFileList[22] = mExecutablePath + "/" + "../media/sound/clock.wav";
|
||||
mFileList[23] = mExecutablePath + "/" + "../media/sound/powerball.wav";
|
||||
|
||||
// Texturas
|
||||
mFileList[24] = mExecutablePath + "/" + "../media/gfx/balloon.png";
|
||||
mFileList[25] = mExecutablePath + "/" + "../media/gfx/bullet.png";
|
||||
mFileList[31] = mExecutablePath + "/" + "../media/gfx/game_bg.png";
|
||||
mFileList[32] = mExecutablePath + "/" + "../media/gfx/game_text.png";
|
||||
mFileList[33] = mExecutablePath + "/" + "../media/gfx/intro.png";
|
||||
mFileList[34] = mExecutablePath + "/" + "../media/gfx/items.png";
|
||||
mFileList[35] = mExecutablePath + "/" + "../media/gfx/logo.png";
|
||||
mFileList[37] = mExecutablePath + "/" + "../media/gfx/player1_body.png";
|
||||
mFileList[38] = mExecutablePath + "/" + "../media/gfx/player1_death.png";
|
||||
mFileList[39] = mExecutablePath + "/" + "../media/gfx/player1_legs.png";
|
||||
mFileList[40] = mExecutablePath + "/" + "../media/gfx/title.png";
|
||||
mFileList[41] = mExecutablePath + "/" + "../media/gfx/player1_head.png";
|
||||
mFileList[42] = mExecutablePath + "/" + "../media/gfx/player2_body.png";
|
||||
mFileList[43] = mExecutablePath + "/" + "../media/gfx/player2_death.png";
|
||||
mFileList[44] = mExecutablePath + "/" + "../media/gfx/player2_legs.png";
|
||||
mFileList[45] = mExecutablePath + "/" + "../media/gfx/player2_head.png";
|
||||
|
||||
// Fuentes
|
||||
mFileList[27] = mExecutablePath + "/" + "../media/font/8bithud.png";
|
||||
mFileList[46] = mExecutablePath + "/" + "../media/font/8bithud.txt";
|
||||
mFileList[28] = mExecutablePath + "/" + "../media/font/nokia.png";
|
||||
mFileList[54] = mExecutablePath + "/" + "../media/font/nokia_big2.png";
|
||||
mFileList[52] = mExecutablePath + "/" + "../media/font/nokia.txt";
|
||||
mFileList[56] = mExecutablePath + "/" + "../media/font/nokia2.png";
|
||||
mFileList[57] = mExecutablePath + "/" + "../media/font/nokia2.txt";
|
||||
mFileList[55] = mExecutablePath + "/" + "../media/font/nokia_big2.txt";
|
||||
mFileList[29] = mExecutablePath + "/" + "../media/font/smb2_big.png";
|
||||
mFileList[47] = mExecutablePath + "/" + "../media/font/smb2_big.txt";
|
||||
mFileList[30] = mExecutablePath + "/" + "../media/font/smb2.png";
|
||||
mFileList[48] = mExecutablePath + "/" + "../media/font/smb2.txt";
|
||||
|
||||
// Textos
|
||||
mFileList[49] = mExecutablePath + "/" + "../media/lang/es_ES.txt";
|
||||
mFileList[50] = mExecutablePath + "/" + "../media/lang/en_UK.txt";
|
||||
mFileList[51] = mExecutablePath + "/" + "../media/lang/ba_BA.txt";
|
||||
|
||||
// DATA
|
||||
mFileList[53] = mExecutablePath + "/" + "../data/gamecontrollerdb.txt";
|
||||
}
|
||||
|
||||
// Comprueba los ficheros del vector de ficheros que coinciden con una ruta dada
|
||||
bool Director::checkFolder(std::string name, std::string path)
|
||||
{
|
||||
bool success = true;
|
||||
std::string p;
|
||||
std::string filename;
|
||||
SDL_RWops *file;
|
||||
|
||||
// Comprueba los ficheros de la carpeta
|
||||
printf("\n>> %s FILES\n", name.c_str());
|
||||
for (int i = 3; i < MAX_FILE_LIST; i++)
|
||||
{
|
||||
if (mFileList[i].find(path.c_str()) != std::string::npos)
|
||||
{
|
||||
p = mFileList[i].c_str();
|
||||
filename = p.substr(p.find_last_of("\\/") + 1);
|
||||
file = SDL_RWFromFile(p.c_str(), "r+b");
|
||||
if (file != NULL)
|
||||
{
|
||||
printf("Checking file %-20s [OK]\n", filename.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Checking file %-20s [ERROR]\n", filename.c_str());
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
SDL_RWclose(file);
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
// Comprueba que todos los ficheros existen
|
||||
bool Director::checkFileList()
|
||||
{
|
||||
bool success = true;
|
||||
printf("Checking files...\n");
|
||||
|
||||
if (success)
|
||||
success &= checkFolder("MUSIC", "/media/music/");
|
||||
|
||||
if (success)
|
||||
success &= checkFolder("SOUND", "/media/sound/");
|
||||
|
||||
if (success)
|
||||
success &= checkFolder("BITMAP", "/media/gfx/");
|
||||
|
||||
if (success)
|
||||
success &= checkFolder("FONT", "/media/font/");
|
||||
|
||||
if (success)
|
||||
success &= checkFolder("LANG", "/media/lang/");
|
||||
|
||||
// Resultado
|
||||
if (success)
|
||||
printf("\n** All files OK.\n\n");
|
||||
else
|
||||
printf("\n** A file is missing. Exiting.\n\n");
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// Carga el fichero de configuración
|
||||
bool Director::loadConfigFile()
|
||||
{
|
||||
// Pone unos valores por defecto
|
||||
mOptions->fullScreenMode = 0;
|
||||
mOptions->windowSize = 3;
|
||||
mOptions->language = en_UK;
|
||||
mOptions->difficulty = DIFFICULTY_NORMAL;
|
||||
mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
|
||||
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
|
||||
mOptions->filter = FILTER_NEAREST;
|
||||
mOptions->vSync = true;
|
||||
|
||||
// Indicador de éxito en la carga
|
||||
bool success = true;
|
||||
|
||||
const std::string p = mFileList[2];
|
||||
std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
||||
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "r+b");
|
||||
|
||||
// El fichero no existe
|
||||
if (file == NULL)
|
||||
{
|
||||
printf("Warning: Unable to open %s file\n", filename.c_str());
|
||||
|
||||
// Crea el fichero para escritura
|
||||
file = SDL_RWFromFile(p.c_str(), "w+b");
|
||||
if (file != NULL)
|
||||
{
|
||||
printf("New file (%s) created!\n", filename.c_str());
|
||||
|
||||
// Escribe los datos
|
||||
SDL_RWwrite(file, &mOptions->fullScreenMode, sizeof(mOptions->fullScreenMode), 1);
|
||||
SDL_RWwrite(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1);
|
||||
SDL_RWwrite(file, &mOptions->language, sizeof(mOptions->language), 1);
|
||||
SDL_RWwrite(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1);
|
||||
SDL_RWwrite(file, &mOptions->input[0].deviceType, sizeof(mOptions->input[0].deviceType), 1);
|
||||
SDL_RWwrite(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
||||
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
||||
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
||||
|
||||
// Cierra el fichero
|
||||
SDL_RWclose(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Error: Unable to create file %s\n", filename.c_str());
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
// El fichero existe
|
||||
else
|
||||
{
|
||||
// Carga los datos
|
||||
printf("Reading file %s\n", filename.c_str());
|
||||
SDL_RWread(file, &mOptions->fullScreenMode, sizeof(mOptions->fullScreenMode), 1);
|
||||
SDL_RWread(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1);
|
||||
SDL_RWread(file, &mOptions->language, sizeof(mOptions->language), 1);
|
||||
SDL_RWread(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1);
|
||||
SDL_RWread(file, &mOptions->input[0].deviceType, sizeof(mOptions->input[0].deviceType), 1);
|
||||
SDL_RWread(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
||||
SDL_RWread(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
||||
SDL_RWread(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
||||
|
||||
// Normaliza los valores
|
||||
if (!((mOptions->fullScreenMode == 0) ||
|
||||
(mOptions->fullScreenMode == SDL_WINDOW_FULLSCREEN) ||
|
||||
(mOptions->fullScreenMode == SDL_WINDOW_FULLSCREEN_DESKTOP)))
|
||||
mOptions->fullScreenMode = 0;
|
||||
if ((mOptions->windowSize < 1) || (mOptions->windowSize > 4))
|
||||
mOptions->windowSize = 3;
|
||||
if ((mOptions->language < 0) || (mOptions->language > MAX_LANGUAGES))
|
||||
mOptions->language = en_UK;
|
||||
|
||||
// Cierra el fichero
|
||||
SDL_RWclose(file);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// Guarda el fichero de configuración
|
||||
bool Director::saveConfigFile()
|
||||
{
|
||||
bool success = true;
|
||||
const std::string p = mFileList[2];
|
||||
std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
||||
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "w+b");
|
||||
if (file != NULL)
|
||||
{
|
||||
// Guarda los datos
|
||||
SDL_RWwrite(file, &mOptions->fullScreenMode, sizeof(mOptions->fullScreenMode), 1);
|
||||
SDL_RWwrite(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1);
|
||||
SDL_RWwrite(file, &mOptions->language, sizeof(mOptions->language), 1);
|
||||
SDL_RWwrite(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1);
|
||||
SDL_RWwrite(file, &mOptions->input[0].deviceType, sizeof(mOptions->input[0].deviceType), 1);
|
||||
SDL_RWwrite(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
||||
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
||||
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
||||
|
||||
printf("Writing file %s\n", filename.c_str());
|
||||
|
||||
// Cierra el fichero
|
||||
SDL_RWclose(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Error: Unable to save %s file! %s\n", filename.c_str(), SDL_GetError());
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Director::setExecutablePath(std::string path)
|
||||
{
|
||||
mExecutablePath = path.substr(0, path.find_last_of("\\/"));
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
Uint8 Director::getSubsection()
|
||||
{
|
||||
return mSection.subsection;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
Uint8 Director::getSection()
|
||||
{
|
||||
return mSection.name;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Director::setSection(section_t section)
|
||||
{
|
||||
mSection = section;
|
||||
}
|
||||
|
||||
void Director::runLogo()
|
||||
{
|
||||
mLogo = new Logo(mRenderer, mFileList);
|
||||
setSection(mLogo->run());
|
||||
delete mLogo;
|
||||
}
|
||||
|
||||
void Director::runIntro()
|
||||
{
|
||||
mIntro = new Intro(mRenderer, mFileList, mLang);
|
||||
setSection(mIntro->run());
|
||||
delete mIntro;
|
||||
}
|
||||
|
||||
void Director::runTitle()
|
||||
{
|
||||
mTitle = new Title(mWindow, mRenderer, mInput, mFileList, mOptions, mLang);
|
||||
setSection(mTitle->run(mSection.subsection));
|
||||
delete mTitle;
|
||||
}
|
||||
|
||||
void Director::runGame()
|
||||
{
|
||||
if (mSection.subsection == GAME_SECTION_PLAY_1P)
|
||||
mGame = new Game(1, mRenderer, mFileList, mLang, mInput, false, mOptions);
|
||||
if (mSection.subsection == GAME_SECTION_PLAY_2P)
|
||||
mGame = new Game(2, mRenderer, mFileList, mLang, mInput, false, mOptions);
|
||||
setSection(mGame->run());
|
||||
delete mGame;
|
||||
}
|
||||
|
||||
void Director::run()
|
||||
{
|
||||
// Bucle principal
|
||||
while (!(getSection() == PROG_SECTION_QUIT))
|
||||
{
|
||||
switch (getSection())
|
||||
{
|
||||
case PROG_SECTION_LOGO:
|
||||
runLogo();
|
||||
break;
|
||||
case PROG_SECTION_INTRO:
|
||||
runIntro();
|
||||
break;
|
||||
case PROG_SECTION_TITLE:
|
||||
runTitle();
|
||||
break;
|
||||
case PROG_SECTION_GAME:
|
||||
runGame();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user