From 2a303deff1b3330ff50ea04512636b54d1ead217 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 3 Sep 2024 13:59:07 +0200 Subject: [PATCH] Renombradas las variables de param_t --- data/config/param.txt | 36 +++++++------- source/background.cpp | 6 +-- source/common/utils.h | 71 ++++++++++++++++------------ source/define_buttons.cpp | 4 +- source/director.cpp | 12 ++--- source/fade.cpp | 28 +++++------ source/game.cpp | 12 ++--- source/game_logo.cpp | 4 +- source/hiscore_table.cpp | 10 ++-- source/instructions.cpp | 40 ++++++++-------- source/intro.cpp | 8 ++-- source/load_param.cpp | 98 +++++++++++++++++++-------------------- source/logo.cpp | 4 +- source/title.cpp | 12 ++--- 14 files changed, 179 insertions(+), 166 deletions(-) diff --git a/data/config/param.txt b/data/config/param.txt index 9753314..1ac5ea4 100644 --- a/data/config/param.txt +++ b/data/config/param.txt @@ -1,33 +1,33 @@ ## GAME -gameWidth 320 -gameHeight 240 -itemSize 20 +game.width 320 +game.height 256 +game.itemSize 20 ## FADE -numSquaresWidth 160 -numSquaresHeight 120 -fadeRandomSquaresDelay 1 -fadeRandomSquaresMult 500 -fadePostDuration 80 -venetianSize 16 +fade.numSquaresWidth 160 +fade.numSquaresHeight 128 +fade.randomSquaresDelay 1 +fade.randomSquaresMult 500 +fade.postDuration 80 +fade.venetianSize 16 ## SCOREBOARD scoreboard.x 0 -scoreboard.y 200 +scoreboard.y 216 scoreboard.w 320 scoreboard.h 40 ## TITLE -pressStart 170 -titleCounter 800 -arcadeEdition 123 -titleCC 80 +title.pressStartPosition 170 +title.titleDuration 800 +title.arcadeEditionPosition 123 +title.titleCCPosition 80 ## BACKGROUND -backgroundAttenuateColor.r 255 -backgroundAttenuateColor.g 255 -backgroundAttenuateColor.b 255 -backgroundAttenuateColor.a 0 +background.attenuateColor.r 255 +background.attenuateColor.g 255 +background.attenuateColor.b 255 +background.attenuateAlpha 0 ## BALLOONS balloon1.vel 2.75f diff --git a/source/background.cpp b/source/background.cpp index 9da64ca..79fe39b 100644 --- a/source/background.cpp +++ b/source/background.cpp @@ -14,12 +14,12 @@ Background::Background(SDL_Renderer *renderer, Asset *asset, param_t *param) cloudsSpeed = 0; transition = 0; counter = 0; - rect = {0, 0, param->gameWidth, param->gameHeight}; + rect = {0, 0, param->game.width, param->game.height}; srcRect = {playArea.x, rect.h - playArea.h, playArea.w, playArea.h}; dstRect = {0, 0, playArea.w, playArea.h}; base = rect.h; - color = {param->backgroundAttenuateColor.r, param->backgroundAttenuateColor.g, param->backgroundAttenuateColor.b}; - alphaColorText = alphaColorTextTemp = param->backgroundAttenuateAlpha; + color = {param->background.attenuateColor.r, param->background.attenuateColor.g, param->background.attenuateColor.b}; + alphaColorText = alphaColorTextTemp = param->background.attenuateAlpha; // Carga las texturas buildingsTexture = new Texture(renderer, asset->get("game_buildings.png")); diff --git a/source/common/utils.h b/source/common/utils.h index 7156eff..d0179e8 100644 --- a/source/common/utils.h +++ b/source/common/utils.h @@ -169,8 +169,43 @@ struct options_t std::vector controller; // Opciones con las asignaciones del mando para cada jugador }; +// param.game +struct paramGame_t +{ + int width; // Ancho de la resolucion nativa del juego + int height; // Alto de la resolucion nativa del juego + int itemSize; // Tamaño de los items del juego +}; + +// param.fade +struct paramFade_t +{ + 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 + int randomSquaresDelay; // Duración entre cada pintado de cuadrados + int randomSquaresMult; // Cantidad de cuadrados que se pintaran cada vez + int postDuration; // Duración final del fade + int venetianSize; // Altura de los rectangulos para FADE_VENETIAN +}; + +// param.title +struct paramTitle_t +{ + int pressStartPosition; // Posición del texto para empezar a jugar + int titleDuration; // Tiempo de inactividad del titulo + int arcadeEditionPosition; // Posición del bitmap + int titleCCPosition; // Posición del bitmap +}; + +// param.background +struct paramBackground_t +{ + color_t attenuateColor; + int attenuateAlpha; +}; + // Estructura para guardar los parametros de un globo -struct balloon_t +struct paramBalloon_t { float grav; // Aceleración en el eje Y. Modifica la velocidad float vel; // Velocidad inicial que tienen al rebotar contra el suelo @@ -179,34 +214,12 @@ struct balloon_t // Estructura para almacenar todos los parámetros del juego struct param_t { - // GAME - int gameWidth; // Ancho de la resolucion nativa del juego - int gameHeight; // Alto de la resolucion nativa del juego - int itemSize; // Tamaño de los items del juego - - // FADE - 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 - int fadeRandomSquaresDelay; // Duración entre cada pintado de cuadrados - int fadeRandomSquaresMult; // Cantidad de cuadrados que se pintaran cada vez - int fadePostDuration; // Duración final del fade - int venetianSize; // Altura de los rectangulos para FADE_VENETIAN - - // SCOREBOARD - SDL_Rect scoreboard; // Posición y tamaño del marcador - - // TITLE - int pressStart; // Posición del texto para empezar a jugar - int titleCounter; // Tiempo de inactividad del titulo - int arcadeEdition; // Posición del bitmap - int titleCC; // Posición del bitmap - - // BACKGROUND - color_t backgroundAttenuateColor; - int backgroundAttenuateAlpha; - - // BALLOONS - balloon_t balloon1, balloon2, balloon3, balloon4; // Parametros de velocidad y gravedad de cada tipo de globo + paramGame_t game; // Parametros relacionados con el juego + paramFade_t fade; // Parametros para ajustar el fade + SDL_Rect scoreboard; // Posición y tamaño del marcador + paramTitle_t title; // Parametros con ajustes para la sección Title + paramBackground_t background; // Parametros que afectan a la clase Background + paramBalloon_t balloon1, balloon2, balloon3, balloon4; // Parametros de velocidad y gravedad de cada tipo de globo }; // Estructura para almacenar ficheros de sonido y su nombre diff --git a/source/define_buttons.cpp b/source/define_buttons.cpp index ba804db..697cab6 100644 --- a/source/define_buttons.cpp +++ b/source/define_buttons.cpp @@ -12,8 +12,8 @@ DefineButtons::DefineButtons(Input *input, Text *text, param_t *param, options_t // Inicializa variables enabled = false; - x = param->gameWidth / 2; - y = param->pressStart; + x = param->game.width / 2; + y = param->title.pressStartPosition; indexController = 0; indexButton = 0; diff --git a/source/director.cpp b/source/director.cpp index 6f43459..ddd049e 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -224,7 +224,7 @@ bool Director::initSDL() } #endif // Crea la ventana - window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, param->gameWidth * options->video.window.size, param->gameHeight * 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) @@ -261,7 +261,7 @@ bool Director::initSDL() SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF); // Establece el tamaño del buffer de renderizado - SDL_RenderSetLogicalSize(renderer, param->gameWidth, param->gameHeight); + SDL_RenderSetLogicalSize(renderer, param->game.width, param->game.height); // Establece el modo de mezcla SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); @@ -427,10 +427,10 @@ void Director::loadParams() loadParam(param, asset->get("param.txt")); // Modifica las opciones desde el fichero de parametros - options->video.window.width = options->video.window.size * param->gameWidth; - options->video.window.height = options->video.window.size * param->gameHeight; - options->video.gameWidth = param->gameWidth; - options->video.gameHeight = param->gameHeight; + 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 diff --git a/source/fade.cpp b/source/fade.cpp index e4f6830..fb84402 100644 --- a/source/fade.cpp +++ b/source/fade.cpp @@ -10,7 +10,7 @@ Fade::Fade(SDL_Renderer *renderer, param_t *param) this->param = param; // Crea la textura donde dibujar el fade - backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->gameWidth, param->gameHeight); + 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->numSquaresWidth; - numSquaresHeight = param->numSquaresHeight; - fadeRandomSquaresDelay = param->fadeRandomSquaresDelay; - fadeRandomSquaresMult = param->fadeRandomSquaresMult; + 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->gameHeight - (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->gameHeight) + 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->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->gameWidth, 0}; - rect2 = {0, 0, param->gameWidth, 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->gameWidth / numSquaresWidth, param->gameHeight / 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->gameWidth, 0}; + rect1 = {0, 0, param->game.width, 0}; square.clear(); a = 255; // Añade los cuadrados al vector - const int max = param->gameHeight / param->venetianSize; + const int max = param->game.height / param->fade.venetianSize; for (int i = 0; i < max; ++i) { - rect1.y = i * param->venetianSize; + rect1.y = i * param->fade.venetianSize; square.push_back(rect1); } diff --git a/source/game.cpp b/source/game.cpp index cd36f82..5433f6f 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -260,7 +260,7 @@ void Game::init(int playerID) // Inicializa el objeto para el fundido fade->setColor(fadeColor.r, fadeColor.g, fadeColor.b); - fade->setPost(param->fadePostDuration); + fade->setPost(param->fade.postDuration); fade->setType(FADE_VENETIAN); // Con los globos creados, calcula el nivel de amenaza @@ -1651,17 +1651,17 @@ void Game::throwCoffee(int x, int y) ss->setPosX(x - 8); ss->setPosY(y - 8); - ss->setWidth(param->itemSize); - ss->setHeight(param->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->gameHeight + 1); + ss->setDestY(param->game.height + 1); ss->setEnabled(true); ss->setEnabledCounter(1); - ss->setSpriteClip(0, param->itemSize, param->itemSize, param->itemSize); + ss->setSpriteClip(0, param->game.itemSize, param->game.itemSize, param->game.itemSize); ss->setRotate(true); ss->setRotateSpeed(10); ss->setRotateAmount(90.0); @@ -2594,7 +2594,7 @@ void Game::checkEvents() { // CREA UN SPRITE DE 1000 PUNTOS case SDLK_h: - createItemScoreSprite(param->gameWidth / 2, param->gameWidth / 2, n1000Sprite); + createItemScoreSprite(param->game.width / 2, param->game.width / 2, n1000Sprite); break; // CREA UNA POWERBALL diff --git a/source/game_logo.cpp b/source/game_logo.cpp index 47f9df0..2084b56 100644 --- a/source/game_logo.cpp +++ b/source/game_logo.cpp @@ -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->gameWidth - arcadeEditionTexture->getWidth()) / 2, param->arcadeEdition, 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->gameHeight - y; + int despDown = param->game.height - y; return std::max(despUp, despDown); } \ No newline at end of file diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index 1c0a356..7733397 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -22,7 +22,7 @@ HiScoreTable::HiScoreTable(Screen *screen, Asset *asset, Input *input, Lang *lan 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->gameWidth, param->gameHeight); + backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->game.width, param->game.height); SDL_SetTextureBlendMode(backbuffer, SDL_BLENDMODE_BLEND); // Inicializa variables @@ -31,7 +31,7 @@ HiScoreTable::HiScoreTable(Screen *screen, Asset *asset, Input *input, Lang *lan ticksSpeed = 15; counter = 0; counterEnd = 800; - viewArea = {0, 0, param->gameWidth, param->gameHeight}; + viewArea = {0, 0, param->game.width, param->game.height}; fadeMode = FADE_IN; // Inicializa objetos @@ -42,7 +42,7 @@ HiScoreTable::HiScoreTable(Screen *screen, Asset *asset, Input *input, Lang *lan background->setTransition(0.8f); fade->setColor(fadeColor.r, fadeColor.g, fadeColor.b); fade->setType(FADE_RANDOM_SQUARE); - fade->setPost(param->fadePostDuration); + fade->setPost(param->fade.postDuration); fade->setMode(fadeMode); fade->activate(); @@ -106,7 +106,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->gameHeight - 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); @@ -150,7 +150,7 @@ void HiScoreTable::render() background->render(); // Establece la ventana del backbuffer - viewArea.y = std::max(0, param->gameHeight - 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/instructions.cpp b/source/instructions.cpp index c2865d7..2d06564 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -17,15 +17,15 @@ Instructions::Instructions(Screen *screen, Asset *asset, Input *input, Lang *lan // 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->gameWidth, param->gameHeight}, TILED_MODE_STATIC); + tiledbg = new Tiledbg(renderer, asset, {0, 0, param->game.width, param->game.height}, TILED_MODE_STATIC); fade = new Fade(renderer, param); // Crea un backbuffer para el renderizador - backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->gameWidth, param->gameHeight); + 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->gameWidth, param->gameHeight); + 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, Lang *lan ticksSpeed = 15; counter = 0; counterEnd = 700; - view = {0, 0, param->gameWidth, param->gameHeight}; + 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->fadePostDuration); + 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->itemSize, param->itemSize, itemTextures[i]); - sprite->setPos((SDL_Point){spritePos.x, spritePos.y + ((param->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->itemSize, param->itemSize}; + SDL_Rect srcRect = {0, 0, param->game.itemSize, param->game.itemSize}; // Disquito - srcRect.y = param->itemSize * (((counter + 12) / 36) % 2); + srcRect.y = param->game.itemSize * (((counter + 12) / 36) % 2); sprites[0]->setSpriteClip(srcRect); // Gavineixon - srcRect.y = param->itemSize * (((counter + 9) / 36) % 2); + srcRect.y = param->game.itemSize * (((counter + 9) / 36) % 2); sprites[1]->setSpriteClip(srcRect); // Pacmar - srcRect.y = param->itemSize * (((counter + 6) / 36) % 2); + srcRect.y = param->game.itemSize * (((counter + 6) / 36) % 2); sprites[2]->setSpriteClip(srcRect); // Time Stopper - srcRect.y = param->itemSize * (((counter + 3) / 36) % 2); + srcRect.y = param->game.itemSize * (((counter + 3) / 36) % 2); sprites[3]->setSpriteClip(srcRect); // Coffee - srcRect.y = param->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->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->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->gameHeight - 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,7 +166,7 @@ void Instructions::fillTexture() const int l = text->lenght(lang->getText(i)); lenght = l > lenght ? l : lenght; } - const int anchorItem = (param->gameWidth - (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, GAMECANVAS_CENTER_X, firstLine, lang->getText(11), 1, orangeColor, 1, shdwTxtColor); @@ -182,7 +182,7 @@ void Instructions::fillTexture() text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, anchor2, lang->getText(16), 1, orangeColor, 1, shdwTxtColor); const int anchor3 = anchor2 + spacePostHeader; - // const int anchor4 = anchor3 + ((param->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->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->gameHeight - 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/intro.cpp b/source/intro.cpp index c94b052..9605a27 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -46,7 +46,7 @@ Intro::Intro(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *pa bitmaps[0]->setAccelY(0.0f); bitmaps[0]->setSpriteClip(0, 0, 128, 96); - bitmaps[1]->setPosX(param->gameWidth); + bitmaps[1]->setPosX(param->game.width); bitmaps[1]->setPosY(GAMECANVAS_FIRST_QUARTER_Y - 24); bitmaps[1]->setVelX(-1.0f); bitmaps[1]->setVelY(0.0f); @@ -64,7 +64,7 @@ Intro::Intro(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *pa bitmaps[2]->setEnabledCounter(250); bitmaps[3]->setPosX(GAMECANVAS_CENTER_X - 64); - bitmaps[3]->setPosY(param->gameHeight); + bitmaps[3]->setPosY(param->game.height); bitmaps[3]->setVelX(0.0f); bitmaps[3]->setVelY(-0.7f); bitmaps[3]->setAccelX(0.0f); @@ -79,7 +79,7 @@ Intro::Intro(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *pa bitmaps[4]->setAccelY(0.3f); bitmaps[4]->setSpriteClip(0, 192, 128, 96); - bitmaps[5]->setPosX(param->gameWidth); + bitmaps[5]->setPosX(param->game.width); bitmaps[5]->setPosY(GAMECANVAS_FIRST_QUARTER_Y - 24); bitmaps[5]->setVelX(-0.7f); bitmaps[5]->setVelY(0.0f); @@ -93,7 +93,7 @@ Intro::Intro(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *pa { Writer *w = new Writer(text); w->setPosX(BLOCK * 0); - w->setPosY(param->gameHeight - (BLOCK * 6)); + w->setPosY(param->game.height - (BLOCK * 6)); w->setKerning(-1); w->setEnabled(false); w->setEnabledCounter(180); diff --git a/source/load_param.cpp b/source/load_param.cpp index 5fdeef6..766b1d9 100644 --- a/source/load_param.cpp +++ b/source/load_param.cpp @@ -9,30 +9,30 @@ bool setOptions(param_t *param, std::string var, std::string value); void initParam(param_t *param) { // GAME - param->gameWidth = 320; - param->gameHeight = 240; - param->itemSize = 20; + param->game.width = 320; + param->game.height = 240; + param->game.itemSize = 20; // SCOREBOARD param->scoreboard = {0, 200, 320, 40}; // FADE - param->numSquaresWidth = 160; - param->numSquaresHeight = 120; - param->fadeRandomSquaresDelay = 1; - param->fadeRandomSquaresMult = 500; - param->fadePostDuration = 80; - param->venetianSize = 16; + param->fade.numSquaresWidth = 160; + param->fade.numSquaresHeight = 120; + param->fade.randomSquaresDelay = 1; + param->fade.randomSquaresMult = 500; + param->fade.postDuration = 80; + param->fade.venetianSize = 16; // TITLE - param->pressStart = 160; - param->titleCounter = 800; - param->arcadeEdition = 123; - param->titleCC = 11; + param->title.pressStartPosition = 160; + param->title.titleDuration = 800; + param->title.arcadeEditionPosition = 123; + param->title.titleCCPosition = 11; // BACKGROUND - param->backgroundAttenuateColor = {255, 255, 255}; - param->backgroundAttenuateAlpha = 32; + param->background.attenuateColor = {255, 255, 255}; + param->background.attenuateAlpha = 32; // BALLOONS param->balloon1.vel = 2.60f; @@ -139,50 +139,50 @@ bool setOptions(param_t *param, std::string var, std::string value) bool success = true; // GAME - if (var == "gameWidth") + if (var == "game.width") { - param->gameWidth = std::stoi(value); + param->game.width = std::stoi(value); } - else if (var == "gameHeight") + else if (var == "game.height") { - param->gameHeight = std::stoi(value); + param->game.height = std::stoi(value); } - else if (var == "itemSize") + else if (var == "game.itemSize") { - param->itemSize = std::stoi(value); + param->game.itemSize = std::stoi(value); } // FADE - else if (var == "numSquaresWidth") + else if (var == "fade.numSquaresWidth") { - param->numSquaresWidth = std::stoi(value); + param->fade.numSquaresWidth = std::stoi(value); } - else if (var == "numSquaresHeight") + else if (var == "fade.numSquaresHeight") { - param->numSquaresHeight = std::stoi(value); + param->fade.numSquaresHeight = std::stoi(value); } - else if (var == "fadeRandomSquaresDelay") + else if (var == "fade.randomSquaresDelay") { - param->fadeRandomSquaresDelay = std::stoi(value); + param->fade.randomSquaresDelay = std::stoi(value); } - else if (var == "fadeRandomSquaresMult") + else if (var == "fade.randomSquaresMult") { - param->fadeRandomSquaresMult = std::stoi(value); + param->fade.randomSquaresMult = std::stoi(value); } - else if (var == "fadePostDuration") + else if (var == "fade.postDuration") { - param->fadePostDuration = std::stoi(value); + param->fade.postDuration = std::stoi(value); } - else if (var == "venetianSize") + else if (var == "fade.venetianSize") { - param->venetianSize = std::stoi(value); + param->fade.venetianSize = std::stoi(value); } // SCOREBOARD @@ -207,45 +207,45 @@ bool setOptions(param_t *param, std::string var, std::string value) } // TITLE - else if (var == "pressStart") + else if (var == "title.pressStartPosition") { - param->pressStart = std::stoi(value); + param->title.pressStartPosition = std::stoi(value); } - else if (var == "titleCounter") + else if (var == "title.titleDuration") { - param->titleCounter = std::stoi(value); + param->title.titleDuration = std::stoi(value); } - else if (var == "arcadeEdition") + else if (var == "title.arcadeEditionPosition") { - param->arcadeEdition = std::stoi(value); + param->title.arcadeEditionPosition = std::stoi(value); } - else if (var == "titleCC") + else if (var == "title.titleCCPosition") { - param->titleCC = std::stoi(value); + param->title.titleCCPosition = std::stoi(value); } // BACKGROUND - else if (var == "backgroundAttenuateColor.r") + else if (var == "background.attenuateColor.r") { - param->backgroundAttenuateColor.r = std::stoi(value); + param->background.attenuateColor.r = std::stoi(value); } - else if (var == "backgroundAttenuateColor.g") + else if (var == "background.attenuateColor.g") { - param->backgroundAttenuateColor.g = std::stoi(value); + param->background.attenuateColor.g = std::stoi(value); } - else if (var == "backgroundAttenuateColor.b") + else if (var == "background.attenuateColor.b") { - param->backgroundAttenuateColor.b = std::stoi(value); + param->background.attenuateColor.b = std::stoi(value); } - else if (var == "backgroundAttenuateColor.a") + else if (var == "background.attenuateAlpha") { - param->backgroundAttenuateAlpha = std::stoi(value); + param->background.attenuateAlpha = std::stoi(value); } // BALLOON diff --git a/source/logo.cpp b/source/logo.cpp index 64ac74c..bbfbc2b 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -16,7 +16,7 @@ Logo::Logo(Screen *screen, Asset *asset, Input *input, param_t *param, section_t 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->gameWidth - 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; @@ -40,7 +40,7 @@ Logo::Logo(Screen *screen, Asset *asset, Input *input, param_t *param, section_t { Sprite *temp = new Sprite(0, i, jailTexture->getWidth(), 1, jailTexture); temp->setSpriteClip(0, i, jailTexture->getWidth(), 1); - const int posX = (i % 2 == 0) ? param->gameWidth + (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/title.cpp b/source/title.cpp index 9523866..7b6ab45 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -26,9 +26,9 @@ Title::Title(Screen *screen, Asset *asset, Input *input, options_t *options, Lan 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); - tiledbg = new Tiledbg(renderer, asset, {0, 0, param->gameWidth, param->gameHeight}, 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, GAMECANVAS_CENTER_X, param->titleCC); + gameLogo = new GameLogo(renderer, screen, asset, param, GAMECANVAS_CENTER_X, param->title.titleCCPosition); gameLogo->enable(); defineButtons = new DefineButtons(input, text2, param, options, section); @@ -67,7 +67,7 @@ void Title::init() ticksSpeed = 15; fade->setColor(fadeColor.r, fadeColor.g, fadeColor.b); fade->setType(FADE_RANDOM_SQUARE); - fade->setPost(param->fadePostDuration); + fade->setPost(param->fade.postDuration); demo = true; numControllers = input->getNumControllers(); } @@ -145,7 +145,7 @@ void Title::update() // Actualiza el mosaico de fondo tiledbg->update(); - if (counter == param->titleCounter) + if (counter == param->title.titleDuration) { fade->activate(); postFade = 3; @@ -175,11 +175,11 @@ void Title::render() // 'PULSA 1P o 2P PARA JUGAR' if (counter % 50 > 14 && !defineButtons->isEnabled()) { - text1->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, param->pressStart, lang->getText(23), 1, noColor, 1, shadow); + text1->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, param->title.pressStartPosition, lang->getText(23), 1, noColor, 1, shadow); } // Mini logo - const int pos1 = (param->gameHeight / 5 * 4) + BLOCK; + const int pos1 = (param->game.height / 5 * 4) + BLOCK; const int pos2 = pos1 + miniLogoSprite->getHeight() + 3; miniLogoSprite->setPosY(pos1); miniLogoSprite->render();