From 022e44cfebb24a0e4e74d83be54ad9848be15cf9 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 18 Jun 2024 08:58:28 +0200 Subject: [PATCH] =?UTF-8?q?A=C3=B1adido=20puntero=20a=20la=20estructura=20?= =?UTF-8?q?param=20en=20las=20clases=20necesarias?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/background.cpp | 3 ++- source/background.h | 3 ++- source/common/utils.h | 8 ++++++++ source/const.h | 24 ++++++++++++------------ source/director.cpp | 32 ++++++++++++++++++++++---------- source/director.h | 6 +++++- source/fade.cpp | 22 +++++++++------------- source/fade.h | 21 +++++++++++++-------- source/game.cpp | 7 ++++--- source/game.h | 5 +++-- source/game_logo.cpp | 5 +++-- source/game_logo.h | 12 +++++++----- source/hiscore_table.cpp | 19 ++++++------------- source/hiscore_table.h | 3 ++- source/instructions.cpp | 11 ++++++----- source/instructions.h | 3 ++- source/intro.cpp | 11 ++++++----- source/intro.h | 3 ++- source/logo.cpp | 7 ++++--- source/logo.h | 3 ++- source/title.cpp | 15 ++++++++------- source/title.h | 8 +++++--- 22 files changed, 133 insertions(+), 98 deletions(-) diff --git a/source/background.cpp b/source/background.cpp index e546d08..1bc6ab5 100644 --- a/source/background.cpp +++ b/source/background.cpp @@ -1,12 +1,13 @@ #include "background.h" // Constructor -Background::Background(SDL_Renderer *renderer, Screen *screen, Asset *asset) +Background::Background(SDL_Renderer *renderer, Screen *screen, Asset *asset, param_t *param) { // Copia los punteros this->renderer = renderer; this->screen = screen; this->asset = asset; + this->param = param; // Inicializa variables gradientNumber = 0; diff --git a/source/background.h b/source/background.h index 657ef20..b975340 100644 --- a/source/background.h +++ b/source/background.h @@ -29,6 +29,7 @@ private: SDL_Rect dstRect; // Posición donde dibujar la parte del objeto fondo que se dibujará en pantalla SDL_Texture *canvas; // Textura para componer el fondo int base; // Linea de fondo coincidente con el area inferior de la zona de juego + param_t *param; // Puntero con todos los parametros del programa Texture *buildingsTexture; // Textura con los edificios de fondo Texture *cloudsTexture; // Textura con las nubes de fondo @@ -49,7 +50,7 @@ private: public: // Constructor - Background(SDL_Renderer *renderer, Screen *screen, Asset *asset); + Background(SDL_Renderer *renderer, Screen *screen, Asset *asset, param_t *param); // Destructor ~Background(); diff --git a/source/common/utils.h b/source/common/utils.h index 8e02417..b3b5214 100644 --- a/source/common/utils.h +++ b/source/common/utils.h @@ -156,6 +156,14 @@ struct options_t op_audio_t audio; // Opciones para el audio }; +struct param_t +{ + int gameWidth; // Ancho del juego + int gameHeight; // Alto del juego + + SDL_Rect scoreboard; // Posición y tamaño del marcador +}; + // Calcula el cuadrado de la distancia entre dos puntos double distanceSquared(int x1, int y1, int x2, int y2); diff --git a/source/const.h b/source/const.h index fd66d7e..f4aab55 100644 --- a/source/const.h +++ b/source/const.h @@ -11,18 +11,18 @@ #define HALF_BLOCK BLOCK / 2 // Resolución nativa del juego -#define GAMECANVAS_WIDTH 320 -#define GAMECANVAS_HEIGHT 240 +#define WIDTH 320 +#define HEIGHT 240 // Marcador -const int SCOREBOARD_WIDTH = GAMECANVAS_WIDTH; +const int SCOREBOARD_WIDTH = WIDTH; const int SCOREBOARD_HEIGHT = 32; const int SCOREBOARD_X = 0; -const int SCOREBOARD_Y = GAMECANVAS_HEIGHT - SCOREBOARD_HEIGHT; +const int SCOREBOARD_Y = HEIGHT - SCOREBOARD_HEIGHT; // Zona de juego -const SDL_Rect windowArea = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT}; -const SDL_Rect playArea = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT - SCOREBOARD_HEIGHT}; +const SDL_Rect windowArea = {0, 0, WIDTH, HEIGHT}; +const SDL_Rect playArea = {0, 0, WIDTH, HEIGHT - SCOREBOARD_HEIGHT}; const int PLAY_AREA_TOP = 0; const int PLAY_AREA_BOTTOM = playArea.h; const int PLAY_AREA_LEFT = 0; @@ -37,12 +37,12 @@ const int PLAY_AREA_FIRST_QUARTER_Y = PLAY_AREA_HEIGHT / 4; const int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3; // Anclajes de pantalla -const int GAMECANVAS_CENTER_X = GAMECANVAS_WIDTH / 2; -const int GAMECANVAS_FIRST_QUARTER_X = GAMECANVAS_WIDTH / 4; -const int GAMECANVAS_THIRD_QUARTER_X = (GAMECANVAS_WIDTH / 4) * 3; -const int GAMECANVAS_CENTER_Y = GAMECANVAS_HEIGHT / 2; -const int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4; -const int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3; +const int GAMECANVAS_CENTER_X = WIDTH / 2; +const int GAMECANVAS_FIRST_QUARTER_X = WIDTH / 4; +const int GAMECANVAS_THIRD_QUARTER_X = (WIDTH / 4) * 3; +const int GAMECANVAS_CENTER_Y = HEIGHT / 2; +const int GAMECANVAS_FIRST_QUARTER_Y = HEIGHT / 4; +const int GAMECANVAS_THIRD_QUARTER_Y = (HEIGHT / 4) * 3; // Secciones del programa #define SECTION_PROG_LOGO 0 diff --git a/source/director.cpp b/source/director.cpp index 81a69cd..660f921 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -14,6 +14,9 @@ // Constructor Director::Director(int argc, char *argv[]) { + // Carga los parametros para configurar el juego + loadParams(); + // Inicializa variables section = new section_t(); section->name = SECTION_PROG_TITLE; @@ -70,6 +73,7 @@ Director::~Director() delete screen; delete lang; delete options; + delete param; delete section; SDL_DestroyRenderer(renderer); @@ -186,9 +190,6 @@ bool Director::initSDL() else { // Crea un renderizador para la ventana. El vsync se activa en funcion de las opciones - // Crea un renderizador para la ventana. El vsync se activa en funcion de las opciones - // Uint32 flags = SDL_RENDERER_SOFTWARE; - // Uint32 flags = SDL_RENDERER_ACCELERATED; Uint32 flags = 0; if (options->video.vSync) { @@ -357,6 +358,17 @@ bool Director::setFileList() return asset->check(); } +// Carga los parametros para configurar el juego +void Director::loadParams() +{ + param = new param_t; + + param->gameWidth = 320; + param->gameHeight = 240; + + param->scoreboard = {0, 240-32, 320, 32}; +} + // Inicializa las opciones del programa void Director::initOptions() { @@ -378,8 +390,8 @@ void Director::initOptions() options->input.push_back(inp); // Opciones de video - options->video.gameWidth = GAMECANVAS_WIDTH; - options->video.gameHeight = GAMECANVAS_HEIGHT; + options->video.gameWidth = param->gameWidth; + options->video.gameHeight = param->gameHeight; options->video.mode = 0; options->video.window.size = 3; options->video.window.width = options->video.window.size * options->video.gameWidth; @@ -625,21 +637,21 @@ bool Director::saveConfigFile() void Director::runLogo() { - logo = new Logo(renderer, screen, asset, input, section); + logo = new Logo(renderer, screen, asset, input, param, section); logo->run(); delete logo; } void Director::runIntro() { - intro = new Intro(renderer, screen, asset, input, lang, section); + intro = new Intro(renderer, screen, asset, input, lang, param, section); intro->run(); delete intro; } void Director::runTitle() { - title = new Title(renderer, screen, input, asset, options, lang, section); + title = new Title(renderer, screen, input, asset, options, lang, param, section); title->run(); delete title; } @@ -647,7 +659,7 @@ void Director::runTitle() void Director::runGame() { const int numPlayers = section->subsection == SUBSECTION_GAME_PLAY_1P ? 1 : 2; - game = new Game(numPlayers, 0, renderer, screen, asset, lang, input, false, options, section); + game = new Game(numPlayers, 0, renderer, screen, asset, lang, input, false, param, options, section); game->run(); delete game; } @@ -768,7 +780,7 @@ bool Director::setOptions(options_t *options, std::string var, std::string value options->audio.sound.enabled = stringToBool(value); } - else if (var == "sound.volume") + else if (var == "sound.volume") { options->audio.sound.volume = std::stoi(value); } diff --git a/source/director.h b/source/director.h index 4e7551f..7d5afef 100644 --- a/source/director.h +++ b/source/director.h @@ -46,7 +46,8 @@ private: section_t *section; // Sección y subsección actual del programa; // Variables - struct options_t *options; // Variable con todas las opciones del programa + options_t *options; // Variable con todas las opciones del programa + param_t *param; // Variable con todos los parametros del programa std::string executablePath; // Path del ejecutable std::string systemFolder; // Carpeta del sistema donde guardar datos @@ -59,6 +60,9 @@ private: // Inicializa el objeto input void initInput(); + // Carga los parametros para configurar el juego + void loadParams(); + // Inicializa las opciones del programa void initOptions(); diff --git a/source/fade.cpp b/source/fade.cpp index 78e986e..a83696b 100644 --- a/source/fade.cpp +++ b/source/fade.cpp @@ -3,15 +3,11 @@ #include // Constructor -Fade::Fade(SDL_Renderer *renderer) +Fade::Fade(SDL_Renderer *renderer, param_t *param) { mRenderer = renderer; - mBackbuffer = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); - if (mBackbuffer == nullptr) - { - std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl; - } + mBackbuffer = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->gameWidth, param->gameHeight); } // Destructor @@ -41,7 +37,7 @@ void Fade::render() switch (mFadeType) { case FADE_FULLSCREEN: - mRect1 = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT}; + mRect1 = {0, 0, param->gameWidth, param->gameHeight}; for (int i = 0; i < 256; i += 4) { @@ -69,21 +65,21 @@ void Fade::render() break; case FADE_CENTER: - mRect1 = {0, 0, GAMECANVAS_WIDTH, 0}; - mRect2 = {0, 0, GAMECANVAS_WIDTH, 0}; + mRect1 = {0, 0, param->gameWidth, 0}; + mRect2 = {0, 0, param->gameWidth, 0}; SDL_SetRenderDrawColor(mRenderer, mR, mG, mB, 64); for (int i = 0; i < mCounter; i++) { mRect1.h = mRect2.h = i * 4; - mRect2.y = GAMECANVAS_HEIGHT - (i * 4); + mRect2.y = param->gameHeight - (i * 4); SDL_RenderFillRect(mRenderer, &mRect1); SDL_RenderFillRect(mRenderer, &mRect2); } - if ((mCounter * 4) > GAMECANVAS_HEIGHT) + if ((mCounter * 4) > param->gameHeight) mFinished = true; break; @@ -101,8 +97,8 @@ void Fade::render() // Dibujamos sobre el backbuffer SDL_SetRenderTarget(mRenderer, mBackbuffer); - mRect1.x = rand() % (GAMECANVAS_WIDTH - mRect1.w); - mRect1.y = rand() % (GAMECANVAS_HEIGHT - mRect1.h); + mRect1.x = rand() % (param->gameWidth - mRect1.w); + mRect1.y = rand() % (param->gameHeight - mRect1.h); SDL_RenderFillRect(mRenderer, &mRect1); // Volvemos a usar el renderizador de forma normal diff --git a/source/fade.h b/source/fade.h index d1890a3..d8a8c33 100644 --- a/source/fade.h +++ b/source/fade.h @@ -2,6 +2,7 @@ #include #include "common/texture.h" +#include "common/utils.h" #ifndef FADE_H #define FADE_H @@ -15,19 +16,23 @@ class Fade { private: + // Objetos y punteros SDL_Renderer *mRenderer; // El renderizador de la ventana SDL_Texture *mBackbuffer; // Textura para usar como backbuffer - Uint8 mFadeType; // Tipo de fade a realizar - Uint16 mCounter; // Contador interno - bool mEnabled; // Indica si el fade está activo - bool mFinished; // Indica si ha terminado la transición - Uint8 mR, mG, mB; // Colores para el fade - SDL_Rect mRect1; // Rectangulo usado para crear los efectos de transición - SDL_Rect mRect2; // Rectangulo usado para crear los efectos de transición + + // Variables + Uint8 mFadeType; // Tipo de fade a realizar + Uint16 mCounter; // Contador interno + bool mEnabled; // Indica si el fade está activo + bool mFinished; // Indica si ha terminado la transición + Uint8 mR, mG, mB; // Colores para el fade + SDL_Rect mRect1; // Rectangulo usado para crear los efectos de transición + SDL_Rect mRect2; // Rectangulo usado para crear los efectos de transición + param_t *param; // Puntero con todos los parametros del programa public: // Constructor - Fade(SDL_Renderer *renderer); + Fade(SDL_Renderer *renderer, param_t *param); // Destructor ~Fade(); diff --git a/source/game.cpp b/source/game.cpp index 3c5b073..cb742b3 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -1,7 +1,7 @@ #include "game.h" // Constructor -Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, options_t *options, section_t *section) +Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, param_t *param, options_t *options, section_t *section) { // Copia los punteros this->renderer = renderer; @@ -9,6 +9,7 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr this->asset = asset; this->lang = lang; this->input = input; + this->param = param; this->options = options; this->section = section; @@ -25,10 +26,10 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr difficulty = options->difficulty; // Crea los objetos - fade = new Fade(renderer); + fade = new Fade(renderer, param); eventHandler = new SDL_Event(); scoreboard = new Scoreboard(renderer, screen, asset, lang, options); - background = new Background(renderer, screen, asset); + background = new Background(renderer, screen, asset, param); // Carga los recursos loadMedia(); diff --git a/source/game.h b/source/game.h index 286911c..abcc198 100644 --- a/source/game.h +++ b/source/game.h @@ -211,7 +211,8 @@ private: Uint8 difficulty; // Dificultad del juego float difficultyScoreMultiplier; // Multiplicador de puntos en función de la dificultad color_t difficultyColor; // Color asociado a la dificultad - struct options_t *options; // Variable con todas las variables de las opciones del programa + options_t *options; // Variable con todas las opciones del programa + param_t *param; // Puntero con todos los parametros del programa Uint8 onePlayerControl; // Variable para almacenar el valor de las opciones enemyFormation_t enemyFormation[NUMBER_OF_ENEMY_FORMATIONS]; // Vector con todas las formaciones enemigas enemyPool_t enemyPool[10]; // Variable con los diferentes conjuntos de formaciones enemigas @@ -487,7 +488,7 @@ private: public: // Constructor - Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, options_t *options, section_t *section); + Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, param_t *param, options_t *options, section_t *section); // Destructor ~Game(); diff --git a/source/game_logo.cpp b/source/game_logo.cpp index b344280..c68f16d 100644 --- a/source/game_logo.cpp +++ b/source/game_logo.cpp @@ -1,12 +1,13 @@ #include "game_logo.h" // Constructor -GameLogo::GameLogo(SDL_Renderer *renderer, Screen *screen, Asset *asset, int x, int y) +GameLogo::GameLogo(SDL_Renderer *renderer, Screen *screen, Asset *asset, param_t *param, int x, int y) { // Copia los punteros this->renderer = renderer; this->screen = screen; this->asset = asset; + this->param = param; this->x = x; this->y = y; @@ -203,7 +204,7 @@ void GameLogo::reLoad() int GameLogo::getInitialVerticalDesp() { int despUp = y; - int despDown = GAMECANVAS_HEIGHT - y; + int despDown = param->gameHeight - y; return std::max(despUp, despDown); } \ No newline at end of file diff --git a/source/game_logo.h b/source/game_logo.h index 5870ff6..d549585 100644 --- a/source/game_logo.h +++ b/source/game_logo.h @@ -29,10 +29,12 @@ private: SmartSprite *coffeeBitmap; // Sprite con la palabra COFFEE para la pantalla de titulo SmartSprite *crisisBitmap; // Sprite con la palabra CRISIS para la pantalla de titulo - // Variables - int x; // Posición donde ddibujar a la clase - int y; // Posición donde ddibujar a la clase JA_Sound_t *crashSound; // Sonido con el impacto del título + param_t *param; // Puntero con todos los parametros del programa + + // Variables + int x; // Posición donde dibujar el logo + int y; // Posición donde dibujar el logo enum status_e { @@ -50,7 +52,7 @@ private: int lenght; // Cantidad de desplazamientos a realizar int remaining; // Cantidad de desplazamientos pendientes a realizar int origin; // Valor inicial de la pantalla para dejarla igual tras el desplazamiento - } shake; // Estructura para generar el efecto de agitación + } shake; // Estructura para generar el efecto de agitación // Inicializa las variables void init(); @@ -60,7 +62,7 @@ private: public: // Constructor - GameLogo(SDL_Renderer *renderer, Screen *screen, Asset *asset, int x, int y); + GameLogo(SDL_Renderer *renderer, Screen *screen, Asset *asset, param_t *param, int x, int y); // Destructor ~GameLogo(); diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index a97bd61..ec93341 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -4,7 +4,7 @@ const Uint8 SELF = 0; // Constructor -HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, section_t *section) +HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, options_t *options, section_t *section) { // Copia los punteros this->renderer = renderer; @@ -14,6 +14,7 @@ HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, this->lang = lang; this->section = section; this->options = options; + this->param = param; // Reserva memoria para los punteros eventHandler = new SDL_Event(); @@ -21,14 +22,7 @@ HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer); // Crea un backbuffer para el renderizador - backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); - if (backbuffer == nullptr) - { - if (options->console) - { - std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl; - } - } + backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->gameWidth, param->gameHeight); // Inicializa variables section->name = SELF; @@ -90,7 +84,7 @@ void HiScoreTable::update() void HiScoreTable::render() { // Pinta en pantalla - SDL_Rect window = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT}; + SDL_Rect window = {0, 0, param->gameWidth, param->gameHeight}; const color_t orangeColor = {0xFF, 0x7A, 0x00}; // hay 27 letras - 7 de puntos quedan 20 caracteres 20 - nameLenght 0 numDots @@ -121,11 +115,10 @@ void HiScoreTable::render() const std::string line = names[i] + dots + "0000000"; text->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, (i * spaceBetweenLines) + spaceBetweenHeader, line, 1, orangeColor, 1, shdwTxtColor); } - if ((mode == mhst_manual) && (counter % 50 > 14)) { - text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, GAMECANVAS_HEIGHT - 12, lang->getText(22), 1, orangeColor, 1, shdwTxtColor); + text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, param->gameHeight - 12, lang->getText(22), 1, orangeColor, 1, shdwTxtColor); } // Cambia el destino de renderizado @@ -140,7 +133,7 @@ void HiScoreTable::render() // Establece la ventana del backbuffer if (mode == mhst_auto) { - window.y = std::max(8, GAMECANVAS_HEIGHT - counter + 100); + window.y = std::max(8, param->gameHeight - counter + 100); } else { diff --git a/source/hiscore_table.h b/source/hiscore_table.h index 5e1a4e0..5afcfcf 100644 --- a/source/hiscore_table.h +++ b/source/hiscore_table.h @@ -42,6 +42,7 @@ private: Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa bool manualQuit; // Indica si se quiere salir del modo manual mode_hiScoreTable_e mode; // Modo en el que se van a ejecutar las instrucciones + param_t *param; // Puntero con todos los parametros del programa // Actualiza las variables void update(); @@ -60,7 +61,7 @@ private: public: // Constructor - HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, section_t *section); + HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, options_t *options, section_t *section); // Destructor ~HiScoreTable(); diff --git a/source/instructions.cpp b/source/instructions.cpp index 07d6a3a..2c0967f 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -4,7 +4,7 @@ const Uint8 SELF = 0; // Constructor -Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section) +Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section) { // Copia los punteros this->renderer = renderer; @@ -12,6 +12,7 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, this->asset = asset; this->input = input; this->lang = lang; + this->param = param; this->section = section; // Reserva memoria para los punteros @@ -39,7 +40,7 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer); // Crea un backbuffer para el renderizador - backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); + backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->gameWidth, param->gameHeight); if (backbuffer == nullptr) { std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl; @@ -110,7 +111,7 @@ void Instructions::update() void Instructions::render() { // Pinta en pantalla - SDL_Rect window = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT}; + SDL_Rect window = {0, 0, param->gameWidth, param->gameHeight}; SDL_Rect srcRect = {0, 0, 16, 16}; const color_t orangeColor = {0xFF, 0x7A, 0x00}; @@ -142,7 +143,7 @@ void Instructions::render() if ((mode == m_manual) && (counter % 50 > 14)) { - text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, GAMECANVAS_HEIGHT - 12, lang->getText(22), 1, orangeColor, 1, shdwTxtColor); + text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, param->gameHeight - 12, lang->getText(22), 1, orangeColor, 1, shdwTxtColor); } // Disquito @@ -192,7 +193,7 @@ void Instructions::render() // Establece la ventana del backbuffer if (mode == m_auto) { - window.y = std::max(8, GAMECANVAS_HEIGHT - counter + 100); + window.y = std::max(8, param->gameHeight - counter + 100); } else { diff --git a/source/instructions.h b/source/instructions.h index 7179ce5..ae12c1f 100644 --- a/source/instructions.h +++ b/source/instructions.h @@ -36,6 +36,7 @@ private: Lang *lang; // Objeto para gestionar los textos en diferentes idiomas Text *text; // Objeto para escribir texto section_t *section; // Estado del bucle principal para saber si continua o se sale + param_t *param; // Puntero con todos los parametros del programa // Variables Uint16 counter; // Contador @@ -59,7 +60,7 @@ private: public: // Constructor - Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section); + Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section); // Destructor ~Instructions(); diff --git a/source/intro.cpp b/source/intro.cpp index 579000a..f78fc2c 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -1,7 +1,7 @@ #include "intro.h" // Constructor -Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section) +Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section) { // Copia los punteros this->renderer = renderer; @@ -9,6 +9,7 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, this->lang = lang; this->asset = asset; this->input = input; + this->param = param; this->section = section; // Reserva memoria para los objetos @@ -47,7 +48,7 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, bitmaps[0]->setAccelY(0.0f); bitmaps[0]->setSpriteClip(0, 0, 128, 96); - bitmaps[1]->setPosX(GAMECANVAS_WIDTH); + bitmaps[1]->setPosX(param->gameWidth); bitmaps[1]->setPosY(GAMECANVAS_FIRST_QUARTER_Y - 24); bitmaps[1]->setVelX(-1.0f); bitmaps[1]->setVelY(0.0f); @@ -65,7 +66,7 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, bitmaps[2]->setEnabledCounter(250); bitmaps[3]->setPosX(GAMECANVAS_CENTER_X - 64); - bitmaps[3]->setPosY(GAMECANVAS_HEIGHT); + bitmaps[3]->setPosY(param->gameHeight); bitmaps[3]->setVelX(0.0f); bitmaps[3]->setVelY(-0.7f); bitmaps[3]->setAccelX(0.0f); @@ -80,7 +81,7 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, bitmaps[4]->setAccelY(0.3f); bitmaps[4]->setSpriteClip(0, 192, 128, 96); - bitmaps[5]->setPosX(GAMECANVAS_WIDTH); + bitmaps[5]->setPosX(param->gameWidth); bitmaps[5]->setPosY(GAMECANVAS_FIRST_QUARTER_Y - 24); bitmaps[5]->setVelX(-0.7f); bitmaps[5]->setVelY(0.0f); @@ -94,7 +95,7 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, { Writer *w = new Writer(text); w->setPosX(BLOCK * 0); - w->setPosY(GAMECANVAS_HEIGHT - (BLOCK * 6)); + w->setPosY(param->gameHeight - (BLOCK * 6)); w->setKerning(-1); w->setEnabled(false); w->setEnabledCounter(180); diff --git a/source/intro.h b/source/intro.h index 6520cc1..1748c0f 100644 --- a/source/intro.h +++ b/source/intro.h @@ -31,6 +31,7 @@ private: std::vector texts; // Textos de la intro Text *text; // Textos de la intro section_t *section; // Estado del bucle principal para saber si continua o se sale + param_t *param; // Puntero con todos los parametros del programa // Variables Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa @@ -58,7 +59,7 @@ private: public: // Constructor - Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section); + Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section); // Destructor ~Intro(); diff --git a/source/logo.cpp b/source/logo.cpp index e207f43..b586358 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -2,20 +2,21 @@ #include // Constructor -Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, section_t *section) +Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, param_t *param, section_t *section) { // Copia la dirección de los objetos this->renderer = renderer; this->screen = screen; this->asset = asset; this->input = input; + this->param = param; this->section = section; // Reserva memoria para los punteros eventHandler = new SDL_Event(); jailTexture = new Texture(renderer, asset->get("logo_jailgames.png")); sinceTexture = new Texture(renderer, asset->get("logo_since_1998.png")); - sinceSprite = new Sprite((GAMECANVAS_WIDTH - sinceTexture->getWidth()) / 2, 83 + jailTexture->getHeight() + 5, sinceTexture->getWidth(), sinceTexture->getHeight(), sinceTexture, renderer); + sinceSprite = new Sprite((param->gameWidth - sinceTexture->getWidth()) / 2, 83 + jailTexture->getHeight() + 5, sinceTexture->getWidth(), sinceTexture->getHeight(), sinceTexture, renderer); sinceSprite->setSpriteClip(0, 0, sinceTexture->getWidth(), sinceTexture->getHeight()); sinceTexture->setColor(0, 0, 0); @@ -37,7 +38,7 @@ Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, s { Sprite *temp = new Sprite(0, i, jailTexture->getWidth(), 1, jailTexture, renderer); temp->setSpriteClip(0, i, jailTexture->getWidth(), 1); - const int posX = (i % 2 == 0) ? GAMECANVAS_WIDTH + (i * 3) : -jailTexture->getWidth() - (i * 3); + const int posX = (i % 2 == 0) ? param->gameWidth + (i * 3) : -jailTexture->getWidth() - (i * 3); temp->setPosX(posX); temp->setPosY(dest.y + i); jailSprite.push_back(temp); diff --git a/source/logo.h b/source/logo.h index e45daed..f4dab3d 100644 --- a/source/logo.h +++ b/source/logo.h @@ -27,6 +27,7 @@ private: std::vector jailSprite; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES Sprite *sinceSprite; // Sprite para manejar la sinceTexture section_t *section; // Estado del bucle principal para saber si continua o se sale + param_t *param; // Puntero con todos los parametros del programa // Variables std::vector color; // Vector con los colores para el fade @@ -59,7 +60,7 @@ private: public: // Constructor - Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, section_t *section); + Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, param_t *param, section_t *section); // Destructor ~Logo(); diff --git a/source/title.cpp b/source/title.cpp index d2480e3..22b3770 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -1,7 +1,7 @@ #include "title.h" // Constructor -Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t *section) +Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, param_t *param, section_t *section) { // Copia las direcciones de los punteros y objetos this->renderer = renderer; @@ -10,11 +10,12 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, this->asset = asset; this->options = options; this->lang = lang; + this->param = param; this->section = section; // Reserva memoria y crea los objetos eventHandler = new SDL_Event(); - fade = new Fade(renderer); + fade = new Fade(renderer, param); text1 = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer); text2 = new Text(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer); @@ -22,7 +23,7 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, miniLogoTexture = new Texture(renderer, asset->get("logo_jailgames_mini.png")); miniLogoSprite = new Sprite(GAMECANVAS_CENTER_X - miniLogoTexture->getWidth() / 2, 0, miniLogoTexture->getWidth(), miniLogoTexture->getHeight(), miniLogoTexture, renderer); - backgroundObj = new Background(renderer, screen, asset); + backgroundObj = new Background(renderer, screen, asset, param); backgroundObj->setSrcDest(windowArea); backgroundObj->setDstDest(windowArea); backgroundObj->setCloudsSpeed(-0.5f); @@ -31,7 +32,7 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, tiledbg = new Tiledbg(renderer, screen, asset, {0, 0, param->gameWidth, param->gameHeight}); - gameLogo = new GameLogo(renderer, screen, asset, GAMECANVAS_CENTER_X, GAMECANVAS_FIRST_QUARTER_Y + 20); + gameLogo = new GameLogo(renderer, screen, asset, param, GAMECANVAS_CENTER_X, GAMECANVAS_FIRST_QUARTER_Y + 20); gameLogo->enable(); // Musicas @@ -355,7 +356,7 @@ void Title::run() // Ejecuta la parte donde se muestran las instrucciones void Title::runInstructions(mode_e mode) { - instructions = new Instructions(renderer, screen, asset, input, lang, section); + instructions = new Instructions(renderer, screen, asset, input, lang, param, section); instructions->run(mode); delete instructions; } @@ -363,7 +364,7 @@ void Title::runInstructions(mode_e mode) // Ejecuta la parte donde se muestra la tabla de puntuaciones void Title::runHiScoreTable(mode_hiScoreTable_e mode) { - hiScoreTable = new HiScoreTable(renderer, screen, asset, input, lang, options, section); + hiScoreTable = new HiScoreTable(renderer, screen, asset, input, lang, param, options, section); hiScoreTable->run(mode); delete hiScoreTable; } @@ -371,7 +372,7 @@ void Title::runHiScoreTable(mode_hiScoreTable_e mode) // Ejecuta el juego en modo demo void Title::runDemoGame() { - demoGame = new Game(1, 0, renderer, screen, asset, lang, input, true, options, section); + demoGame = new Game(1, 0, renderer, screen, asset, lang, input, true, param, options, section); demoGame->run(); delete demoGame; } diff --git a/source/title.h b/source/title.h index fb4c9a7..eeaa264 100644 --- a/source/title.h +++ b/source/title.h @@ -58,15 +58,17 @@ private: Text *text2; // Objeto de texto para poder escribir textos en pantalla Fade *fade; // Objeto para realizar fundidos en pantalla + JA_Music_t *titleMusic; // Musica para el titulo + // Variable - JA_Music_t *titleMusic; // Musica para el titulo int counter; // Temporizador para la pantalla de titulo Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa bool demo; // Indica si el modo demo estará activo section_t nextSection; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint8 postFade; // Opción a realizar cuando termina el fundido - struct options_t *options; // Variable con todas las variables de las opciones del programa + options_t *options; // Variable con todas las variables de las opciones del programa + param_t *param; // Puntero con todos los parametros del programa options_t optionsPrevious; // Variable de respaldo para las opciones std::vector availableInputDevices; // Vector con todos los metodos de control disponibles std::vector deviceIndex; // Indice para el jugador [i] del vector de dispositivos de entrada disponibles @@ -109,7 +111,7 @@ private: public: // Constructor - Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t *section); + Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, param_t *param, section_t *section); // Destructor ~Title();