diff --git a/data/notify.png b/data/notify.png new file mode 100644 index 0000000..753f74c Binary files /dev/null and b/data/notify.png differ diff --git a/data/notify.wav b/data/notify.wav new file mode 100644 index 0000000..ddb57c0 Binary files /dev/null and b/data/notify.wav differ diff --git a/main.cpp b/main.cpp index d4fa007..443c420 100644 --- a/main.cpp +++ b/main.cpp @@ -13,6 +13,7 @@ Código fuente creado por JailDesigner #include "units/asset.h" #include "units/movingsprite.h" #include "units/texture.h" +#include "units/screen.h" SDL_Event *event; SDL_Window *window; @@ -30,6 +31,7 @@ int main(int argc, char *argv[]) // Inicializa las opciones struct options_t *options = new options_t; + initOptions(options); options->gameWidth = 640; options->gameHeight = 480; options->console = true; @@ -41,6 +43,8 @@ int main(int argc, char *argv[]) asset->add("/data/smb2.txt", t_font); asset->add("/data/smb2.png", t_bitmap); asset->add("/data/z80.png", t_bitmap); + asset->add("/data/notify.png", t_bitmap); + asset->add("/data/notify.wav", t_sound); asset->setVerbose(options->console); if (!asset->check()) { @@ -74,6 +78,10 @@ int main(int argc, char *argv[]) sound = JA_LoadSound(asset->get("sound.wav").c_str()); int volume = 128; + // Inicializa el objeto screen + Screen *screen = new Screen(window, renderer, options); + screen->addNotifier(asset->get("notify.png"), asset->get("smb2.png"), asset->get("smb2.txt"), asset->get("notify.wav")); + // Inicializa el texto Text *text = new Text(asset->get("smb2.txt"), asset->get("smb2.png"), renderer); @@ -160,7 +168,7 @@ int main(int argc, char *argv[]) sprite->update(); // Actualiza el degradado - //if (counter % 4 == 0) + // if (counter % 4 == 0) { gradBreathDirection == 0 ? gradCurrentColor-- : gradCurrentColor++; if (gradCurrentColor == gradColorMin) @@ -175,8 +183,10 @@ int main(int argc, char *argv[]) } // Dibuja en pantalla - SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF); - SDL_RenderClear(renderer); + //SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF); + //SDL_RenderClear(renderer); + screen->start(); + screen->clean(); // Dibuja un degradado de fondo const int gradFirstLine = options->gameHeight / 3; const int gradLastLine = options->gameHeight; @@ -195,7 +205,8 @@ int main(int argc, char *argv[]) // Dibuja el sprite sprite->render(); // Vuelca el buffer en pantalla - SDL_RenderPresent(renderer); + //SDL_RenderPresent(renderer); + screen->blit(); } // Finaliza el sprite @@ -205,6 +216,9 @@ int main(int argc, char *argv[]) // Finaliza el texto delete text; + // Finaliza el objeto screen + delete screen; + // Finaliza jail_audio JA_DeleteSound(sound); JA_DeleteMusic(music); diff --git a/units/screen.cpp b/units/screen.cpp index 2158bd3..7c9c359 100644 --- a/units/screen.cpp +++ b/units/screen.cpp @@ -3,16 +3,12 @@ #include // Constructor -Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options) +Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options) { // Inicializa variables this->window = window; this->renderer = renderer; this->options = options; - this->asset = asset; - - // Crea los objetos - notify = new Notify(renderer, asset->get("notify.png"), asset->get("smb2.png"), asset->get("smb2.txt"), asset->get("notify.wav"), options); gameCanvasWidth = options->gameWidth; gameCanvasHeight = options->gameHeight; @@ -41,13 +37,17 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options setVideoMode(options->videoMode); // Inicializa variables + notifyAdded = false; notifyActive = false; } // Destructor Screen::~Screen() { - delete notify; + if (notify != nullptr) + { + delete notify; + } SDL_DestroyTexture(gameCanvas); } @@ -97,7 +97,7 @@ void Screen::setVideoMode(int videoMode) SDL_ShowCursor(SDL_ENABLE); // Esconde la ventana - //SDL_HideWindow(window); + // SDL_HideWindow(window); if (options->borderEnabled) { @@ -118,7 +118,7 @@ void Screen::setVideoMode(int videoMode) SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); // Muestra la ventana - //SDL_ShowWindow(window); + // SDL_ShowWindow(window); } // Si está activo el modo de pantalla completa añade el borde @@ -385,30 +385,46 @@ void Screen::renderFX() renderSpectrumFade(); } +// Añade un notificador a la pantalla +void Screen::addNotifier(string iconsFile, string bitmapFontFile, string offsetFontFile, string soundFile) +{ + notify = new Notify(renderer, iconsFile, bitmapFontFile, offsetFontFile, soundFile, options); + notifyAdded = true; +} + // Actualiza el notificador void Screen::updateNotifier() { - notify->update(); - notifyActive = notify->active(); + if (notifyAdded) + { + notify->update(); + notifyActive = notify->active(); + } } // Muestra una notificación de texto por pantalla; void Screen::showNotification(std::string text1, std::string text2, int icon) { - notify->showText(text1, text2, icon); + if (notifyAdded) + { + notify->showText(text1, text2, icon); + } } // Dibuja las notificaciones void Screen::renderNotifications() { - if (!notifyActive) + if (notifyAdded) { - return; - } + if (!notifyActive) + { + return; + } - SDL_RenderSetLogicalSize(renderer, notificationLogicalWidth, notificationLogicalHeight); - notify->render(); - SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight); + SDL_RenderSetLogicalSize(renderer, notificationLogicalWidth, notificationLogicalHeight); + notify->render(); + SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight); + } } // Establece el tamaño de las notificaciones diff --git a/units/screen.h b/units/screen.h index a35fd5b..f55d70a 100644 --- a/units/screen.h +++ b/units/screen.h @@ -1,7 +1,6 @@ #pragma once #include -#include "asset.h" #include "notify.h" #include "utils.h" #include @@ -18,7 +17,6 @@ private: // Objetos y punteros SDL_Window *window; // Ventana de la aplicación SDL_Renderer *renderer; // El renderizador de la ventana - Asset *asset; // Objeto con el listado de recursos SDL_Texture *gameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa options_t *options; // Variable con todas las opciones del programa Notify *notify; // Dibuja notificaciones por pantalla @@ -32,6 +30,7 @@ private: int borderHeight; // Anltura del borde SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla + bool notifyAdded; // Indica si se ha añadido un notificador bool notifyActive; // Indica si hay notificaciones activas int notificationLogicalWidth; // Ancho lógico de las notificaciones en relación al tamaño de pantalla int notificationLogicalHeight; // Alto lógico de las notificaciones en relación al tamaño de pantalla @@ -71,7 +70,7 @@ private: public: // Constructor - Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options); + Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options); // Destructor ~Screen(); @@ -134,6 +133,9 @@ public: // Dibuja los efectos void renderFX(); + // Añade un notificador a la pantalla + void addNotifier(string iconsFile, string bitmapFontFile, string offsetFontFile, string soundFile); + // Actualiza el notificador void updateNotifier(); diff --git a/units/utils.cpp b/units/utils.cpp index c2d109a..f7d84a5 100644 --- a/units/utils.cpp +++ b/units/utils.cpp @@ -553,4 +553,31 @@ bool colorAreEqual(color_t color1, color_t color2) const bool b = color1.b == color2.b; return (r && g && b); +} + +// Inicializa la estructura de opciones +void initOptions(options_t *options) +{ + options->configVersion = ""; + options->videoMode = 0; + options->windowSize = 1; + options->filter = 0; + options->vSync = true; + options->gameWidth = 320; + options->gameHeight = 240; + options->integerScale = true; + options->keepAspect = true; + options->borderEnabled = false; + options->borderWidth = 0; + options->borderHeight = 0; + options->palette = p_zxspectrum; + options->console = false; + + options->notifications.posV = pos_top; + options->notifications.posH = pos_left; + options->notifications.sound = true; + options->notifications.color = {48, 48, 48}; + + options->screen.windowWidth = options->gameWidth * options->windowSize; + options->screen.windowHeight = options->gameHeight * options->windowSize; } \ No newline at end of file diff --git a/units/utils.h b/units/utils.h index 512d4d7..77c456b 100644 --- a/units/utils.h +++ b/units/utils.h @@ -102,20 +102,20 @@ struct cheat_t // Estructura para el servicio online struct online_t { - bool enabled; // Indica si se quiere usar el modo online o no - bool sessionEnabled; // Indica ya se ha hecho login - string server; // Servidor para los servicios online - int port; // Puerto del servidor - string gameID; // Identificador del juego para los servicios online - string jailerID; // Identificador del jugador para los servicios online - int score; // Puntuación almacenada online + bool enabled; // Indica si se quiere usar el modo online o no + bool sessionEnabled; // Indica ya se ha hecho login + string server; // Servidor para los servicios online + int port; // Puerto del servidor + string gameID; // Identificador del juego para los servicios online + string jailerID; // Identificador del jugador para los servicios online + int score; // Puntuación almacenada online }; // Estructura para almacenar estadísticas struct op_stats_t { - int rooms; // Cantidad de habitaciones visitadas - int items; // Cantidad de items obtenidos + int rooms; // Cantidad de habitaciones visitadas + int items; // Cantidad de items obtenidos string worstNightmare; // Habitación con más muertes acumuladas }; @@ -129,7 +129,7 @@ struct op_screen_t // Estructura con todas las opciones de configuración del programa struct options_t { - string configVersion; // Versión del programa. Sirve para saber si las opciones son compatibles + 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 @@ -199,4 +199,7 @@ string boolToString(bool value); // Compara dos colores bool colorAreEqual(color_t color1, color_t color2); +// Inicializa la estructura de opciones +void initOptions(options_t *options); + #endif \ No newline at end of file