diff --git a/Makefile b/Makefile index a2dbe8b..e0e7dbc 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ executable = jaildoctors_dilemma source = source/*.cpp source/common/*.cpp appName = JailDoctor's Dilemma releaseFolder = jdd_release -version = v1.06 +version = v1.06.1 # Release names windowsRelease = $(executable)-$(version)-win32-x64.zip diff --git a/data/sound/notify.wav b/data/sound/notify.wav new file mode 100644 index 0000000..87927fc Binary files /dev/null and b/data/sound/notify.wav differ diff --git a/source/ask_me.cpp b/source/ask_me.cpp deleted file mode 100644 index a062c73..0000000 --- a/source/ask_me.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "ask_me.h" - -// Constructor -AskMe::AskMe(options_t *options) -{ - this->options = options; -} - -// Destructor -AskMe::~AskMe() -{ - -} \ No newline at end of file diff --git a/source/ask_me.h b/source/ask_me.h deleted file mode 100644 index fc4eec4..0000000 --- a/source/ask_me.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once -#include -#include "common/utils.h" -#include -#include - -#ifndef ASK_ME_H -#define ASK_ME_H - -class AskMe -{ -private: - // Punteros y objetos - options_t *options; - - // Variables - - -public: - // Constructor - AskMe(options_t *options); - - // Destructor - ~AskMe(); -}; - -#endif diff --git a/source/common/notify.cpp b/source/common/notify.cpp index 4be6665..43e3ca3 100644 --- a/source/common/notify.cpp +++ b/source/common/notify.cpp @@ -4,7 +4,7 @@ #include // Constructor -Notify::Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile) +Notify::Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile, std::string soundFile) { // Inicializa variables this->renderer = renderer; @@ -14,6 +14,7 @@ Notify::Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textF // Crea objetos texture = new Texture(renderer, bitmapFile); text = new Text(textFile, texture, renderer); + sound = JA_LoadSound(soundFile.c_str()); } // Destructor @@ -22,6 +23,7 @@ Notify::~Notify() // Libera la memoria de los objetos delete texture; delete text; + JA_DeleteSound(sound); for (auto notification : notifications) { @@ -143,6 +145,9 @@ void Notify::showText(std::string text) // Añade la notificación a la lista notifications.push_back(n); + + // Reproduce el sonido de la notificación + JA_PlaySound(sound); } // Indica si hay notificaciones activas diff --git a/source/common/notify.h b/source/common/notify.h index dbc6b67..fae665f 100644 --- a/source/common/notify.h +++ b/source/common/notify.h @@ -1,9 +1,10 @@ #pragma once #include +#include "jail_audio.h" +#include "sprite.h" #include "text.h" #include "texture.h" -#include "sprite.h" #include "utils.h" #include @@ -55,6 +56,7 @@ private: color_t bgColor; // Color de fondo de las notificaciones int waitTime; // Tiempo que se ve la notificación std::vector notifications; // La lista de notificaciones activas + JA_Sound sound; // Sonido a reproducir cuando suena la notificación // Elimina las notificaciones finalizadas void clearFinishedNotifications(); @@ -67,7 +69,7 @@ public: void update(); // Constructor - Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile); + Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile, std::string soundFile); // Destructor ~Notify(); diff --git a/source/common/screen.cpp b/source/common/screen.cpp index 473f3f9..b05f846 100644 --- a/source/common/screen.cpp +++ b/source/common/screen.cpp @@ -12,7 +12,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options this->asset = asset; // Crea los objetos - notify = new Notify(renderer, asset->get("smb2.png"), asset->get("smb2.txt")); + notify = new Notify(renderer, asset->get("smb2.png"), asset->get("smb2.txt"), asset->get("notify.wav")); gameCanvasWidth = options->gameWidth; gameCanvasHeight = options->gameHeight; diff --git a/source/common/utils.cpp b/source/common/utils.cpp index e05dc28..7f6fae7 100644 --- a/source/common/utils.cpp +++ b/source/common/utils.cpp @@ -294,28 +294,6 @@ SDL_Point checkCollision(d_line_t &l1, v_line_t &l2) return {-1, -1}; } -// Detector de colisiones entre una linea diagonal y una vertical -/*bool checkCollision(d_line_t &l1, v_line_t &l2) -{ - // Normaliza la linea diagonal - normalizeLine(l1); - - // Comprueba si la linea vertical esta a la izquierda de la linea diagonal - if (l2.x < l1.x1) - { - return false; - } - - // Comprueba si la linea vertical esta a la derecha de la linea diagonal - if (l2.x > l1.x2) - { - return false; - } - - // Inacabada - return true; -}*/ - // Normaliza una linea diagonal void normalizeLine(d_line_t &l) { @@ -367,16 +345,6 @@ bool checkCollision(SDL_Point &p, d_line_t &l) // En caso contrario, el punto está en la linea return true; - - - /*const int m = (l.y2 - l.y1) / (l.x2 - l.x1); - const int c = 0; - - // Comprueba si p cumple la ecuación de la linea - if (p.y == ((m * p.x) + c)) - return true; - - return false;*/ } // Devuelve un color_t a partir de un string diff --git a/source/common/utils.h b/source/common/utils.h index 097a4d7..be1d648 100644 --- a/source/common/utils.h +++ b/source/common/utils.h @@ -92,21 +92,22 @@ struct op_stats_t // Estructura con todas las opciones de configuración del programa struct options_t { - Uint32 videoMode; // Contiene el valor del modo de pantalla completa - int windowSize; // Contiene el valor por el que se multiplica el tamaño de la ventana - Uint32 filter; // Filtro usado para el escalado de la imagen - bool vSync; // Indica si se quiere usar vsync o no - int gameWidth; // Ancho de la resolucion nativa del juego - int gameHeight; // Alto de la resolucion nativa del juego - bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa - bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa - bool borderEnabled; // Indica si ha de mostrar el borde en el modo de ventana - float borderSize; // Porcentaje de borde que se añade a lo ventana - palette_e palette; // Paleta de colores a usar en el juego - bool console; // Indica si ha de mostrar información por la consola de texto - cheat_t cheat; // Contiene trucos y ventajas para el juego - op_stats_t stats; // Datos con las estadisticas de juego - online_t online; // Datos del servicio online + std::string configVersion; // Versión del programa. Sirve para saber si las opciones son compatibles + Uint32 videoMode; // Contiene el valor del modo de pantalla completa + int windowSize; // Contiene el valor por el que se multiplica el tamaño de la ventana + Uint32 filter; // Filtro usado para el escalado de la imagen + bool vSync; // Indica si se quiere usar vsync o no + int gameWidth; // Ancho de la resolucion nativa del juego + int gameHeight; // Alto de la resolucion nativa del juego + bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa + bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa + bool borderEnabled; // Indica si ha de mostrar el borde en el modo de ventana + float borderSize; // Porcentaje de borde que se añade a lo ventana + palette_e palette; // Paleta de colores a usar en el juego + bool console; // Indica si ha de mostrar información por la consola de texto + cheat_t cheat; // Contiene trucos y ventajas para el juego + op_stats_t stats; // Datos con las estadisticas de juego + online_t online; // Datos del servicio online }; // Calcula el cuadrado de la distancia entre dos puntos diff --git a/source/director.cpp b/source/director.cpp index 4a8d033..d31e192 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -18,7 +18,7 @@ Director::Director(int argc, char *argv[]) section.subsection = SUBSECTION_LOGO_TO_INTRO; #ifdef DEBUG - section.name = SECTION_PROG_GAME; + section.name = SECTION_PROG_LOGO; #endif // Crea e inicializa las opciones del programa @@ -59,7 +59,7 @@ Director::Director(int argc, char *argv[]) music = JA_LoadMusic(asset->get("title.ogg").c_str()); // Inicializa los servicios online - initOnline(); + //initOnline(); } Director::~Director() @@ -112,7 +112,10 @@ void Director::initOptions() // Crea el puntero a la estructura de opciones options = new options_t; - // Inicializa valores + // Version + options->configVersion = "v1.06.1"; + + // Opciones dee video options->gameWidth = GAMECANVAS_WIDTH; options->gameHeight = GAMECANVAS_HEIGHT; options->videoMode = 0; @@ -134,8 +137,8 @@ void Director::initOptions() options->stats.rooms = 0; options->stats.items = 0; - // Online - options->online.enabled = false; + // Opciones online + options->online.enabled = true; options->online.server = "jaildoctor.duckdns.org"; options->online.port = 9911; #ifdef DEBUG @@ -188,6 +191,10 @@ bool Director::loadConfig() // Indicador de éxito en la carga bool success = true; + // Versión actual del fichero + const std::string configVersion = options->configVersion; + options->configVersion = ""; + // Variables para manejar el fichero std::string line; std::ifstream file(asset->get("config.txt")); @@ -234,6 +241,13 @@ bool Director::loadConfig() saveConfig(); } + // Si la versión de fichero no coincide, crea un fichero nuevo con los valores por defecto + if (configVersion != options->configVersion) + { + initOptions(); + saveConfig(); + } + // Normaliza los valores const bool a = options->videoMode == 0; const bool b = options->videoMode == SDL_WINDOW_FULLSCREEN; @@ -289,7 +303,10 @@ bool Director::saveConfig() } // Escribe en el fichero - file << "## VISUAL OPTIONS\n"; + file << "## VERSION\n"; + file << "version=" + options->configVersion + "\n"; + + file << "\n## VISUAL OPTIONS\n"; if (options->videoMode == 0) { file << "videoMode=0\n"; @@ -954,7 +971,12 @@ bool Director::setOptions(options_t *options, std::string var, std::string value // Indicador de éxito en la asignación bool success = true; - if (var == "videoMode") + if (var == "configVersion") + { + options->configVersion = value; + } + + else if (var == "videoMode") { if (value == "SDL_WINDOW_FULLSCREEN_DESKTOP") { @@ -1512,6 +1534,7 @@ bool Director::setFileList() asset->add(prefix + "/data/sound/jump22.wav", t_sound); asset->add(prefix + "/data/sound/jump23.wav", t_sound); asset->add(prefix + "/data/sound/jump24.wav", t_sound); + asset->add(prefix + "/data/sound/notify.wav", t_sound); // Logo asset->add(prefix + "/data/logo/jailgames.png", t_bitmap); diff --git a/source/enter_id.cpp b/source/enter_id.cpp index dbd4cea..357a910 100644 --- a/source/enter_id.cpp +++ b/source/enter_id.cpp @@ -40,9 +40,6 @@ EnterID::EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t // Escribe el texto en la textura fillTexture(); - - // Deja el texto a tamaño fijo - // text->setFixedWidth(true); } // Destructor @@ -81,6 +78,17 @@ void EnterID::checkEventHandler() break; } + // El ENTER solo se comprueba cuando se suelta, para no saltarse la siguiente sección + if ((eventHandler->type == SDL_KEYUP && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONUP)) + { + if (eventHandler->key.keysym.scancode == SDL_SCANCODE_RETURN) + { + options->online.jailerID = (std::string)name; + endSection(); + break; + } + } + // Comprueba las teclas que se han pulsado if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN)) { @@ -116,13 +124,7 @@ void EnterID::checkEventHandler() name[--pos] = 0; } } - else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_RETURN) - { - options->online.jailerID = (std::string)name; - initOnline(); - section.name = SECTION_PROG_INTRO; - break; - } + else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_ESCAPE) { section.name = SECTION_PROG_QUIT; @@ -286,4 +288,12 @@ void EnterID::initOnline() std::cout << caption << std::endl; } } +} + +// Termina la sección +void EnterID::endSection() +{ + initOnline(); + section.name = (section.subsection == SUBSECTION_LOGO_TO_INTRO) ? SECTION_PROG_INTRO : SECTION_PROG_TITLE; + section.subsection = 0; } \ No newline at end of file diff --git a/source/enter_id.h b/source/enter_id.h index 4f85bc9..38fdcbf 100644 --- a/source/enter_id.h +++ b/source/enter_id.h @@ -63,6 +63,9 @@ private: // Inicializa los servicios online void initOnline(); + // Termina la sección + void endSection(); + public: // Constructor EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options); diff --git a/source/logo.cpp b/source/logo.cpp index cb3d92a..3693ee8 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -125,8 +125,7 @@ void Logo::checkEventHandler() break; default: - section.name = SECTION_PROG_TITLE; - section.subsection = 0; + endSection(); break; } } @@ -269,22 +268,7 @@ void Logo::update() // Comprueba si ha terminado el logo if (counter == endLogo + postLogo) { - if (options->online.jailerID == "") - { - section.name = SECTION_PROG_ENTER_ID; - section.subsection = 0; - } - - else if (section.subsection == SUBSECTION_LOGO_TO_INTRO) - { - section.name = SECTION_PROG_INTRO; - section.subsection = 0; - } - else - { - section.name = SECTION_PROG_TITLE; - section.subsection = 0; - } + endSection(); } } } @@ -327,12 +311,18 @@ section_t Logo::run() // Cambia la paleta void Logo::switchPalette() { - if (options->palette == p_zxspectrum) + options->palette = options->palette == p_zxspectrum ? p_zxarne : p_zxspectrum; +} + +// Termina la sección +void Logo::endSection() +{ + if (options->online.enabled && options->online.jailerID == "") { - options->palette = p_zxarne; + section.name = SECTION_PROG_ENTER_ID; } else { - options->palette = p_zxspectrum; + section.name = (section.subsection == SUBSECTION_LOGO_TO_INTRO) ? SECTION_PROG_INTRO : SECTION_PROG_TITLE; } } \ No newline at end of file diff --git a/source/logo.h b/source/logo.h index 7bdc77e..882ea70 100644 --- a/source/logo.h +++ b/source/logo.h @@ -56,6 +56,9 @@ private: // Cambia la paleta void switchPalette(); + // Termina la sección + void endSection(); + public: // Constructor Logo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, int subsection);