El joc ja reinicia correctament
This commit is contained in:
@@ -21,38 +21,31 @@
|
|||||||
#include <vector> // Para vector
|
#include <vector> // Para vector
|
||||||
#include "asset.h" // Para Asset, AssetType
|
#include "asset.h" // Para Asset, AssetType
|
||||||
#include "credits.h"
|
#include "credits.h"
|
||||||
#include "dbgtxt.h" // Para dbg_init
|
#include "dbgtxt.h" // Para dbg_init
|
||||||
#include "game.h" // Para Game, GAME_MODE_DEMO_OFF, GAME_...
|
#include "game.h" // Para Game, GAME_MODE_DEMO_OFF, GAME_...
|
||||||
#include "global_inputs.h" // Para init
|
#include "global_inputs.h" // Para init
|
||||||
#include "hiscore_table.h" // Para HiScoreTable
|
#include "hiscore_table.h" // Para HiScoreTable
|
||||||
#include "input.h" // Para Input, InputType
|
#include "input.h" // Para Input, InputType
|
||||||
#include "instructions.h" // Para Instructions
|
#include "instructions.h" // Para Instructions
|
||||||
#include "intro.h" // Para Intro
|
#include "intro.h" // Para Intro
|
||||||
#include "jail_audio.h" // Para JA_SetMusicVolume, JA_SetSoundV...
|
#include "jail_audio.h" // Para JA_SetMusicVolume, JA_SetSoundV...
|
||||||
#include "lang.h" // Para Code, loadFromFile
|
#include "lang.h" // Para Code, loadFromFile
|
||||||
#include "logo.h" // Para Logo
|
#include "logo.h" // Para Logo
|
||||||
#include "manage_hiscore_table.h" // Para ManageHiScoreTable
|
#include "manage_hiscore_table.h" // Para ManageHiScoreTable
|
||||||
#include "notifier.h" // Para Notifier
|
#include "notifier.h" // Para Notifier
|
||||||
#include "on_screen_help.h" // Para OnScreenHelp
|
#include "on_screen_help.h" // Para OnScreenHelp
|
||||||
#include "options.h" // Para Options, OptionsController, opt...
|
#include "options.h" // Para Options, OptionsController, opt...
|
||||||
#include "param.h" // Para Param, ParamGame, param, loadPa...
|
#include "param.h" // Para Param, ParamGame, param, loadPa...
|
||||||
#include "resource.h" // Para Resource
|
#include "resource.h" // Para Resource
|
||||||
#include "screen.h" // Para Screen
|
#include "screen.h" // Para Screen
|
||||||
#include "section.h" // Para Name, Options, name, options
|
#include "section.h" // Para Name, Options, name, options
|
||||||
#include "title.h" // Para Title
|
#include "title.h" // Para Title
|
||||||
#include "utils.h" // Para Overrides, overrides
|
#include "utils.h" // Para Overrides, overrides
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include <pwd.h> // para getpwuid, passwd
|
#include <pwd.h> // para getpwuid, passwd
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Inicia la semilla aleatoria
|
|
||||||
void initRand()
|
|
||||||
{
|
|
||||||
unsigned int seed = static_cast<unsigned int>(std::chrono::system_clock::now().time_since_epoch().count());
|
|
||||||
std::srand(seed);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Director::Director(int argc, const char *argv[])
|
Director::Director(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
@@ -74,42 +67,36 @@ Director::Director(int argc, const char *argv[])
|
|||||||
|
|
||||||
std::cout << "Game start" << std::endl;
|
std::cout << "Game start" << std::endl;
|
||||||
|
|
||||||
initRand();
|
// Inicia la semilla aleatoria
|
||||||
|
unsigned int seed = static_cast<unsigned int>(std::chrono::system_clock::now().time_since_epoch().count());
|
||||||
|
std::srand(seed);
|
||||||
|
|
||||||
// Comprueba los parametros del programa
|
// Comprueba los parametros del programa
|
||||||
checkProgramArguments(argc, argv);
|
checkProgramArguments(argc, argv);
|
||||||
|
|
||||||
// Crea la carpeta del sistema donde guardar datos
|
// Crea la carpeta del sistema donde guardar los datos persistentes
|
||||||
createSystemFolder("jailgames");
|
createSystemFolder("jailgames");
|
||||||
createSystemFolder("jailgames/coffee_crisis_arcade_edition");
|
createSystemFolder("jailgames/coffee_crisis_arcade_edition");
|
||||||
|
|
||||||
// Crea el objeto que controla los ficheros de recursos
|
init();
|
||||||
Asset::init(executable_path_);
|
}
|
||||||
|
|
||||||
// Crea el indice de ficheros
|
Director::~Director()
|
||||||
setFileList();
|
{
|
||||||
|
close();
|
||||||
|
std::cout << "\nBye!" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
// Carga el fichero de configuración
|
// Inicializa todo
|
||||||
loadOptionsFile(Asset::get()->get("config.txt"));
|
void Director::init()
|
||||||
|
{
|
||||||
|
Asset::init(executable_path_); // Crea el objeto que controla los ficheros de recursos
|
||||||
|
setFileList(); // Crea el indice de ficheros
|
||||||
|
loadOptionsFile(Asset::get()->get("config.txt")); // Carga el fichero de configuración
|
||||||
|
loadParams(); // Carga los parametros
|
||||||
|
loadScoreFile(); // Carga el fichero de puntuaciones
|
||||||
|
|
||||||
// Carga los parametros para configurar el juego
|
// Inicializa y crea el resto de objetos
|
||||||
#ifdef ANBERNIC
|
|
||||||
const std::string paramFilePath = asset->get("param_320x240.txt");
|
|
||||||
#else
|
|
||||||
const std::string paramFilePath = overrides.param_file == "--320x240" ? Asset::get()->get("param_320x240.txt") : Asset::get()->get("param_320x256.txt");
|
|
||||||
#endif
|
|
||||||
loadParamsFromFile(paramFilePath);
|
|
||||||
|
|
||||||
// Carga el fichero de puntuaciones
|
|
||||||
{
|
|
||||||
auto manager = std::make_unique<ManageHiScoreTable>(options.game.hi_score_table);
|
|
||||||
if (overrides.clear_hi_score_table)
|
|
||||||
manager->clear();
|
|
||||||
else
|
|
||||||
manager->loadFromFile(Asset::get()->get("score.bin"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa todo
|
|
||||||
initSDL();
|
initSDL();
|
||||||
initJailAudio();
|
initJailAudio();
|
||||||
dbg_init(renderer_);
|
dbg_init(renderer_);
|
||||||
@@ -123,7 +110,8 @@ Director::Director(int argc, const char *argv[])
|
|||||||
globalInputs::init();
|
globalInputs::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
Director::~Director()
|
// Cierra todo
|
||||||
|
void Director::close()
|
||||||
{
|
{
|
||||||
saveOptionsFile(Asset::get()->get("config.txt"));
|
saveOptionsFile(Asset::get()->get("config.txt"));
|
||||||
|
|
||||||
@@ -134,12 +122,38 @@ Director::~Director()
|
|||||||
Notifier::destroy();
|
Notifier::destroy();
|
||||||
OnScreenHelp::destroy();
|
OnScreenHelp::destroy();
|
||||||
|
|
||||||
|
JA_Quit();
|
||||||
|
|
||||||
SDL_DestroyRenderer(renderer_);
|
SDL_DestroyRenderer(renderer_);
|
||||||
SDL_DestroyWindow(window_);
|
SDL_DestroyWindow(window_);
|
||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << "\nBye!" << std::endl;
|
// Carga los parametros
|
||||||
|
void Director::loadParams()
|
||||||
|
{
|
||||||
|
// Carga los parametros para configurar el juego
|
||||||
|
#ifdef ANBERNIC
|
||||||
|
const std::string paramFilePath = asset->get("param_320x240.txt");
|
||||||
|
#else
|
||||||
|
const std::string paramFilePath = overrides.param_file == "--320x240" ? Asset::get()->get("param_320x240.txt") : Asset::get()->get("param_320x256.txt");
|
||||||
|
#endif
|
||||||
|
loadParamsFromFile(paramFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga el fichero de puntuaciones
|
||||||
|
void Director::loadScoreFile()
|
||||||
|
{
|
||||||
|
auto manager = std::make_unique<ManageHiScoreTable>(options.game.hi_score_table);
|
||||||
|
if (overrides.clear_hi_score_table)
|
||||||
|
{
|
||||||
|
manager->clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
manager->loadFromFile(Asset::get()->get("score.bin"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asigna los botones y teclas al objeto Input
|
// Asigna los botones y teclas al objeto Input
|
||||||
@@ -664,6 +678,7 @@ int Director::run()
|
|||||||
switch (section::name)
|
switch (section::name)
|
||||||
{
|
{
|
||||||
case section::Name::INIT:
|
case section::Name::INIT:
|
||||||
|
Resource::get()->reload();
|
||||||
section::name = section::Name::LOGO;
|
section::name = section::Name::LOGO;
|
||||||
break;
|
break;
|
||||||
case section::Name::LOGO:
|
case section::Name::LOGO:
|
||||||
|
|||||||
@@ -74,6 +74,18 @@ private:
|
|||||||
void shutdownSystem();
|
void shutdownSystem();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Inicializa todo
|
||||||
|
void init();
|
||||||
|
|
||||||
|
// Cierra todo
|
||||||
|
void close();
|
||||||
|
|
||||||
|
// Carga los parametros
|
||||||
|
void loadParams();
|
||||||
|
|
||||||
|
// Carga el fichero de puntuaciones
|
||||||
|
void loadScoreFile();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Director(int argc, const char *argv[]);
|
Director(int argc, const char *argv[]);
|
||||||
|
|||||||
@@ -83,14 +83,28 @@ namespace globalInputs
|
|||||||
case lang::Code::es_ES:
|
case lang::Code::es_ES:
|
||||||
return Asset::get()->get("es_ES.txt");
|
return Asset::get()->get("es_ES.txt");
|
||||||
break;
|
break;
|
||||||
case lang::Code::en_UK:
|
|
||||||
return Asset::get()->get("en_UK.txt");
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
|
return Asset::get()->get("en_UK.txt");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Asset::get()->get("en_UK.txt");
|
}
|
||||||
|
|
||||||
|
// Obtiene una cadena a partir de un lang::Code
|
||||||
|
std::string getLangName(lang::Code code)
|
||||||
|
{
|
||||||
|
switch (code)
|
||||||
|
{
|
||||||
|
case lang::Code::ba_BA:
|
||||||
|
return "ba_BA";
|
||||||
|
break;
|
||||||
|
case lang::Code::es_ES:
|
||||||
|
return "es_ES";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return "en_UK";
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia el idioma
|
// Cambia el idioma
|
||||||
@@ -99,7 +113,7 @@ namespace globalInputs
|
|||||||
options.game.language = lang::change(options.game.language);
|
options.game.language = lang::change(options.game.language);
|
||||||
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language)));
|
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language)));
|
||||||
section::name = section::Name::INIT;
|
section::name = section::Name::INIT;
|
||||||
Notifier::get()->showText({"Reset"});
|
Notifier::get()->showText({getLangName(options.game.language)});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||||
|
|||||||
@@ -34,6 +34,24 @@ Resource *Resource::get()
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Resource::Resource()
|
Resource::Resource()
|
||||||
|
{
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vacia todos los vectores de recursos
|
||||||
|
void Resource::clear()
|
||||||
|
{
|
||||||
|
sounds_.clear();
|
||||||
|
musics_.clear();
|
||||||
|
textures_.clear();
|
||||||
|
text_files_.clear();
|
||||||
|
texts_.clear();
|
||||||
|
animations_.clear();
|
||||||
|
demos_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga todos los recursos
|
||||||
|
void Resource::load()
|
||||||
{
|
{
|
||||||
std::cout << "** LOADING RESOURCES" << std::endl;
|
std::cout << "** LOADING RESOURCES" << std::endl;
|
||||||
loadSounds();
|
loadSounds();
|
||||||
@@ -48,6 +66,13 @@ Resource::Resource()
|
|||||||
std::cout << "\n** RESOURCES LOADED" << std::endl;
|
std::cout << "\n** RESOURCES LOADED" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Recarga todos los recursos
|
||||||
|
void Resource::reload()
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
// Obtiene el sonido a partir de un nombre
|
// Obtiene el sonido a partir de un nombre
|
||||||
JA_Sound_t *Resource::getSound(const std::string &name)
|
JA_Sound_t *Resource::getSound(const std::string &name)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -117,6 +117,12 @@ private:
|
|||||||
// Crea los objetos de texto
|
// Crea los objetos de texto
|
||||||
void createText();
|
void createText();
|
||||||
|
|
||||||
|
// Vacia todos los vectores de recursos
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
// Carga todos los recursos
|
||||||
|
void load();
|
||||||
|
|
||||||
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos resource desde fuera
|
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos resource desde fuera
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
@@ -155,4 +161,7 @@ public:
|
|||||||
|
|
||||||
// Obtiene el fichero con los datos para el modo demostración a partir de un çindice
|
// Obtiene el fichero con los datos para el modo demostración a partir de un çindice
|
||||||
DemoData &getDemoData(int index);
|
DemoData &getDemoData(int index);
|
||||||
|
|
||||||
|
// Recarga todos los recursos
|
||||||
|
void reload();
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user