diff --git a/source/ask_me.cpp b/source/ask_me.cpp new file mode 100644 index 0000000..a062c73 --- /dev/null +++ b/source/ask_me.cpp @@ -0,0 +1,13 @@ +#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 new file mode 100644 index 0000000..fc4eec4 --- /dev/null +++ b/source/ask_me.h @@ -0,0 +1,27 @@ +#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/cheevos.cpp b/source/cheevos.cpp new file mode 100644 index 0000000..91cc0e9 --- /dev/null +++ b/source/cheevos.cpp @@ -0,0 +1,13 @@ +#include "cheevos.h" + +// Constructor +Cheevos::Cheevos(options_t *options) +{ + this->options = options; +} + +// Destructor +Cheevos::~Cheevos() +{ + +} \ No newline at end of file diff --git a/source/cheevos.h b/source/cheevos.h new file mode 100644 index 0000000..d90fb95 --- /dev/null +++ b/source/cheevos.h @@ -0,0 +1,27 @@ +#pragma once +#include +#include "common/utils.h" +#include +#include + +#ifndef CHEEVOS_H +#define CHEEVOS_H + +class Cheevos +{ +private: + // Punteros y objetos + options_t *options; + + // Variables + + +public: + // Constructor + Cheevos(options_t *options); + + // Destructor + ~Cheevos(); +}; + +#endif diff --git a/source/common/notify.cpp b/source/common/notify.cpp index 4be6665..651a2ab 100644 --- a/source/common/notify.cpp +++ b/source/common/notify.cpp @@ -135,7 +135,7 @@ void Notify::showText(std::string text) SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255); SDL_RenderClear(renderer); n.texture->setBlendMode(SDL_BLENDMODE_BLEND); - this->text->writeDX(TXT_CENTER | TXT_STROKE, width / 2, despV, text, 1, {255, 255, 255}, 1, {0, 0, 0}); + this->text->writeDX(TXT_CENTER | TXT_STROKE, width / 2, despV, text, 1, {255, 255, 255}, 2, {0, 0, 0}); SDL_SetRenderTarget(renderer, nullptr); // Crea el sprite diff --git a/source/common/screen.cpp b/source/common/screen.cpp index 4bdc562..473f3f9 100644 --- a/source/common/screen.cpp +++ b/source/common/screen.cpp @@ -29,7 +29,10 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight); if (gameCanvas == nullptr) { - std::cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << std::endl; + if (options->console) + { + std::cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << std::endl; + } } // Establece el modo de video diff --git a/source/const.h b/source/const.h index 7de58b1..dd30b2f 100644 --- a/source/const.h +++ b/source/const.h @@ -57,7 +57,8 @@ const int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3; #define SECTION_PROG_GAME_OVER 6 #define SECTION_PROG_ENDING 7 #define SECTION_PROG_ENDING2 8 -#define SECTION_PROG_QUIT 9 +#define SECTION_PROG_ENTER_ID 9 +#define SECTION_PROG_QUIT 10 // Subsecciones #define SUBSECTION_LOGO_TO_INTRO 0 diff --git a/source/director.cpp b/source/director.cpp index 27b2c1b..623e9d4 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -84,16 +84,22 @@ Director::~Director() // Inicializa los servicios online void Director::initOnline() { - if (!options->online.enabled) - { - return; - } + //if (!options->online.enabled) + //{ + // return; + //} + + options->online.enabled = true; // Obten el Jailer ID if (options->online.jailerID == "") { // Jailer ID no definido screen->showText("No ha especificado ningun Jailer ID"); - std::cout << "No ha especificado ningun Jailer ID" << std::endl; + if (options->console) + { + std::cout << "No ha especificado ningun Jailer ID" << std::endl; + } + options->online.enabled = false; } else { // Jailer ID iniciado @@ -105,12 +111,18 @@ void Director::initOnline() if (jscore::initOnlineScore(options->online.gameID)) { screen->showText(options->online.jailerID + " ha iniciado sesion"); - std::cout << options->online.jailerID << " ha iniciado sesion" << std::endl; + if (options->console) + { + std::cout << options->online.jailerID << " ha iniciado sesion" << std::endl; + } } else { screen->showText("Fallo al conectar a " + options->online.server); - std::cout << "Fallo al conectar a " << options->online.server << std::endl; + if (options->console) + { + std::cout << "Fallo al conectar a " << options->online.server << std::endl; + } options->online.enabled = false; @@ -358,9 +370,9 @@ void Director::createSystemFolder() #endif #ifdef _WIN32 - systemFolder = std::string(getenv("APPDATA")) + "/" + folderName; + systemFolder = std::string(getenv("APPDATA")) + "/" + folderName; #elif __APPLE__ - struct passwd *pw = getpwuid(getuid()); + struct passwd *pw = getpwuid(getuid()); const char *homedir = pw->pw_dir; systemFolder = std::string(homedir) + "/Library/Application Support/" + folderName; #elif __linux__ @@ -386,15 +398,15 @@ void Director::createSystemFolder() case EACCES: printf("the parent directory does not allow write"); exit(EXIT_FAILURE); - + case EEXIST: printf("pathname already exists"); exit(EXIT_FAILURE); - + case ENAMETOOLONG: printf("pathname is too long"); exit(EXIT_FAILURE); - + default: perror("mkdir"); exit(EXIT_FAILURE); @@ -1647,6 +1659,20 @@ void Director::runDemo() resource->free(); } +// Ejecuta la seccion en la que se solicita al usuario su ID online +void Director::runEnterID() +{ + if (options->console) + { + std::cout << "\n* SECTION: ENTER_ID" << std::endl; + } + // loadResources(section); + enterID = new EnterID(renderer, screen, asset, options); + setSection(enterID->run()); + delete enterID; + resource->free(); +} + // Ejecuta la seccion del final del juego void Director::runEnding() { @@ -1731,6 +1757,10 @@ void Director::run() runDemo(); break; + case SECTION_PROG_ENTER_ID: + runEnterID(); + break; + case SECTION_PROG_GAME: runGame(); break; diff --git a/source/director.h b/source/director.h index c237497..01713be 100644 --- a/source/director.h +++ b/source/director.h @@ -12,13 +12,14 @@ #include "const.h" #include "credits.h" #include "demo.h" +#include "ending.h" +#include "ending2.h" +#include "enter_id.h" +#include "game_over.h" #include "game.h" #include "intro.h" #include "logo.h" #include "title.h" -#include "game_over.h" -#include "ending.h" -#include "ending2.h" #ifndef DIRECTOR_H #define DIRECTOR_H @@ -39,6 +40,7 @@ private: Intro *intro; // Objeto para gestionar la introducción del juego Credits *credits; // Objeto para gestionar los creditos del juego Demo *demo; // Objeto para gestionar el modo demo, en el que se ven pantallas del juego + EnterID *enterID; // Objeto para gestionar la sección donde se solicita el ID online al usuario Ending *ending; // Objeto para gestionar el final del juego Ending2 *ending2; // Objeto para gestionar el final del juego GameOver *gameOver; // Objeto para gestionar el final de la partida @@ -53,7 +55,7 @@ private: // Crea e inicializa las opciones del programa void initOptions(); - + // Inicializa los servicios online void initOnline(); @@ -111,6 +113,9 @@ private: // Ejecuta la seccion de la demo, donde se ven pantallas del juego void runDemo(); + // Ejecuta la seccion en la que se solicita al usuario su ID online + void runEnterID(); + // Ejecuta la seccion del final del juego void runEnding(); diff --git a/source/enter_id.cpp b/source/enter_id.cpp new file mode 100644 index 0000000..ddc0e04 --- /dev/null +++ b/source/enter_id.cpp @@ -0,0 +1,135 @@ +#include "enter_id.h" +#include "const.h" +#include "common/jail_audio.h" + +// Constructor +EnterID::EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options) +{ + // Copia la dirección de los objetos + this->renderer = renderer; + this->screen = screen; + this->asset = asset; + this->options = options; + + // Reserva memoria para los punteros + eventHandler = new SDL_Event(); + texture = new Texture(renderer, asset->get("smb2.png")); + text = new Text(asset->get("smb2.txt"), texture, renderer); + + // Inicializa variables + counter = 0; + section.name = SECTION_PROG_ENTER_ID; + ticks = 0; + ticksSpeed = 15; +} + +// Destructor +EnterID::~EnterID() +{ + delete eventHandler; + delete text; + delete texture; +} + +// Bucle para el logo del juego +section_t EnterID::run() +{ + // Detiene la música + JA_StopMusic(); + + while (section.name == SECTION_PROG_ENTER_ID) + { + update(); + render(); + } + + return section; +} + +// Comprueba el manejador de eventos +void EnterID::checkEventHandler() +{ + // Comprueba los eventos que hay en la cola + while (SDL_PollEvent(eventHandler) != 0) + { + // Evento de salida de la aplicación + if (eventHandler->type == SDL_QUIT) + { + section.name = SECTION_PROG_QUIT; + break; + } + + // Comprueba las teclas que se han pulsado + if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN)) + { + switch (eventHandler->key.keysym.scancode) + { + case SDL_SCANCODE_ESCAPE: + section.name = SECTION_PROG_QUIT; + break; + + case SDL_SCANCODE_F1: + screen->setWindowSize(1); + break; + + case SDL_SCANCODE_F2: + screen->setWindowSize(2); + break; + + case SDL_SCANCODE_F3: + screen->setWindowSize(3); + break; + + case SDL_SCANCODE_F4: + screen->setWindowSize(4); + break; + + case SDL_SCANCODE_F5: + // switchPalette(); + break; + + default: + break; + } + } + } +} + +// Actualiza las variables +void EnterID::update() +{ + // Comprueba que la diferencia de ticks sea mayor a la velocidad del juego + if (SDL_GetTicks() - ticks > ticksSpeed) + { + // Actualiza el contador de ticks + ticks = SDL_GetTicks(); + + // Comprueba el manejador de eventos + checkEventHandler(); + + // Actualiza el contador + counter++; + + // Comprueba el contador + if (counter > 200) + { + section.name = SECTION_PROG_INTRO; + } + } +} + +// Dibuja en pantalla +void EnterID::render() +{ + // Prepara para empezar a dibujar en la textura de juego + screen->start(); + + // Limpia la pantalla + screen->clean(); + + // Escribe texto + text->writeCentered(GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y, "SECCION ENTER_ID"); + + // Vuelca el contenido del renderizador en pantalla + screen->blit(); +} \ No newline at end of file diff --git a/source/enter_id.h b/source/enter_id.h new file mode 100644 index 0000000..0eada85 --- /dev/null +++ b/source/enter_id.h @@ -0,0 +1,52 @@ +#pragma once +#include +#include "common/asset.h" +#include "common/screen.h" +#include "common/utils.h" +#include "common/text.h" +#include "common/texture.h" +#include +#include + +#ifndef ENTER_ID_H +#define ASK_ME_H + +class EnterID +{ +private: + // Punteros y objetos + Asset *asset; // Objeto con los ficheros de recursos + options_t *options; // Puntero a las opciones del juego + Screen *screen; // Objeto encargado de dibujar en pantalla + SDL_Event *eventHandler; // Manejador de eventos + SDL_Renderer *renderer; // El renderizador de la ventana + Text *text; // Objeto para escribir texto en pantalla + Texture *texture; // Textura para la fuente para el texto + + // Variables + int counter; // Contador + section_t section; // Estado del bucle principal para saber si continua o se sale + Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa + Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa + + // Actualiza las variables + void update(); + + // Dibuja en pantalla + void render(); + + // Comprueba el manejador de eventos + void checkEventHandler(); + +public: + // Constructor + EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options); + + // Destructor + ~EnterID(); + + // Bucle principal + section_t run(); +}; + +#endif diff --git a/source/logo.cpp b/source/logo.cpp index 35dd291..cb3d92a 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -87,7 +87,6 @@ void Logo::checkEventHandler() switch (eventHandler->key.keysym.scancode) { case SDL_SCANCODE_ESCAPE: - // std::cout << "PULSADO ESCAPE" << std::endl; section.name = SECTION_PROG_QUIT; break; @@ -270,7 +269,13 @@ void Logo::update() // Comprueba si ha terminado el logo if (counter == endLogo + postLogo) { - if (section.subsection == SUBSECTION_LOGO_TO_INTRO) + 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;