From 46b41757b2cbda873478d458b8095901f2521458 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 27 Sep 2024 17:42:25 +0200 Subject: [PATCH] =?UTF-8?q?Convertit=20"param"=20a=20variable=20global=20e?= =?UTF-8?q?n=20lloc=20de=20anar=20marejant=20amb=20punterets=20i=20passant?= =?UTF-8?q?=208.000.000=20de=20par=C3=A0metres?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/background.cpp | 8 +- source/background.h | 6 +- source/balloon.cpp | 38 +++--- source/balloon.h | 3 +- source/define_buttons.cpp | 8 +- source/define_buttons.h | 3 +- source/director.cpp | 33 +++--- source/director.h | 3 +- source/enemy_formations.cpp | 18 +-- source/enemy_formations.h | 3 +- source/fade.cpp | 32 ++--- source/fade.h | 3 +- source/game.cpp | 64 +++++----- source/game.h | 3 +- source/game_logo.cpp | 8 +- source/game_logo.h | 3 +- source/hiscore_table.cpp | 24 ++-- source/hiscore_table.h | 3 +- source/instructions.cpp | 58 ++++----- source/instructions.h | 3 +- source/intro.cpp | 30 ++--- source/intro.h | 3 +- source/logo.cpp | 12 +- source/logo.h | 3 +- source/{load_param.cpp => param.cpp} | 169 ++++++++++++++------------- source/{load_param.h => param.h} | 4 +- source/title.cpp | 24 ++-- source/title.h | 3 +- 28 files changed, 279 insertions(+), 293 deletions(-) rename source/{load_param.cpp => param.cpp} (51%) rename source/{load_param.h => param.h} (69%) diff --git a/source/background.cpp b/source/background.cpp index 043d711..832069a 100644 --- a/source/background.cpp +++ b/source/background.cpp @@ -1,12 +1,12 @@ #include "background.h" +#include "param.h" // Constructor -Background::Background(SDL_Renderer *renderer, Asset *asset, param_t *param) +Background::Background(SDL_Renderer *renderer, Asset *asset) { // Copia los punteros this->renderer = renderer; this->asset = asset; - this->param = param; // Carga las texturas buildingsTexture = new Texture(renderer, asset->get("game_buildings.png")); @@ -27,8 +27,8 @@ Background::Background(SDL_Renderer *renderer, Asset *asset, param_t *param) dstRect = {0, 0, 320, 240}; base = rect.h; - color = {param->background.attenuateColor.r, param->background.attenuateColor.g, param->background.attenuateColor.b}; - alphaColorText = alphaColorTextTemp = param->background.attenuateAlpha; + color = {param.background.attenuateColor.r, param.background.attenuateColor.g, param.background.attenuateColor.b}; + alphaColorText = alphaColorTextTemp = param.background.attenuateAlpha; gradientRect[0] = {0, 0, rect.w, rect.h}; gradientRect[1] = {rect.w, 0, rect.w, rect.h}; diff --git a/source/background.h b/source/background.h index 7f2aed7..7038658 100644 --- a/source/background.h +++ b/source/background.h @@ -1,9 +1,9 @@ #pragma once #include -#include "common/screen.h" #include "common/asset.h" #include "common/movingsprite.h" +#include "common/utils.h" /* Esta clase es la encargada de dibujar el fondo que aparece durante la sección @@ -68,8 +68,6 @@ private: SDL_Texture *canvas; // Textura para componer el fondo SDL_Texture *colorTexture; // Textura para atenuar el fondo - param_t *param; // Puntero con todos los parametros del programa - // Variables SDL_Rect gradientRect[4]; // Vector con las coordenadas de los 4 degradados para el cielo SDL_Rect topCloudsRect[4]; // Vector con las coordenadas de los 4 nubes de arriba @@ -107,7 +105,7 @@ private: public: // Constructor - Background(SDL_Renderer *renderer, Asset *asset, param_t *param); + Background(SDL_Renderer *renderer, Asset *asset); // Destructor ~Background(); diff --git a/source/balloon.cpp b/source/balloon.cpp index c8f1a53..7c842f5 100644 --- a/source/balloon.cpp +++ b/source/balloon.cpp @@ -1,10 +1,10 @@ -#include "const.h" #include "balloon.h" +#include "const.h" +#include "param.h" // Constructor -Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector *animation, param_t *param) +Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector *animation) { - this->param = param; sprite = new AnimatedSprite(texture, "", animation); disable(); @@ -23,8 +23,8 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c this->velX = velx; velY = 0; maxVelY = 3.0f; - gravity = param->balloon1.grav; - defaultVelY = param->balloon1.vel; + gravity = param.balloon1.grav; + defaultVelY = param.balloon1.vel; // Puntos que da el globo al ser destruido score = BALLOON_SCORE_1; @@ -45,8 +45,8 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c this->velX = velx; velY = 0; maxVelY = 3.0f; - gravity = param->balloon2.grav; - defaultVelY = param->balloon2.vel; + gravity = param.balloon2.grav; + defaultVelY = param.balloon2.vel; // Puntos que da el globo al ser destruido score = BALLOON_SCORE_2; @@ -67,8 +67,8 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c this->velX = velx; velY = 0; maxVelY = 3.0f; - gravity = param->balloon3.grav; - defaultVelY = param->balloon3.vel; + gravity = param.balloon3.grav; + defaultVelY = param.balloon3.vel; // Puntos que da el globo al ser destruido score = BALLOON_SCORE_3; @@ -89,8 +89,8 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c this->velX = velx; velY = 0; maxVelY = 3.0f; - gravity = param->balloon4.grav; - defaultVelY = param->balloon4.vel; + gravity = param.balloon4.grav; + defaultVelY = param.balloon4.vel; // Puntos que da el globo al ser destruido score = BALLOON_SCORE_4; @@ -199,8 +199,8 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c this->velX = velx; velY = 0; maxVelY = 3.0f; - gravity = param->balloon4.grav; - defaultVelY = param->balloon4.vel; + gravity = param.balloon4.grav; + defaultVelY = param.balloon4.vel; // Puntos que da el globo al ser destruido score = 0; @@ -285,9 +285,9 @@ void Balloon::allignTo(int x) { posX = PLAY_AREA_LEFT + 1; } - else if ((posX + width) > param->game.playArea.rect.w) + else if ((posX + width) > param.game.playArea.rect.w) { - posX = float(param->game.playArea.rect.w - width - 1); + posX = float(param.game.playArea.rect.w - width - 1); } // Posición X,Y del sprite @@ -347,7 +347,7 @@ void Balloon::move() posX += (velX * speed); // Si queda fuera de pantalla, corregimos su posición y cambiamos su sentido - if ((posX < PLAY_AREA_LEFT) || (posX + width > param->game.playArea.rect.w)) + if ((posX < PLAY_AREA_LEFT) || (posX + width > param.game.playArea.rect.w)) { // Corrige posición posX -= (velX * speed); @@ -385,10 +385,10 @@ void Balloon::move() } // Si el globo se sale por la parte inferior - if (posY + height > param->game.playArea.rect.h) + if (posY + height > param.game.playArea.rect.h) { // Corrige - posY = param->game.playArea.rect.h - height; + posY = param.game.playArea.rect.h - height; // Invierte colocando una velocidad por defecto velY = -defaultVelY; @@ -508,7 +508,7 @@ void Balloon::updateState() posX += velX; // Comprueba no se salga por los laterales - if ((posX < PLAY_AREA_LEFT) || (posX > (param->game.playArea.rect.w - width))) + if ((posX < PLAY_AREA_LEFT) || (posX > (param.game.playArea.rect.w - width))) { // Corrige y cambia el sentido de la velocidad posX -= velX; diff --git a/source/balloon.h b/source/balloon.h index 54af3a9..5c5e563 100644 --- a/source/balloon.h +++ b/source/balloon.h @@ -85,7 +85,6 @@ private: // Objetos y punteros AnimatedSprite *sprite; // Sprite del objeto globo - param_t *param; // Puntero con todos los parametros del programa // Variables float posX; // Posición en el eje X @@ -140,7 +139,7 @@ private: public: // Constructor - Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector *animation, param_t *param); + Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector *animation); // Destructor ~Balloon(); diff --git a/source/define_buttons.cpp b/source/define_buttons.cpp index 893f188..863d477 100644 --- a/source/define_buttons.cpp +++ b/source/define_buttons.cpp @@ -1,19 +1,19 @@ #include "define_buttons.h" +#include "param.h" // Constructor -DefineButtons::DefineButtons(Input *input, Text *text, param_t *param, options_t *options, section_t *section) +DefineButtons::DefineButtons(Input *input, Text *text, options_t *options, section_t *section) { // Copia punteros a los objetos this->input = input; this->text = text; - this->param = param; this->options = options; this->section = section; // Inicializa variables enabled = false; - x = param->game.width / 2; - y = param->title.pressStartPosition; + x = param.game.width / 2; + y = param.title.pressStartPosition; indexController = 0; indexButton = 0; diff --git a/source/define_buttons.h b/source/define_buttons.h index b1853ee..5ed52f9 100644 --- a/source/define_buttons.h +++ b/source/define_buttons.h @@ -23,7 +23,6 @@ private: // Variables options_t *options; // Opciones del programa - param_t *param; // Puntero con todos los parametros del programa section_t *section; // Indicador para el bucle del titulo bool enabled; // Indica si el objeto está habilitado int x; // Posición donde dibujar el texto @@ -47,7 +46,7 @@ private: public: // Constructor - DefineButtons(Input *input, Text *text, param_t *param, options_t *options, section_t *section); + DefineButtons(Input *input, Text *text, options_t *options, section_t *section); // Destructor ~DefineButtons(); diff --git a/source/director.cpp b/source/director.cpp index 0a3957f..451ad0d 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -95,7 +95,6 @@ Director::~Director() delete input; delete screen; delete options; - delete param; delete section; deleteSounds(); @@ -247,7 +246,7 @@ bool Director::initSDL() SDL_DisplayMode DM; SDL_GetCurrentDisplayMode(0, &DM); std::cout << "\nCurrent display mode: " + std::to_string(DM.w) + "x" + std::to_string(DM.h) + " @ " + std::to_string(DM.refresh_rate) + "Hz" << std::endl; - std::cout << "Window resolution : " + std::to_string(param->game.width) + "x" + std::to_string(param->game.height) + " x" + std::to_string(options->video.window.size) << std::endl; + std::cout << "Window resolution : " + std::to_string(param.game.width) + "x" + std::to_string(param.game.height) + " x" + std::to_string(options->video.window.size) << std::endl; } // Establece el filtro de la textura @@ -268,7 +267,7 @@ bool Director::initSDL() } #endif // Crea la ventana - window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, param->game.width * options->video.window.size, param->game.height * options->video.window.size, SDL_WINDOW_HIDDEN); + window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, param.game.width * options->video.window.size, param.game.height * options->video.window.size, SDL_WINDOW_HIDDEN); if (window == nullptr) { if (options->console) @@ -305,7 +304,7 @@ bool Director::initSDL() SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF); // Establece el tamaño del buffer de renderizado - SDL_RenderSetLogicalSize(renderer, param->game.width, param->game.height); + SDL_RenderSetLogicalSize(renderer, param.game.width, param.game.height); // Establece el modo de mezcla SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); @@ -467,15 +466,13 @@ bool Director::setFileList() // Carga los parametros para configurar el juego void Director::loadParams(std::string filepath) { - param = new param_t; - - loadParamsFromFile(param, filepath); + loadParamsFromFile(filepath); // Modifica las opciones desde el fichero de parametros - options->video.window.width = options->video.window.size * param->game.width; - options->video.window.height = options->video.window.size * param->game.height; - options->video.gameWidth = param->game.width; - options->video.gameHeight = param->game.height; + options->video.window.width = options->video.window.size * param.game.width; + options->video.window.height = options->video.window.size * param.game.height; + options->video.gameWidth = param.game.width; + options->video.gameHeight = param.game.height; } // Inicializa las opciones del programa @@ -886,7 +883,7 @@ void Director::deleteMusics() // Ejecuta la sección con el logo void Director::runLogo() { - logo = new Logo(screen, asset, input, options, param, section); + logo = new Logo(screen, asset, input, options, section); logo->run(); delete logo; } @@ -894,7 +891,7 @@ void Director::runLogo() // Ejecuta la sección con la secuencia de introducción void Director::runIntro() { - intro = new Intro(screen, asset, input, options, param, section, getMusic(musics, "intro.ogg")); + intro = new Intro(screen, asset, input, options, section, getMusic(musics, "intro.ogg")); intro->run(); delete intro; } @@ -902,7 +899,7 @@ void Director::runIntro() // Ejecuta la sección con el titulo del juego void Director::runTitle() { - title = new Title(screen, asset, input, options, param, section, getMusic(musics, "title.ogg")); + title = new Title(screen, asset, input, options, section, getMusic(musics, "title.ogg")); title->run(); delete title; } @@ -912,7 +909,7 @@ void Director::runGame() { const int playerID = section->options; const int currentStage = 0; - game = new Game(playerID, currentStage, GAME_MODE_DEMO_OFF, screen, asset, input, options, param, section, getMusic(musics, "playing.ogg")); + game = new Game(playerID, currentStage, GAME_MODE_DEMO_OFF, screen, asset, input, options, section, getMusic(musics, "playing.ogg")); game->run(); delete game; } @@ -920,7 +917,7 @@ void Director::runGame() // Ejecuta la sección donde se muestran las instrucciones void Director::runInstructions() { - instructions = new Instructions(screen, asset, input, options, param, section, getMusic(musics, "title.ogg")); + instructions = new Instructions(screen, asset, input, options, section, getMusic(musics, "title.ogg")); instructions->run(); delete instructions; } @@ -928,7 +925,7 @@ void Director::runInstructions() // Ejecuta la sección donde se muestra la tabla de puntuaciones void Director::runHiScoreTable() { - hiScoreTable = new HiScoreTable(screen, asset, input, options, param, section, getMusic(musics, "title.ogg")); + hiScoreTable = new HiScoreTable(screen, asset, input, options, section, getMusic(musics, "title.ogg")); hiScoreTable->run(); delete hiScoreTable; } @@ -938,7 +935,7 @@ void Director::runDemoGame() { const int playerID = (rand() % 2) + 1; const int currentStage = 0; - demoGame = new Game(playerID, currentStage, GAME_MODE_DEMO_ON, screen, asset, input, options, param, section, nullptr); + demoGame = new Game(playerID, currentStage, GAME_MODE_DEMO_ON, screen, asset, input, options, section, nullptr); demoGame->run(); delete demoGame; } diff --git a/source/director.h b/source/director.h index 08d09a4..0e71a83 100644 --- a/source/director.h +++ b/source/director.h @@ -16,7 +16,7 @@ #include "logo.h" #include "player.h" #include "title.h" -#include "load_param.h" +#include "param.h" #include "manage_hiscore_table.h" // Textos @@ -42,7 +42,6 @@ private: // Variables options_t *options; // 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 std::string paramFileArgument; // Argumento para gestionar el fichero con los parametros del programa diff --git a/source/enemy_formations.cpp b/source/enemy_formations.cpp index 758caa9..f7e831b 100644 --- a/source/enemy_formations.cpp +++ b/source/enemy_formations.cpp @@ -1,9 +1,9 @@ #include "enemy_formations.h" +#include "param.h" // Constructor -EnemyFormations::EnemyFormations(param_t *param) +EnemyFormations::EnemyFormations() { - this->param = param; initEnemyFormations(); initEnemyPools(); initGameStages(); @@ -19,20 +19,20 @@ void EnemyFormations::initEnemyFormations() { const int y4 = - BLOCK; const int x4_0 = PLAY_AREA_LEFT; - const int x4_100 = param->game.playArea.rect.w - BALLOON_WIDTH_4; + const int x4_100 = param.game.playArea.rect.w - BALLOON_WIDTH_4; const int y3 = - BLOCK; const int x3_0 = PLAY_AREA_LEFT; - const int x3_100 = param->game.playArea.rect.w - BALLOON_WIDTH_3; + const int x3_100 = param.game.playArea.rect.w - BALLOON_WIDTH_3; const int y2 = - BLOCK; const int x2_0 = PLAY_AREA_LEFT; - const int x2_100 = param->game.playArea.rect.w - BALLOON_WIDTH_2; + const int x2_100 = param.game.playArea.rect.w - BALLOON_WIDTH_2; const int y1 = - BLOCK; const int x1_0 = PLAY_AREA_LEFT; - const int x1_50 = param->game.playArea.centerX - (BALLOON_WIDTH_1 / 2); - const int x1_100 = param->game.playArea.rect.w - BALLOON_WIDTH_1; + const int x1_50 = param.game.playArea.centerX - (BALLOON_WIDTH_1 / 2); + const int x1_100 = param.game.playArea.rect.w - BALLOON_WIDTH_1; // Inicializa a cero las variables for (int i = 0; i < NUMBER_OF_ENEMY_FORMATIONS; i++) @@ -70,11 +70,11 @@ void EnemyFormations::initEnemyFormations() // #01 - Dos enemigos BALLOON4 uno a cada cuarto. Ambos van hacia el centro j = 1; enemyFormation[j].numberOfEnemies = 2; - incX = param->game.playArea.centerX; + incX = param.game.playArea.centerX; incTime = 0; for (int i = 0; i < enemyFormation[j].numberOfEnemies; i++) { - enemyFormation[j].init[i].x = param->game.playArea.firstQuarterX - (BALLOON_WIDTH_4 / 2) + (i * incX); + enemyFormation[j].init[i].x = param.game.playArea.firstQuarterX - (BALLOON_WIDTH_4 / 2) + (i * incX); enemyFormation[j].init[i].y = y4; enemyFormation[j].init[i].velX = BALLOON_VELX_NEGATIVE * (((i % 2) * 2) - 1); enemyFormation[j].init[i].kind = BALLOON_4; diff --git a/source/enemy_formations.h b/source/enemy_formations.h index 6c74639..7b1e521 100644 --- a/source/enemy_formations.h +++ b/source/enemy_formations.h @@ -46,7 +46,6 @@ private: stage_t stage[10]; // Variable con los datos de cada pantalla 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 - param_t *param; // Puntero con todos los parametros del programa // Inicializa las formaciones enemigas void initEnemyFormations(); @@ -59,7 +58,7 @@ private: public: // Constructor - EnemyFormations(param_t *param); + EnemyFormations(); // Destructor ~EnemyFormations(); diff --git a/source/fade.cpp b/source/fade.cpp index fb84402..4d60c46 100644 --- a/source/fade.cpp +++ b/source/fade.cpp @@ -1,16 +1,16 @@ #include "fade.h" #include "const.h" +#include "param.h" #include // Constructor -Fade::Fade(SDL_Renderer *renderer, param_t *param) +Fade::Fade(SDL_Renderer *renderer) { // Copia punteros y objetos this->renderer = renderer; - this->param = param; // Crea la textura donde dibujar el fade - backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->game.width, param->game.height); + backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height); SDL_SetTextureBlendMode(backbuffer, SDL_BLENDMODE_BLEND); // Inicializa las variables @@ -37,10 +37,10 @@ void Fade::init() b = 0; postDuration = 20; postCounter = 0; - numSquaresWidth = param->fade.numSquaresWidth; - numSquaresHeight = param->fade.numSquaresHeight; - fadeRandomSquaresDelay = param->fade.randomSquaresDelay; - fadeRandomSquaresMult = param->fade.randomSquaresMult; + numSquaresWidth = param.fade.numSquaresWidth; + numSquaresHeight = param.fade.numSquaresHeight; + fadeRandomSquaresDelay = param.fade.randomSquaresDelay; + fadeRandomSquaresMult = param.fade.randomSquaresMult; } // Resetea algunas variables para volver a hacer el fade sin perder ciertos parametros @@ -97,7 +97,7 @@ void Fade::update() for (int i = 0; i < counter; i++) { rect1.h = rect2.h = i * 4; - rect2.y = param->game.height - (i * 4); + rect2.y = param.game.height - (i * 4); SDL_RenderFillRect(renderer, &rect1); SDL_RenderFillRect(renderer, &rect2); @@ -107,7 +107,7 @@ void Fade::update() SDL_SetRenderTarget(renderer, temp); // Comprueba si ha terminado - if ((counter * 4) > param->game.height) + if ((counter * 4) > param.game.height) { finished = true; a = 255; @@ -152,7 +152,7 @@ void Fade::update() case FADE_VENETIAN: { // Counter debe ir de 0 a 150 - if (square.back().h < param->fade.venetianSize) + if (square.back().h < param.fade.venetianSize) { // Dibuja sobre el backbuffer SDL_Texture *temp = SDL_GetRenderTarget(renderer); @@ -221,15 +221,15 @@ void Fade::activate() case FADE_CENTER: { - rect1 = {0, 0, param->game.width, 0}; - rect2 = {0, 0, param->game.width, 0}; + rect1 = {0, 0, param.game.width, 0}; + rect2 = {0, 0, param.game.width, 0}; a = 64; break; } case FADE_RANDOM_SQUARE: { - rect1 = {0, 0, param->game.width / numSquaresWidth, param->game.height / numSquaresHeight}; + rect1 = {0, 0, param.game.width / numSquaresWidth, param.game.height / numSquaresHeight}; square.clear(); // Añade los cuadrados al vector @@ -267,16 +267,16 @@ void Fade::activate() case FADE_VENETIAN: { - rect1 = {0, 0, param->game.width, 0}; + rect1 = {0, 0, param.game.width, 0}; square.clear(); a = 255; // Añade los cuadrados al vector - const int max = param->game.height / param->fade.venetianSize; + const int max = param.game.height / param.fade.venetianSize; for (int i = 0; i < max; ++i) { - rect1.y = i * param->fade.venetianSize; + rect1.y = i * param.fade.venetianSize; square.push_back(rect1); } diff --git a/source/fade.h b/source/fade.h index 039a0f1..b8da925 100644 --- a/source/fade.h +++ b/source/fade.h @@ -33,7 +33,6 @@ private: SDL_Rect rect2; // Rectangulo usado para crear los efectos de transición int numSquaresWidth; // Cantidad total de cuadraditos en horizontal para el FADE_RANDOM_SQUARE int numSquaresHeight; // Cantidad total de cuadraditos en vertical para el FADE_RANDOM_SQUARE - param_t *param; // Puntero con todos los parametros del programa std::vector square; // Vector con los indices de los cuadrados para el FADE_RANDOM_SQUARE int fadeRandomSquaresDelay; // Duración entre cada pintado de cuadrados int fadeRandomSquaresMult; // Cantidad de cuadrados que se pintaran cada vez @@ -48,7 +47,7 @@ private: public: // Constructor - Fade(SDL_Renderer *renderer, param_t *param); + Fade(SDL_Renderer *renderer); // Destructor ~Fade(); diff --git a/source/game.cpp b/source/game.cpp index ab4e262..e57103f 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -1,15 +1,15 @@ #include "game.h" +#include "param.h" #define GAME_OVER_COUNTER 350 // Constructor -Game::Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *asset, Input *input, options_t *options, param_t *param, section_t *section, JA_Music_t *music) +Game::Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music) { // Copia los punteros this->screen = screen; this->asset = asset; this->input = input; - this->param = param; this->options = options; this->section = section; this->music = music; @@ -22,12 +22,12 @@ Game::Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *ass difficulty = options->game.difficulty; // Crea los objetos - fade = new Fade(renderer, param); + fade = new Fade(renderer); eventHandler = new SDL_Event(); scoreboard = new Scoreboard(renderer, asset, options); - background = new Background(renderer, asset, param); + background = new Background(renderer, asset); explosions = new Explosions(); - enemyFormations = new EnemyFormations(param); + enemyFormations = new EnemyFormations(); // Carga los recursos loadMedia(); @@ -41,7 +41,7 @@ Game::Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *ass loadDemoFile(asset->get("demo2.bin"), &this->demo.dataFile[index2]); } - background->setPos(param->game.playArea.rect); + background->setPos(param.game.playArea.rect); n1000Sprite = new SmartSprite(gameTextTexture); n2500Sprite = new SmartSprite(gameTextTexture); @@ -52,7 +52,7 @@ Game::Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *ass explosions->addTexture(3, explosionsTextures[2], explosionsAnimations[2]); explosions->addTexture(4, explosionsTextures[3], explosionsAnimations[3]); - canvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->game.playArea.rect.w, param->game.playArea.rect.h); + canvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.playArea.rect.w, param.game.playArea.rect.h); SDL_SetTextureBlendMode(canvas, SDL_BLENDMODE_BLEND); // Inicializa las variables necesarias para la sección 'Game' @@ -107,14 +107,14 @@ void Game::init(int playerID) players.clear(); // Crea los dos jugadores - Player *player1 = new Player(1, (param->game.playArea.firstQuarterX * ((0 * 2) + 1)) - 11, param->game.playArea.rect.h - 30, ¶m->game.playArea.rect, playerTextures[0], playerAnimations); + Player *player1 = new Player(1, (param.game.playArea.firstQuarterX * ((0 * 2) + 1)) - 11, param.game.playArea.rect.h - 30, ¶m.game.playArea.rect, playerTextures[0], playerAnimations); player1->setScoreBoardPanel(SCOREBOARD_LEFT_PANEL); player1->setName(lang::getText(53)); const int controller1 = getController(player1->getId()); player1->setController(controller1); players.push_back(player1); - Player *player2 = new Player(2, (param->game.playArea.firstQuarterX * ((1 * 2) + 1)) - 11, param->game.playArea.rect.h - 30, ¶m->game.playArea.rect, playerTextures[1], playerAnimations); + Player *player2 = new Player(2, (param.game.playArea.firstQuarterX * ((1 * 2) + 1)) - 11, param.game.playArea.rect.h - 30, ¶m.game.playArea.rect, playerTextures[1], playerAnimations); player2->setScoreBoardPanel(SCOREBOARD_RIGHT_PANEL); player2->setName(lang::getText(54)); const int controller2 = getController(player2->getId()); @@ -159,7 +159,7 @@ void Game::init(int playerID) } // Variables para el marcador - scoreboard->setPos({param->scoreboard.x, param->scoreboard.y, param->scoreboard.w, param->scoreboard.h}); + scoreboard->setPos({param.scoreboard.x, param.scoreboard.y, param.scoreboard.w, param.scoreboard.h}); for (auto player : players) { scoreboard->setName(player->getScoreBoardPanel(), player->getName()); @@ -269,7 +269,7 @@ void Game::init(int playerID) // Inicializa el objeto para el fundido fade->setColor(fadeColor.r, fadeColor.g, fadeColor.b); - fade->setPost(param->fade.postDuration); + fade->setPost(param.fade.postDuration); fade->setType(FADE_VENETIAN); // Con los globos creados, calcula el nivel de amenaza @@ -977,7 +977,7 @@ void Game::renderBalloons() int Game::createBalloon(float x, int y, int kind, float velx, float speed, int creationtimer) { const int index = (kind - 1) % 4; - Balloon *b = new Balloon(x, y, kind, velx, speed, creationtimer, balloonTextures[index], balloonAnimations[index], param); + Balloon *b = new Balloon(x, y, kind, velx, speed, creationtimer, balloonTextures[index], balloonAnimations[index]); balloons.push_back(b); return (int)(balloons.size() - 1); } @@ -989,8 +989,8 @@ void Game::createPowerBall() const int posY = -BLOCK; const int left = PLAY_AREA_LEFT; - const int center = param->game.playArea.centerX - (BALLOON_WIDTH_4 / 2); - const int right = param->game.playArea.rect.w - BALLOON_WIDTH_4; + const int center = param.game.playArea.centerX - (BALLOON_WIDTH_4 / 2); + const int right = param.game.playArea.rect.w - BALLOON_WIDTH_4; const float vpos = BALLOON_VELX_POSITIVE; const float vneg = BALLOON_VELX_NEGATIVE; @@ -999,7 +999,7 @@ void Game::createPowerBall() const int x[values] = {left, left, center, center, right, right}; const float vx[values] = {vpos, vpos, vpos, vneg, vneg, vneg}; - Balloon *b = new Balloon(x[luck], posY, POWER_BALL, vx[luck], enemySpeed, 300, balloonTextures[4], balloonAnimations[4], param); + Balloon *b = new Balloon(x[luck], posY, POWER_BALL, vx[luck], enemySpeed, 300, balloonTextures[4], balloonAnimations[4]); balloons.push_back(b); powerBallEnabled = true; @@ -1480,7 +1480,7 @@ void Game::renderBullets() // Crea un objeto bala void Game::createBullet(int x, int y, int kind, bool poweredUp, int owner) { - Bullet *b = new Bullet(x, y, kind, poweredUp, owner, &(param->game.playArea.rect), bulletTexture); + Bullet *b = new Bullet(x, y, kind, poweredUp, owner, &(param.game.playArea.rect), bulletTexture); bullets.push_back(b); } @@ -1605,7 +1605,7 @@ int Game::dropItem() // Crea un objeto item void Game::createItem(int kind, float x, float y) { - Item *item = new Item(kind, x, y, &(param->game.playArea.rect), itemTextures[kind - 1], itemAnimations[kind - 1]); + Item *item = new Item(kind, x, y, &(param.game.playArea.rect), itemTextures[kind - 1], itemAnimations[kind - 1]); items.push_back(item); } @@ -1665,17 +1665,17 @@ void Game::throwCoffee(int x, int y) ss->setPosX(x - 8); ss->setPosY(y - 8); - ss->setWidth(param->game.itemSize); - ss->setHeight(param->game.itemSize); + ss->setWidth(param.game.itemSize); + ss->setHeight(param.game.itemSize); ss->setVelX(-1.0f + ((rand() % 5) * 0.5f)); ss->setVelY(-4.0f); ss->setAccelX(0.0f); ss->setAccelY(0.2f); ss->setDestX(x + (ss->getVelX() * 50)); - ss->setDestY(param->game.height + 1); + ss->setDestY(param.game.height + 1); ss->setEnabled(true); ss->setEnabledCounter(1); - ss->setSpriteClip(0, param->game.itemSize, param->game.itemSize, param->game.itemSize); + ss->setSpriteClip(0, param.game.itemSize, param.game.itemSize, param.game.itemSize); ss->setRotate(true); ss->setRotateSpeed(10); ss->setRotateAmount(90.0); @@ -1995,7 +1995,7 @@ void Game::render() screen->start(); // Copia la textura con la zona de juego a la pantalla - SDL_RenderCopy(renderer, canvas, nullptr, ¶m->game.playArea.rect); + SDL_RenderCopy(renderer, canvas, nullptr, ¶m.game.playArea.rect); // Dibuja el marcador scoreboard->render(); @@ -2283,7 +2283,7 @@ void Game::renderMessages() // GetReady if ((counter < STAGE_COUNTER) && (!demo.enabled)) { - textNokiaBig2->write((int)getReadyBitmapPath[counter], param->game.playArea.centerY - 8, lang::getText(75), -2); + textNokiaBig2->write((int)getReadyBitmapPath[counter], param.game.playArea.centerY - 8, lang::getText(75), -2); } // Time Stopped @@ -2291,7 +2291,7 @@ void Game::renderMessages() { if ((timeStoppedCounter > 100) || (timeStoppedCounter % 10 > 4)) { - textNokia2->writeDX(TXT_CENTER, param->game.playArea.centerX, param->game.playArea.firstQuarterY, lang::getText(36) + std::to_string(timeStoppedCounter / 10), -1, noColor, 1, shdwTxtColor); + textNokia2->writeDX(TXT_CENTER, param.game.playArea.centerX, param.game.playArea.firstQuarterY, lang::getText(36) + std::to_string(timeStoppedCounter / 10), -1, noColor, 1, shdwTxtColor); } if (timeStoppedCounter > 100) @@ -2329,13 +2329,13 @@ void Game::renderMessages() if (!gameCompleted) { // Escribe el número de fases restantes - textNokiaBig2->writeDX(TXT_CENTER, param->game.playArea.centerX, stageBitmapPath[stageBitmapCounter], text, -2, noColor, 2, shdwTxtColor); + textNokiaBig2->writeDX(TXT_CENTER, param.game.playArea.centerX, stageBitmapPath[stageBitmapCounter], text, -2, noColor, 2, shdwTxtColor); } else { // Escribe el texto de juego completado text = lang::getText(50); - textNokiaBig2->writeDX(TXT_CENTER, param->game.playArea.centerX, stageBitmapPath[stageBitmapCounter], text, -2, noColor, 1, shdwTxtColor); - textNokia2->writeDX(TXT_CENTER, param->game.playArea.centerX, stageBitmapPath[stageBitmapCounter] + textNokiaBig2->getCharacterSize() + 2, lang::getText(76), -1, noColor, 1, shdwTxtColor); + textNokiaBig2->writeDX(TXT_CENTER, param.game.playArea.centerX, stageBitmapPath[stageBitmapCounter], text, -2, noColor, 1, shdwTxtColor); + textNokia2->writeDX(TXT_CENTER, param.game.playArea.centerX, stageBitmapPath[stageBitmapCounter] + textNokiaBig2->getCharacterSize() + 2, lang::getText(76), -1, noColor, 1, shdwTxtColor); } } } @@ -2439,8 +2439,8 @@ void Game::initPaths() // Letrero de STAGE # const int firstPart = STAGE_COUNTER / 4; // 50 const int secondPart = firstPart * 3; // 150 - const int centerPoint = param->game.playArea.centerY - (BLOCK * 2); - const int distance = (param->game.playArea.rect.h) - (param->game.playArea.centerY - 16); + const int centerPoint = param.game.playArea.centerY - (BLOCK * 2); + const int distance = (param.game.playArea.rect.h) - (param.game.playArea.centerY - 16); for (int i = 0; i < STAGE_COUNTER; ++i) { @@ -2464,10 +2464,10 @@ void Game::initPaths() const int size = textNokiaBig2->lenght(lang::getText(75), -2); const float start1 = PLAY_AREA_LEFT - size; - const float finish1 = param->game.playArea.centerX - (size / 2); + const float finish1 = param.game.playArea.centerX - (size / 2); const float start2 = finish1; - const float finish2 = param->game.playArea.rect.w; + const float finish2 = param.game.playArea.rect.w; const float distance1 = finish1 - start1; const float distance2 = finish2 - start2; @@ -2600,7 +2600,7 @@ void Game::checkEvents() { // CREA UN SPRITE DE 1000 PUNTOS case SDLK_h: - createItemScoreSprite(param->game.width / 2, param->game.width / 2, n1000Sprite); + createItemScoreSprite(param.game.width / 2, param.game.width / 2, n1000Sprite); break; // CREA UNA POWERBALL diff --git a/source/game.h b/source/game.h index 4ee001c..9e62448 100644 --- a/source/game.h +++ b/source/game.h @@ -195,7 +195,6 @@ private: float difficultyScoreMultiplier; // Multiplicador de puntos en función de la dificultad color_t difficultyColor; // Color asociado a la dificultad options_t *options; // Opciones del programa - param_t *param; // Puntero con todos los parametros del programa int lastStageReached; // Contiene el número de la última pantalla que se ha alcanzado demo_t demo; // Variable con todas las variables relacionadas con el modo demo int totalPowerToCompleteGame; // La suma del poder necesario para completar todas las fases @@ -450,7 +449,7 @@ private: public: // Constructor - Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *asset, Input *input, options_t *options, param_t *param, section_t *section, JA_Music_t *music); + Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music); // Destructor ~Game(); diff --git a/source/game_logo.cpp b/source/game_logo.cpp index 2084b56..4a095db 100644 --- a/source/game_logo.cpp +++ b/source/game_logo.cpp @@ -1,13 +1,13 @@ #include "game_logo.h" +#include "param.h" // Constructor -GameLogo::GameLogo(SDL_Renderer *renderer, Screen *screen, Asset *asset, param_t *param, int x, int y) +GameLogo::GameLogo(SDL_Renderer *renderer, Screen *screen, Asset *asset, 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; @@ -19,7 +19,7 @@ GameLogo::GameLogo(SDL_Renderer *renderer, Screen *screen, Asset *asset, param_t coffeeBitmap = new SmartSprite(coffeeTexture); crisisBitmap = new SmartSprite(crisisTexture); - arcadeEditionBitmap = new Sprite((param->game.width - arcadeEditionTexture->getWidth()) / 2, param->title.arcadeEditionPosition, arcadeEditionTexture->getWidth(), arcadeEditionTexture->getHeight(), arcadeEditionTexture); + arcadeEditionBitmap = new Sprite((param.game.width - arcadeEditionTexture->getWidth()) / 2, param.title.arcadeEditionPosition, arcadeEditionTexture->getWidth(), arcadeEditionTexture->getHeight(), arcadeEditionTexture); dustBitmapL = new AnimatedSprite(dustTexture, asset->get("title_dust.ani")); dustBitmapR = new AnimatedSprite(dustTexture, asset->get("title_dust.ani")); @@ -207,7 +207,7 @@ void GameLogo::reLoad() int GameLogo::getInitialVerticalDesp() { int despUp = y; - int despDown = param->game.height - y; + int despDown = param.game.height - 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 3b05e2f..7ed039e 100644 --- a/source/game_logo.h +++ b/source/game_logo.h @@ -30,7 +30,6 @@ private: Sprite *arcadeEditionBitmap; // Sprite con los graficos de "Arcade Edition" 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 @@ -62,7 +61,7 @@ private: public: // Constructor - GameLogo(SDL_Renderer *renderer, Screen *screen, Asset *asset, param_t *param, int x, int y); + GameLogo(SDL_Renderer *renderer, Screen *screen, Asset *asset, int x, int y); // Destructor ~GameLogo(); diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index 143ef9b..87fe220 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -1,8 +1,9 @@ #include "hiscore_table.h" +#include "param.h" #include // Constructor -HiScoreTable::HiScoreTable(Screen *screen, Asset *asset, Input *input, options_t *options, param_t *param, section_t *section, JA_Music_t *music) +HiScoreTable::HiScoreTable(Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music) { // Copia punteros this->screen = screen; @@ -10,18 +11,17 @@ HiScoreTable::HiScoreTable(Screen *screen, Asset *asset, Input *input, options_t this->input = input; this->section = section; this->options = options; - this->param = param; this->music = music; renderer = screen->getRenderer(); // Objetos eventHandler = new SDL_Event(); - fade = new Fade(renderer, param); - background = new Background(renderer, asset, param); + fade = new Fade(renderer); + background = new Background(renderer, asset); text = new Text(asset->get("smb2.gif"), asset->get("smb2.txt"), renderer); // Crea un backbuffer para el renderizador - backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->game.width, param->game.height); + backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height); SDL_SetTextureBlendMode(backbuffer, SDL_BLENDMODE_BLEND); // Inicializa variables @@ -30,17 +30,17 @@ HiScoreTable::HiScoreTable(Screen *screen, Asset *asset, Input *input, options_t ticksSpeed = 15; counter = 0; counterEnd = 800; - viewArea = {0, 0, param->game.width, param->game.height}; + viewArea = {0, 0, param.game.width, param.game.height}; fadeMode = FADE_IN; // Inicializa objetos - background->setPos(param->game.gameArea.rect); + background->setPos(param.game.gameArea.rect); background->setCloudsSpeed(-0.1f); background->setGradientNumber(1); background->setTransition(0.8f); fade->setColor(fadeColor.r, fadeColor.g, fadeColor.b); fade->setType(FADE_RANDOM_SQUARE); - fade->setPost(param->fade.postDuration); + fade->setPost(param.fade.postDuration); fade->setMode(fadeMode); fade->activate(); @@ -104,7 +104,7 @@ void HiScoreTable::fillTexture() const int spaceBetweenHeader = 32; const int spaceBetweenLines = text->getCharacterSize() * 2.0f; const int size = spaceBetweenHeader + spaceBetweenLines * (maxNames - 1) + text->getCharacterSize(); - const int firstLine = (param->game.height - size) / 2; + const int firstLine = (param.game.height - size) / 2; // Pinta en el backbuffer el texto y los sprites SDL_Texture *temp = SDL_GetRenderTarget(renderer); @@ -113,7 +113,7 @@ void HiScoreTable::fillTexture() SDL_RenderClear(renderer); // Escribe el texto: Mejores puntuaciones - text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param->game.gameArea.centerX, firstLine, lang::getText(42), 1, orangeColor, 1, shdwTxtColor); + text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.gameArea.centerX, firstLine, lang::getText(42), 1, orangeColor, 1, shdwTxtColor); // Escribe los nombres de la tabla de puntuaciones for (int i = 0; i < maxNames; ++i) @@ -128,7 +128,7 @@ void HiScoreTable::fillTexture() dots = dots + "."; } const std::string line = options->game.hiScoreTable[i].name + dots + score; - text->writeDX(TXT_CENTER | TXT_SHADOW, param->game.gameArea.centerX, (i * spaceBetweenLines) + firstLine + spaceBetweenHeader, line, 1, orangeColor, 1, shdwTxtColor); + text->writeDX(TXT_CENTER | TXT_SHADOW, param.game.gameArea.centerX, (i * spaceBetweenLines) + firstLine + spaceBetweenHeader, line, 1, orangeColor, 1, shdwTxtColor); } // Cambia el destino de renderizado @@ -148,7 +148,7 @@ void HiScoreTable::render() background->render(); // Establece la ventana del backbuffer - viewArea.y = std::max(0, param->game.height - counter + 100); + viewArea.y = std::max(0, param.game.height - counter + 100); // Copia el backbuffer al renderizador SDL_RenderCopy(renderer, backbuffer, nullptr, &viewArea); diff --git a/source/hiscore_table.h b/source/hiscore_table.h index 556447f..4851eb8 100644 --- a/source/hiscore_table.h +++ b/source/hiscore_table.h @@ -40,7 +40,6 @@ private: JA_Music_t *music; // Musica de fondo options_t *options; // Opciones del programa 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 @@ -82,7 +81,7 @@ private: public: // Constructor - HiScoreTable(Screen *screen, Asset *asset, Input *input, options_t *options, param_t *param, section_t *section, JA_Music_t *music); + HiScoreTable(Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music); // Destructor ~HiScoreTable(); diff --git a/source/instructions.cpp b/source/instructions.cpp index 3524d6e..e1ba8cb 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -1,14 +1,14 @@ #include "instructions.h" +#include "param.h" #include // Constructor -Instructions::Instructions(Screen *screen, Asset *asset, Input *input, options_t *options, param_t *param, section_t *section, JA_Music_t *music) +Instructions::Instructions(Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music) { // Copia los punteros this->screen = screen; this->asset = asset; this->input = input; - this->param = param; this->section = section; this->music = music; this->options = options; @@ -17,15 +17,15 @@ Instructions::Instructions(Screen *screen, Asset *asset, Input *input, options_t // Crea objetos eventHandler = new SDL_Event(); text = new Text(asset->get("smb2.gif"), asset->get("smb2.txt"), renderer); - tiledbg = new Tiledbg(renderer, asset, {0, 0, param->game.width, param->game.height}, TILED_MODE_STATIC); - fade = new Fade(renderer, param); + tiledbg = new Tiledbg(renderer, asset, {0, 0, param.game.width, param.game.height}, TILED_MODE_STATIC); + fade = new Fade(renderer); // Crea un backbuffer para el renderizador - backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->game.width, param->game.height); + backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height); SDL_SetTextureBlendMode(backbuffer, SDL_BLENDMODE_BLEND); // Crea una textura para el texto fijo - texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->game.width, param->game.height); + texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height); SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); // Inicializa variables @@ -34,14 +34,14 @@ Instructions::Instructions(Screen *screen, Asset *asset, Input *input, options_t ticksSpeed = 15; counter = 0; counterEnd = 700; - view = {0, 0, param->game.width, param->game.height}; + view = {0, 0, param.game.width, param.game.height}; spritePos = {0, 0}; itemSpace = 2; // Inicializa objetos fade->setColor(fadeColor.r, fadeColor.g, fadeColor.b); fade->setType(FADE_FULLSCREEN); - fade->setPost(param->fade.postDuration); + fade->setPost(param.fade.postDuration); fade->setMode(FADE_IN); fade->activate(); @@ -99,8 +99,8 @@ void Instructions::iniSprites() // Inicializa los sprites for (int i = 0; i < (int)itemTextures.size(); ++i) { - Sprite *sprite = new Sprite(0, 0, param->game.itemSize, param->game.itemSize, itemTextures[i]); - sprite->setPos((SDL_Point){spritePos.x, spritePos.y + ((param->game.itemSize + itemSpace) * i)}); + Sprite *sprite = new Sprite(0, 0, param.game.itemSize, param.game.itemSize, itemTextures[i]); + sprite->setPos((SDL_Point){spritePos.x, spritePos.y + ((param.game.itemSize + itemSpace) * i)}); sprites.push_back(sprite); } } @@ -108,33 +108,33 @@ void Instructions::iniSprites() // Actualiza los sprites void Instructions::updateSprites() { - SDL_Rect srcRect = {0, 0, param->game.itemSize, param->game.itemSize}; + SDL_Rect srcRect = {0, 0, param.game.itemSize, param.game.itemSize}; // Disquito - srcRect.y = param->game.itemSize * (((counter + 12) / 36) % 2); + srcRect.y = param.game.itemSize * (((counter + 12) / 36) % 2); sprites[0]->setSpriteClip(srcRect); // Gavineixon - srcRect.y = param->game.itemSize * (((counter + 9) / 36) % 2); + srcRect.y = param.game.itemSize * (((counter + 9) / 36) % 2); sprites[1]->setSpriteClip(srcRect); // Pacmar - srcRect.y = param->game.itemSize * (((counter + 6) / 36) % 2); + srcRect.y = param.game.itemSize * (((counter + 6) / 36) % 2); sprites[2]->setSpriteClip(srcRect); // Time Stopper - srcRect.y = param->game.itemSize * (((counter + 3) / 36) % 2); + srcRect.y = param.game.itemSize * (((counter + 3) / 36) % 2); sprites[3]->setSpriteClip(srcRect); // Coffee - srcRect.y = param->game.itemSize * (((counter + 0) / 36) % 2); + srcRect.y = param.game.itemSize * (((counter + 0) / 36) % 2); sprites[4]->setSpriteClip(srcRect); } // Rellena la textura de texto void Instructions::fillTexture() { - const int despX = param->game.itemSize + 8; + const int despX = param.game.itemSize + 8; // Modifica el renderizador para pintar en la textura SDL_Texture *temp = SDL_GetRenderTarget(renderer); @@ -153,11 +153,11 @@ void Instructions::fillTexture() const int spacePostHeader = 20; const int spacePreHeader = 28; const int spaceBetweenLines = text->getCharacterSize() * 1.5f; - const int spaceBetweenItemLines = param->game.itemSize + itemSpace; + const int spaceBetweenItemLines = param.game.itemSize + itemSpace; const int spaceNewParagraph = spaceBetweenLines * 0.5f; const int size = (numLines * spaceBetweenLines) + (numItemLines * spaceBetweenItemLines) + (numPostHeaders * spacePostHeader) + (numPreHeaders * spacePreHeader) + (spaceNewParagraph); - const int firstLine = (param->game.height - size) / 2; + const int firstLine = (param.game.height - size) / 2; // Calcula cual es el texto más largo de las descripciones de los items int lenght = 0; @@ -166,23 +166,23 @@ void Instructions::fillTexture() const int l = text->lenght(lang::getText(i)); lenght = l > lenght ? l : lenght; } - const int anchorItem = (param->game.width - (lenght + despX)) / 2; + const int anchorItem = (param.game.width - (lenght + despX)) / 2; // Escribe el texto de las instrucciones - text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param->game.gameArea.centerX, firstLine, lang::getText(11), 1, orangeColor, 1, shdwTxtColor); + text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.gameArea.centerX, firstLine, lang::getText(11), 1, orangeColor, 1, shdwTxtColor); const int anchor1 = firstLine + spacePostHeader; - text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param->game.gameArea.centerX, anchor1 + spaceBetweenLines * 0, lang::getText(12), 1, noColor, 1, shdwTxtColor); - text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param->game.gameArea.centerX, anchor1 + spaceBetweenLines * 1, lang::getText(13), 1, noColor, 1, shdwTxtColor); - text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param->game.gameArea.centerX, anchor1 + spaceNewParagraph + spaceBetweenLines * 2, lang::getText(14), 1, noColor, 1, shdwTxtColor); - text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param->game.gameArea.centerX, anchor1 + spaceNewParagraph + spaceBetweenLines * 3, lang::getText(15), 1, noColor, 1, shdwTxtColor); + text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.gameArea.centerX, anchor1 + spaceBetweenLines * 0, lang::getText(12), 1, noColor, 1, shdwTxtColor); + text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.gameArea.centerX, anchor1 + spaceBetweenLines * 1, lang::getText(13), 1, noColor, 1, shdwTxtColor); + text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.gameArea.centerX, anchor1 + spaceNewParagraph + spaceBetweenLines * 2, lang::getText(14), 1, noColor, 1, shdwTxtColor); + text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.gameArea.centerX, anchor1 + spaceNewParagraph + spaceBetweenLines * 3, lang::getText(15), 1, noColor, 1, shdwTxtColor); // Escribe el texto de los objetos y sus puntos const int anchor2 = anchor1 + spacePreHeader + spaceNewParagraph + spaceBetweenLines * 3; - text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param->game.gameArea.centerX, anchor2, lang::getText(16), 1, orangeColor, 1, shdwTxtColor); + text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.gameArea.centerX, anchor2, lang::getText(16), 1, orangeColor, 1, shdwTxtColor); const int anchor3 = anchor2 + spacePostHeader; - // const int anchor4 = anchor3 + ((param->game.itemSize + text->getCharacterSize()) / 2); + // const int anchor4 = anchor3 + ((param.game.itemSize + text->getCharacterSize()) / 2); text->writeShadowed(anchorItem + despX, anchor3 + spaceBetweenItemLines * 0, lang::getText(17), shdwTxtColor); text->writeShadowed(anchorItem + despX, anchor3 + spaceBetweenItemLines * 1, lang::getText(18), shdwTxtColor); text->writeShadowed(anchorItem + despX, anchor3 + spaceBetweenItemLines * 2, lang::getText(19), shdwTxtColor); @@ -194,7 +194,7 @@ void Instructions::fillTexture() // Da valor a la variable spritePos.x = anchorItem; - spritePos.y = anchor3 - ((param->game.itemSize - text->getCharacterSize()) / 2); + spritePos.y = anchor3 - ((param.game.itemSize - text->getCharacterSize()) / 2); } // Rellena el backbuffer @@ -274,7 +274,7 @@ void Instructions::render() tiledbg->render(); // Establece la ventana del backbuffer - view.y = std::max(0, param->game.height - counter + 100); + view.y = std::max(0, param.game.height - counter + 100); // Copia la textura y el backbuffer al renderizador SDL_RenderCopy(renderer, backbuffer, nullptr, &view); diff --git a/source/instructions.h b/source/instructions.h index 0506069..edbac0a 100644 --- a/source/instructions.h +++ b/source/instructions.h @@ -45,7 +45,6 @@ private: Fade *fade; // Objeto para renderizar fades JA_Music_t *music; // Musica de fondo section_t *section; // Estado del bucle principal para saber si continua o se sale - param_t *param; // Puntero con todos los parametros del programa options_t *options; // Opciones del programa // Variables @@ -89,7 +88,7 @@ private: public: // Constructor - Instructions(Screen *screen, Asset *asset, Input *input, options_t *options, param_t *param, section_t *section, JA_Music_t *music); + Instructions(Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music); // Destructor ~Instructions(); diff --git a/source/intro.cpp b/source/intro.cpp index 632287c..83f4563 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -1,13 +1,13 @@ #include "intro.h" +#include "param.h" // Constructor -Intro::Intro(Screen *screen, Asset *asset, Input *input, options_t *options, param_t *param, section_t *section, JA_Music_t *music) +Intro::Intro(Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music) { // Copia los punteros this->screen = screen; this->asset = asset; this->input = input; - this->param = param; this->section = section; this->music = music; SDL_Renderer *renderer = screen->getRenderer(); @@ -32,28 +32,28 @@ Intro::Intro(Screen *screen, Asset *asset, Input *input, options_t *options, par ss->setWidth(128); ss->setHeight(96); ss->setEnabledCounter(20); - ss->setDestX(param->game.gameArea.centerX - 64); - ss->setDestY(param->game.gameArea.firstQuarterY - 24); + ss->setDestX(param.game.gameArea.centerX - 64); + ss->setDestY(param.game.gameArea.firstQuarterY - 24); bitmaps.push_back(ss); } bitmaps[0]->setPosX(-128); - bitmaps[0]->setPosY(param->game.gameArea.firstQuarterY - 24); + bitmaps[0]->setPosY(param.game.gameArea.firstQuarterY - 24); bitmaps[0]->setVelX(0.0f); bitmaps[0]->setVelY(0.0f); bitmaps[0]->setAccelX(0.6f); bitmaps[0]->setAccelY(0.0f); bitmaps[0]->setSpriteClip(0, 0, 128, 96); - bitmaps[1]->setPosX(param->game.width); - bitmaps[1]->setPosY(param->game.gameArea.firstQuarterY - 24); + bitmaps[1]->setPosX(param.game.width); + bitmaps[1]->setPosY(param.game.gameArea.firstQuarterY - 24); bitmaps[1]->setVelX(-1.0f); bitmaps[1]->setVelY(0.0f); bitmaps[1]->setAccelX(-0.3f); bitmaps[1]->setAccelY(0.0f); bitmaps[1]->setSpriteClip(128, 0, 128, 96); - bitmaps[2]->setPosX(param->game.gameArea.centerX - 64); + bitmaps[2]->setPosX(param.game.gameArea.centerX - 64); bitmaps[2]->setPosY(-96); bitmaps[2]->setVelX(0.0f); bitmaps[2]->setVelY(3.0f); @@ -62,15 +62,15 @@ Intro::Intro(Screen *screen, Asset *asset, Input *input, options_t *options, par bitmaps[2]->setSpriteClip(0, 96, 128, 96); bitmaps[2]->setEnabledCounter(250); - bitmaps[3]->setPosX(param->game.gameArea.centerX - 64); - bitmaps[3]->setPosY(param->game.height); + bitmaps[3]->setPosX(param.game.gameArea.centerX - 64); + bitmaps[3]->setPosY(param.game.height); bitmaps[3]->setVelX(0.0f); bitmaps[3]->setVelY(-0.7f); bitmaps[3]->setAccelX(0.0f); bitmaps[3]->setAccelY(0.0f); bitmaps[3]->setSpriteClip(128, 96, 128, 96); - bitmaps[4]->setPosX(param->game.gameArea.centerX - 64); + bitmaps[4]->setPosX(param.game.gameArea.centerX - 64); bitmaps[4]->setPosY(-96); bitmaps[4]->setVelX(0.0f); bitmaps[4]->setVelY(3.0f); @@ -78,8 +78,8 @@ Intro::Intro(Screen *screen, Asset *asset, Input *input, options_t *options, par bitmaps[4]->setAccelY(0.3f); bitmaps[4]->setSpriteClip(0, 192, 128, 96); - bitmaps[5]->setPosX(param->game.width); - bitmaps[5]->setPosY(param->game.gameArea.firstQuarterY - 24); + bitmaps[5]->setPosX(param.game.width); + bitmaps[5]->setPosY(param.game.gameArea.firstQuarterY - 24); bitmaps[5]->setVelX(-0.7f); bitmaps[5]->setVelY(0.0f); bitmaps[5]->setAccelX(0.0f); @@ -92,7 +92,7 @@ Intro::Intro(Screen *screen, Asset *asset, Input *input, options_t *options, par { Writer *w = new Writer(text); w->setPosX(BLOCK * 0); - w->setPosY(param->game.height - (BLOCK * 6)); + w->setPosY(param.game.height - (BLOCK * 6)); w->setKerning(-1); w->setEnabled(false); w->setEnabledCounter(180); @@ -137,7 +137,7 @@ Intro::Intro(Screen *screen, Asset *asset, Input *input, options_t *options, par for (auto text : texts) { - text->center(param->game.gameArea.centerX); + text->center(param.game.gameArea.centerX); } } diff --git a/source/intro.h b/source/intro.h index e660065..900a251 100644 --- a/source/intro.h +++ b/source/intro.h @@ -32,7 +32,6 @@ private: Text *text; // Textos de la intro section_t *section; // Estado del bucle principal para saber si continua o se sale options_t *options; // Opciones del programa - param_t *param; // Puntero con todos los parametros del programa // Variables Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa @@ -63,7 +62,7 @@ private: public: // Constructor - Intro(Screen *screen, Asset *asset, Input *input, options_t *options, param_t *param, section_t *section, JA_Music_t *music); + Intro(Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music); // Destructor ~Intro(); diff --git a/source/logo.cpp b/source/logo.cpp index 7d65a7f..4e0685c 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -1,15 +1,15 @@ #include "logo.h" +#include "param.h" #include // Constructor -Logo::Logo(Screen *screen, Asset *asset, Input *input, options_t *options, param_t *param, section_t *section) +Logo::Logo(Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section) { // Copia la dirección de los objetos this->screen = screen; this->asset = asset; this->input = input; this->options = options; - this->param = param; this->section = section; SDL_Renderer *renderer = screen->getRenderer(); @@ -17,7 +17,7 @@ Logo::Logo(Screen *screen, Asset *asset, Input *input, options_t *options, param 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((param->game.width - sinceTexture->getWidth()) / 2, 83 + jailTexture->getHeight() + 5, sinceTexture->getWidth(), sinceTexture->getHeight(), sinceTexture); + sinceSprite = new Sprite((param.game.width - sinceTexture->getWidth()) / 2, 83 + jailTexture->getHeight() + 5, sinceTexture->getWidth(), sinceTexture->getHeight(), sinceTexture); // Inicializa variables counter = 0; @@ -29,8 +29,8 @@ Logo::Logo(Screen *screen, Asset *asset, Input *input, options_t *options, param endLogo_cm = 400; postLogoDuration = 20; speed = 8; - dest.x = param->game.gameArea.centerX - jailTexture->getWidth() / 2; - dest.y = param->game.gameArea.centerY - jailTexture->getHeight() / 2; + dest.x = param.game.gameArea.centerX - jailTexture->getWidth() / 2; + dest.y = param.game.gameArea.centerY - jailTexture->getHeight() / 2; sinceSprite->setPosY(dest.y + jailTexture->getHeight() + 5); sinceSprite->setSpriteClip(0, 0, sinceTexture->getWidth(), sinceTexture->getHeight()); sinceSprite->setEnabled(false); @@ -41,7 +41,7 @@ Logo::Logo(Screen *screen, Asset *asset, Input *input, options_t *options, param { Sprite *temp = new Sprite(0, i, jailTexture->getWidth(), 1, jailTexture); temp->setSpriteClip(0, i, jailTexture->getWidth(), 1); - const int posX = (i % 2 == 0) ? param->game.width + (i * 3) : -jailTexture->getWidth() - (i * 3); + const int posX = (i % 2 == 0) ? param.game.width + (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 4773194..c149931 100644 --- a/source/logo.h +++ b/source/logo.h @@ -33,7 +33,6 @@ 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 options_t *options; // Opciones del programa // Variables @@ -74,7 +73,7 @@ private: public: // Constructor - Logo(Screen *screen, Asset *asset, Input *input, options_t *options, param_t *param, section_t *section); + Logo(Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section); // Destructor ~Logo(); diff --git a/source/load_param.cpp b/source/param.cpp similarity index 51% rename from source/load_param.cpp rename to source/param.cpp index e0ced71..b93b465 100644 --- a/source/load_param.cpp +++ b/source/param.cpp @@ -1,61 +1,63 @@ -#include "load_param.h" +#include "param.h" #include #include +param_t param; + // Asigna variables a partir de dos cadenas -bool setOptions(param_t *param, std::string var, std::string value); +bool setOptions(std::string var, std::string value); // Calcula variables a partir de otras variables -void precalculateZones(param_t *param); +void precalculateZones(); // Establece valores por defecto a las variables -void initParam(param_t *param) +void initParam() { // GAME - param->game.width = 320; - param->game.height = 256; - param->game.itemSize = 20; - param->game.gameArea.rect = {0, 0, param->game.width, param->game.height}; - param->game.playArea.rect = {0, 0, param->game.width, 216}; - precalculateZones(param); + param.game.width = 320; + param.game.height = 256; + param.game.itemSize = 20; + param.game.gameArea.rect = {0, 0, param.game.width, param.game.height}; + param.game.playArea.rect = {0, 0, param.game.width, 216}; + precalculateZones(); // SCOREBOARD - param->scoreboard = {0, 216, param->game.width, 40}; + param.scoreboard = {0, 216, param.game.width, 40}; // FADE - param->fade.numSquaresWidth = param->game.width / 2; - param->fade.numSquaresHeight = param->game.height / 2; - param->fade.randomSquaresDelay = 1; - param->fade.randomSquaresMult = 500; - param->fade.postDuration = 80; - param->fade.venetianSize = 16; + param.fade.numSquaresWidth = param.game.width / 2; + param.fade.numSquaresHeight = param.game.height / 2; + param.fade.randomSquaresDelay = 1; + param.fade.randomSquaresMult = 500; + param.fade.postDuration = 80; + param.fade.venetianSize = 16; // TITLE - param->title.pressStartPosition = 160; - param->title.titleDuration = 800; - param->title.arcadeEditionPosition = 123; - param->title.titleCCPosition = 11; + param.title.pressStartPosition = 160; + param.title.titleDuration = 800; + param.title.arcadeEditionPosition = 123; + param.title.titleCCPosition = 11; // BACKGROUND - param->background.attenuateColor = {255, 255, 255}; - param->background.attenuateAlpha = 32; + param.background.attenuateColor = {255, 255, 255}; + param.background.attenuateAlpha = 32; // BALLOONS - param->balloon1.vel = 2.60f; - param->balloon1.grav = 0.09f; - param->balloon2.vel = 3.50f; - param->balloon2.grav = 0.10f; - param->balloon3.vel = 4.50f; - param->balloon3.grav = 0.10f; - param->balloon4.vel = 4.95f; - param->balloon4.grav = 0.10f; + param.balloon1.vel = 2.60f; + param.balloon1.grav = 0.09f; + param.balloon2.vel = 3.50f; + param.balloon2.grav = 0.10f; + param.balloon3.vel = 4.50f; + param.balloon3.grav = 0.10f; + param.balloon4.vel = 4.95f; + param.balloon4.grav = 0.10f; } // Establece valores para los parametros a partir de un fichero de texto -void loadParamsFromFile(param_t *param, std::string filePath) +void loadParamsFromFile(std::string filePath) { // Pone valores por defecto a las variables - initParam(param); + initParam(); // Variables para manejar el fichero std::string line; @@ -134,7 +136,7 @@ void loadParamsFromFile(param_t *param, std::string filePath) } } - setOptions(param, param1, param2); + setOptions(param1, param2); } // Cierra el fichero @@ -145,11 +147,11 @@ void loadParamsFromFile(param_t *param, std::string filePath) std::cout << "Failed to load file: " << filePath << std::endl; #endif - precalculateZones(param); + precalculateZones(); } // Asigna variables a partir de dos cadenas -bool setOptions(param_t *param, std::string var, std::string value) +bool setOptions(std::string var, std::string value) { // Indicador de éxito en la asignación bool success = true; @@ -157,172 +159,172 @@ bool setOptions(param_t *param, std::string var, std::string value) // GAME if (var == "game.width") { - param->game.width = std::stoi(value); + param.game.width = std::stoi(value); } else if (var == "game.height") { - param->game.height = std::stoi(value); + param.game.height = std::stoi(value); } else if (var == "game.itemSize") { - param->game.itemSize = std::stoi(value); + param.game.itemSize = std::stoi(value); } else if (var == "game.playArea.rect.x") { - param->game.playArea.rect.x = std::stoi(value); + param.game.playArea.rect.x = std::stoi(value); } else if (var == "game.playArea.rect.y") { - param->game.playArea.rect.y = std::stoi(value); + param.game.playArea.rect.y = std::stoi(value); } else if (var == "game.playArea.rect.w") { - param->game.playArea.rect.w = std::stoi(value); + param.game.playArea.rect.w = std::stoi(value); } else if (var == "game.playArea.rect.h") { - param->game.playArea.rect.h = std::stoi(value); + param.game.playArea.rect.h = std::stoi(value); } // FADE else if (var == "fade.numSquaresWidth") { - param->fade.numSquaresWidth = std::stoi(value); + param.fade.numSquaresWidth = std::stoi(value); } else if (var == "fade.numSquaresHeight") { - param->fade.numSquaresHeight = std::stoi(value); + param.fade.numSquaresHeight = std::stoi(value); } else if (var == "fade.randomSquaresDelay") { - param->fade.randomSquaresDelay = std::stoi(value); + param.fade.randomSquaresDelay = std::stoi(value); } else if (var == "fade.randomSquaresMult") { - param->fade.randomSquaresMult = std::stoi(value); + param.fade.randomSquaresMult = std::stoi(value); } else if (var == "fade.postDuration") { - param->fade.postDuration = std::stoi(value); + param.fade.postDuration = std::stoi(value); } else if (var == "fade.venetianSize") { - param->fade.venetianSize = std::stoi(value); + param.fade.venetianSize = std::stoi(value); } // SCOREBOARD else if (var == "scoreboard.x") { - param->scoreboard.x = std::stoi(value); + param.scoreboard.x = std::stoi(value); } else if (var == "scoreboard.y") { - param->scoreboard.y = std::stoi(value); + param.scoreboard.y = std::stoi(value); } else if (var == "scoreboard.w") { - param->scoreboard.w = std::stoi(value); + param.scoreboard.w = std::stoi(value); } else if (var == "scoreboard.h") { - param->scoreboard.h = std::stoi(value); + param.scoreboard.h = std::stoi(value); } // TITLE else if (var == "title.pressStartPosition") { - param->title.pressStartPosition = std::stoi(value); + param.title.pressStartPosition = std::stoi(value); } else if (var == "title.titleDuration") { - param->title.titleDuration = std::stoi(value); + param.title.titleDuration = std::stoi(value); } else if (var == "title.arcadeEditionPosition") { - param->title.arcadeEditionPosition = std::stoi(value); + param.title.arcadeEditionPosition = std::stoi(value); } else if (var == "title.titleCCPosition") { - param->title.titleCCPosition = std::stoi(value); + param.title.titleCCPosition = std::stoi(value); } // BACKGROUND else if (var == "background.attenuateColor.r") { - param->background.attenuateColor.r = std::stoi(value); + param.background.attenuateColor.r = std::stoi(value); } else if (var == "background.attenuateColor.g") { - param->background.attenuateColor.g = std::stoi(value); + param.background.attenuateColor.g = std::stoi(value); } else if (var == "background.attenuateColor.b") { - param->background.attenuateColor.b = std::stoi(value); + param.background.attenuateColor.b = std::stoi(value); } else if (var == "background.attenuateAlpha") { - param->background.attenuateAlpha = std::stoi(value); + param.background.attenuateAlpha = std::stoi(value); } // BALLOON else if (var == "balloon1.vel") { - param->balloon1.vel = std::stof(value); + param.balloon1.vel = std::stof(value); } else if (var == "balloon1.grav") { - param->balloon1.grav = std::stof(value); + param.balloon1.grav = std::stof(value); } else if (var == "balloon2.vel") { - param->balloon2.vel = std::stof(value); + param.balloon2.vel = std::stof(value); } else if (var == "balloon2.grav") { - param->balloon2.grav = std::stof(value); + param.balloon2.grav = std::stof(value); } else if (var == "balloon3.vel") { - param->balloon3.vel = std::stof(value); + param.balloon3.vel = std::stof(value); } else if (var == "balloon3.grav") { - param->balloon3.grav = std::stof(value); + param.balloon3.grav = std::stof(value); } else if (var == "balloon4.vel") { - param->balloon4.vel = std::stof(value); + param.balloon4.vel = std::stof(value); } else if (var == "balloon4.grav") { - param->balloon4.grav = std::stof(value); + param.balloon4.grav = std::stof(value); } // RESTO @@ -335,23 +337,22 @@ bool setOptions(param_t *param, std::string var, std::string value) } // Calcula variables a partir de otras variables -void precalculateZones(param_t *param) +void precalculateZones() { - // playArea - param->game.playArea.centerX = param->game.playArea.rect.w / 2; - param->game.playArea.firstQuarterX = param->game.playArea.rect.w / 4; - param->game.playArea.thirdQuarterX = param->game.playArea.rect.w / 4 * 3; - param->game.playArea.centerY = param->game.playArea.rect.h / 2; - param->game.playArea.firstQuarterY = param->game.playArea.rect.h / 4; - param->game.playArea.thirdQuarterY = param->game.playArea.rect.h / 4 * 3; + param.game.playArea.centerX = param.game.playArea.rect.w / 2; + param.game.playArea.firstQuarterX = param.game.playArea.rect.w / 4; + param.game.playArea.thirdQuarterX = param.game.playArea.rect.w / 4 * 3; + param.game.playArea.centerY = param.game.playArea.rect.h / 2; + param.game.playArea.firstQuarterY = param.game.playArea.rect.h / 4; + param.game.playArea.thirdQuarterY = param.game.playArea.rect.h / 4 * 3; // gameArea - param->game.gameArea.rect = {0, 0, param->game.width, param->game.height}; - param->game.gameArea.centerX = param->game.gameArea.rect.w / 2; - param->game.gameArea.firstQuarterX = param->game.gameArea.rect.w / 4; - param->game.gameArea.thirdQuarterX = param->game.gameArea.rect.w / 4 * 3; - param->game.gameArea.centerY = param->game.gameArea.rect.h / 2; - param->game.gameArea.firstQuarterY = param->game.gameArea.rect.h / 4; - param->game.gameArea.thirdQuarterY = param->game.gameArea.rect.h / 4 * 3; + param.game.gameArea.rect = {0, 0, param.game.width, param.game.height}; + param.game.gameArea.centerX = param.game.gameArea.rect.w / 2; + param.game.gameArea.firstQuarterX = param.game.gameArea.rect.w / 4; + param.game.gameArea.thirdQuarterX = param.game.gameArea.rect.w / 4 * 3; + param.game.gameArea.centerY = param.game.gameArea.rect.h / 2; + param.game.gameArea.firstQuarterY = param.game.gameArea.rect.h / 4; + param.game.gameArea.thirdQuarterY = param.game.gameArea.rect.h / 4 * 3; } \ No newline at end of file diff --git a/source/load_param.h b/source/param.h similarity index 69% rename from source/load_param.h rename to source/param.h index 2aec4ae..7261464 100644 --- a/source/load_param.h +++ b/source/param.h @@ -4,5 +4,7 @@ #include "common/utils.h" #include "const.h" +extern param_t param; + // Establece valores para los parametros a partir de un fichero de texto -void loadParamsFromFile(param_t *param, std::string filePath); \ No newline at end of file +void loadParamsFromFile(std::string filePath); \ No newline at end of file diff --git a/source/title.cpp b/source/title.cpp index 544ef00..7d3cf93 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -1,21 +1,21 @@ #include "title.h" +#include "param.h" // Constructor -Title::Title(Screen *screen, Asset *asset, Input *input, options_t *options, param_t *param, section_t *section, JA_Music_t *music) +Title::Title(Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music) { // Copia las direcciones de los punteros y objetos this->screen = screen; this->input = input; this->asset = asset; this->options = options; - this->param = param; this->section = section; this->music = music; SDL_Renderer *renderer = screen->getRenderer(); // Reserva memoria y crea los objetos eventHandler = new SDL_Event(); - fade = new Fade(renderer, param); + fade = new Fade(renderer); text1 = new Text(asset->get("smb2.gif"), asset->get("smb2.txt"), renderer); text1->addPalette(asset->get("smb2_pal1.gif")); @@ -23,14 +23,14 @@ Title::Title(Screen *screen, Asset *asset, Input *input, options_t *options, par text2 = new Text(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer); miniLogoTexture = new Texture(renderer, asset->get("logo_jailgames_mini.png")); - miniLogoSprite = new Sprite(param->game.gameArea.centerX - miniLogoTexture->getWidth() / 2, 0, miniLogoTexture->getWidth(), miniLogoTexture->getHeight(), miniLogoTexture); + miniLogoSprite = new Sprite(param.game.gameArea.centerX - miniLogoTexture->getWidth() / 2, 0, miniLogoTexture->getWidth(), miniLogoTexture->getHeight(), miniLogoTexture); - tiledbg = new Tiledbg(renderer, asset, {0, 0, param->game.width, param->game.height}, TILED_MODE_RANDOM); + tiledbg = new Tiledbg(renderer, asset, {0, 0, param.game.width, param.game.height}, TILED_MODE_RANDOM); - gameLogo = new GameLogo(renderer, screen, asset, param, param->game.gameArea.centerX, param->title.titleCCPosition); + gameLogo = new GameLogo(renderer, screen, asset, param.game.gameArea.centerX, param.title.titleCCPosition); gameLogo->enable(); - defineButtons = new DefineButtons(input, text2, param, options, section); + defineButtons = new DefineButtons(input, text2, options, section); // Inicializa los valores init(); @@ -66,7 +66,7 @@ void Title::init() ticksSpeed = 15; fade->setColor(fadeColor.r, fadeColor.g, fadeColor.b); fade->setType(FADE_RANDOM_SQUARE); - fade->setPost(param->fade.postDuration); + fade->setPost(param.fade.postDuration); demo = true; numControllers = input->getNumControllers(); } @@ -137,7 +137,7 @@ void Title::update() // Actualiza el mosaico de fondo tiledbg->update(); - if (counter == param->title.titleDuration) + if (counter == param.title.titleDuration) { fade->activate(); postFade = -1; @@ -167,17 +167,17 @@ void Title::render() // 'PULSA 1P o 2P PARA JUGAR' if (counter % 50 > 14 && !defineButtons->isEnabled()) { - text1->writeDX(TXT_CENTER | TXT_SHADOW, param->game.gameArea.centerX, param->title.pressStartPosition, lang::getText(23), 1, noColor, 1, shadow); + text1->writeDX(TXT_CENTER | TXT_SHADOW, param.game.gameArea.centerX, param.title.pressStartPosition, lang::getText(23), 1, noColor, 1, shadow); } // Mini logo - const int pos1 = (param->game.height / 5 * 4) + BLOCK; + const int pos1 = (param.game.height / 5 * 4) + BLOCK; const int pos2 = pos1 + miniLogoSprite->getHeight() + 3; miniLogoSprite->setPosY(pos1); miniLogoSprite->render(); // Texto con el copyright - text1->writeDX(TXT_CENTER | TXT_SHADOW, param->game.gameArea.centerX, pos2, TEXT_COPYRIGHT, 1, noColor, 1, shadow); + text1->writeDX(TXT_CENTER | TXT_SHADOW, param.game.gameArea.centerX, pos2, TEXT_COPYRIGHT, 1, noColor, 1, shadow); } // Define Buttons diff --git a/source/title.h b/source/title.h index b4da406..151f3cb 100644 --- a/source/title.h +++ b/source/title.h @@ -72,7 +72,6 @@ private: Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa int postFade; // Opción a realizar cuando termina el fundido options_t *options; // Opciones del programa - param_t *param; // Puntero con todos los parametros del programa int numControllers; // Número de mandos conectados // Inicializa los valores de las variables @@ -104,7 +103,7 @@ private: public: // Constructor - Title(Screen *screen, Asset *asset, Input *input, options_t *options, param_t *param, section_t *section, JA_Music_t *music); + Title(Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music); // Destructor ~Title();