From f2cc0dc35251800068304e0c68ac1583b2281be5 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sat, 28 Sep 2024 10:16:35 +0200 Subject: [PATCH] Eliminat "const.h" --- source/balloon.cpp | 13 ++++++------- source/bullet.cpp | 14 +++++++------- source/bullet.h | 1 + source/const.h | 29 ----------------------------- source/define_buttons.h | 1 - source/director.cpp | 1 - source/director.h | 1 - source/enemy_formations.cpp | 8 ++++---- source/enemy_formations.h | 1 - source/fade.cpp | 1 - source/game.cpp | 8 ++++---- source/game.h | 1 - source/game_logo.h | 1 - source/hiscore_table.h | 1 - source/instructions.h | 1 - source/intro.h | 1 - source/item.cpp | 12 ++++++------ source/item.h | 1 + source/logo.h | 1 - source/options.h | 1 - source/param.h | 1 - source/player.cpp | 6 +++--- source/scoreboard.h | 1 - source/screen.h | 1 - source/tiledbg.h | 1 - source/title.h | 21 ++++++++++----------- source/utils.cpp | 13 +++++++++++++ source/utils.h | 23 +++++++++++++++++++---- 28 files changed, 74 insertions(+), 91 deletions(-) delete mode 100644 source/const.h diff --git a/source/balloon.cpp b/source/balloon.cpp index 7c842f5..de9b904 100644 --- a/source/balloon.cpp +++ b/source/balloon.cpp @@ -1,5 +1,4 @@ #include "balloon.h" -#include "const.h" #include "param.h" // Constructor @@ -281,9 +280,9 @@ void Balloon::allignTo(int x) { posX = float(x - (width / 2)); - if (posX < PLAY_AREA_LEFT) + if (posX < param.game.playArea.rect.x) { - posX = PLAY_AREA_LEFT + 1; + posX = param.game.playArea.rect.x + 1; } else if ((posX + width) > param.game.playArea.rect.w) { @@ -347,7 +346,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 < param.game.playArea.rect.x) || (posX + width > param.game.playArea.rect.w)) { // Corrige posición posX -= (velX * speed); @@ -369,10 +368,10 @@ void Balloon::move() posY += (velY * speed); // Si se sale por arriba - if (posY < PLAY_AREA_TOP) + if (posY < param.game.playArea.rect.y) { // Corrige - posY = PLAY_AREA_TOP; + posY = param.game.playArea.rect.y; // Invierte sentido velY = -velY; @@ -508,7 +507,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 < param.game.playArea.rect.x) || (posX > (param.game.playArea.rect.w - width))) { // Corrige y cambia el sentido de la velocidad posX -= velX; diff --git a/source/bullet.cpp b/source/bullet.cpp index 335a215..98411de 100644 --- a/source/bullet.cpp +++ b/source/bullet.cpp @@ -1,5 +1,5 @@ -#include "const.h" #include "bullet.h" +#include "param.h" // Constructor Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, SDL_Rect *playArea, Texture *texture) @@ -108,10 +108,10 @@ Uint8 Bullet::move() posX += velX; // Si el objeto se sale del area de juego por los laterales - if ((posX < PLAY_AREA_LEFT - width) || (posX > playArea->w)) + if ((posX < param.game.playArea.rect.x - width) || (posX > playArea->w)) { // Se deshabilita - kind = NO_KIND; + kind = BULLET_NULL; // Mensaje de salida msg = BULLET_MOVE_OUT; @@ -121,10 +121,10 @@ Uint8 Bullet::move() posY += int(velY); // Si el objeto se sale del area de juego por la parte superior - if (posY < PLAY_AREA_TOP - height) + if (posY < param.game.playArea.rect.y - height) { // Se deshabilita - kind = NO_KIND; + kind = BULLET_NULL; // Mensaje de salida msg = BULLET_MOVE_OUT; @@ -143,7 +143,7 @@ Uint8 Bullet::move() // Comprueba si el objeto está habilitado bool Bullet::isEnabled() { - if (kind == NO_KIND) + if (kind == BULLET_NULL) { return false; } @@ -156,7 +156,7 @@ bool Bullet::isEnabled() // Deshabilita el objeto void Bullet::disable() { - kind = NO_KIND; + kind = BULLET_NULL; } // Obtiene el valor de la variable diff --git a/source/bullet.h b/source/bullet.h index 8418ca2..267dd62 100644 --- a/source/bullet.h +++ b/source/bullet.h @@ -8,6 +8,7 @@ #define BULLET_UP 1 #define BULLET_LEFT 2 #define BULLET_RIGHT 3 +#define BULLET_NULL 4 // Tipos de retorno de la funcion move de la bala #define BULLET_MOVE_OK 0 diff --git a/source/const.h b/source/const.h deleted file mode 100644 index e21fdb8..0000000 --- a/source/const.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include -#include "utils.h" - -// Tamaño de bloque -#define BLOCK 8 - -// Para mejor visibilidad -#define PLAY_AREA_LEFT 0 -#define PLAY_AREA_TOP 0 - - - -// Ningun tipo -#define NO_KIND 0 - -// Colores -const color_t bgColor = {0x27, 0x27, 0x36}; -const color_t noColor = {0xFF, 0xFF, 0xFF}; -const color_t shdwTxtColor = {0x43, 0x43, 0x4F}; -const color_t separatorColor = {0x0D, 0x1A, 0x2B}; -const color_t scoreboardColor = {0x2E, 0x3F, 0x47}; -const color_t difficultyEasyColor = {0x4B, 0x69, 0x2F}; -const color_t difficultyNormalColor = {0xFF, 0x7A, 0x00}; -const color_t difficultyHardColor = {0x76, 0x42, 0x8A}; -const color_t flashColor = {0xFF, 0xFF, 0xFF}; -const color_t fadeColor = {0x27, 0x27, 0x36}; -const color_t orangeColor = {0xFF, 0x7A, 0x00}; \ No newline at end of file diff --git a/source/define_buttons.h b/source/define_buttons.h index 68fbfbc..8930868 100644 --- a/source/define_buttons.h +++ b/source/define_buttons.h @@ -3,7 +3,6 @@ #include #include "input.h" #include "text.h" -#include "const.h" #include "lang.h" struct db_button_t diff --git a/source/director.cpp b/source/director.cpp index 6c66954..f2ba9dd 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -1,6 +1,5 @@ #include "director.h" #include "utils.h" -#include "const.h" #include "options.h" #include "section.h" #include diff --git a/source/director.h b/source/director.h index 32fc91f..25fb694 100644 --- a/source/director.h +++ b/source/director.h @@ -7,7 +7,6 @@ #include "screen.h" #include "text.h" #include "utils.h" -#include "const.h" #include "fade.h" #include "game.h" #include "intro.h" diff --git a/source/enemy_formations.cpp b/source/enemy_formations.cpp index f7e831b..21e7645 100644 --- a/source/enemy_formations.cpp +++ b/source/enemy_formations.cpp @@ -18,19 +18,19 @@ EnemyFormations::~EnemyFormations() void EnemyFormations::initEnemyFormations() { const int y4 = - BLOCK; - const int x4_0 = PLAY_AREA_LEFT; + const int x4_0 = param.game.playArea.rect.x; 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_0 = param.game.playArea.rect.x; 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_0 = param.game.playArea.rect.x; 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_0 = param.game.playArea.rect.x; const int x1_50 = param.game.playArea.centerX - (BALLOON_WIDTH_1 / 2); const int x1_100 = param.game.playArea.rect.w - BALLOON_WIDTH_1; diff --git a/source/enemy_formations.h b/source/enemy_formations.h index 5a3b986..aa40c9e 100644 --- a/source/enemy_formations.h +++ b/source/enemy_formations.h @@ -2,7 +2,6 @@ #include #include "utils.h" -#include "const.h" #include "balloon.h" #define NUMBER_OF_ENEMY_FORMATIONS 100 diff --git a/source/fade.cpp b/source/fade.cpp index 4d60c46..3cab337 100644 --- a/source/fade.cpp +++ b/source/fade.cpp @@ -1,5 +1,4 @@ #include "fade.h" -#include "const.h" #include "param.h" #include diff --git a/source/game.cpp b/source/game.cpp index c518f94..d6fad5d 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -985,7 +985,7 @@ void Game::createPowerBall() const int values = 6; const int posY = -BLOCK; - const int left = PLAY_AREA_LEFT; + const int left = param.game.playArea.rect.x; const int center = param.game.playArea.centerX - (BALLOON_WIDTH_4 / 2); const int right = param.game.playArea.rect.w - BALLOON_WIDTH_4; @@ -1416,7 +1416,7 @@ void Game::checkBulletBalloonCollision() // Suelta el item si se da el caso const int droppeditem = dropItem(); - if ((droppeditem != NO_KIND) && !(demo.recording)) + if ((droppeditem != ITEM_NULL) && !(demo.recording)) { if (droppeditem != ITEM_COFFEE_MACHINE) { @@ -1596,7 +1596,7 @@ int Game::dropItem() break; } - return NO_KIND; + return ITEM_NULL; } // Crea un objeto item @@ -2460,7 +2460,7 @@ void Game::initPaths() // Letrero de GetReady const int size = textNokiaBig2->lenght(lang::getText(75), -2); - const float start1 = PLAY_AREA_LEFT - size; + const float start1 = param.game.playArea.rect.x - size; const float finish1 = param.game.playArea.centerX - (size / 2); const float start2 = finish1; diff --git a/source/game.h b/source/game.h index 5490a18..aaaae20 100644 --- a/source/game.h +++ b/source/game.h @@ -12,7 +12,6 @@ #include "sprite.h" #include "text.h" #include "utils.h" -#include "const.h" #include "fade.h" #include "item.h" #include "player.h" diff --git a/source/game_logo.h b/source/game_logo.h index 86f38da..6274f31 100644 --- a/source/game_logo.h +++ b/source/game_logo.h @@ -5,7 +5,6 @@ #include "screen.h" #include "smartsprite.h" #include "jail_audio.h" -#include "const.h" // Clase GameLogo class GameLogo diff --git a/source/hiscore_table.h b/source/hiscore_table.h index b4e5ef7..1167698 100644 --- a/source/hiscore_table.h +++ b/source/hiscore_table.h @@ -8,7 +8,6 @@ #include "sprite.h" #include "text.h" #include "utils.h" -#include "const.h" #include "lang.h" #include "fade.h" #include "background.h" diff --git a/source/instructions.h b/source/instructions.h index 93bfb1f..4702f70 100644 --- a/source/instructions.h +++ b/source/instructions.h @@ -8,7 +8,6 @@ #include "sprite.h" #include "text.h" #include "utils.h" -#include "const.h" #include "lang.h" #include "tiledbg.h" #include "fade.h" diff --git a/source/intro.h b/source/intro.h index db8afff..51f6b48 100644 --- a/source/intro.h +++ b/source/intro.h @@ -8,7 +8,6 @@ #include "smartsprite.h" #include "utils.h" #include "writer.h" -#include "const.h" #include "lang.h" #include #include "section.h" diff --git a/source/item.cpp b/source/item.cpp index 1e080e8..3fa5c9f 100644 --- a/source/item.cpp +++ b/source/item.cpp @@ -1,5 +1,5 @@ -#include "const.h" #include "item.h" +#include "param.h" // Constructor Item::Item(int kind, float x, float y, SDL_Rect *playArea, Texture *texture, std::vector *animation) @@ -52,9 +52,9 @@ void Item::allignTo(int x) { posX = float(x - (width / 2)); - if (posX < PLAY_AREA_LEFT) + if (posX < param.game.playArea.rect.x) { - posX = PLAY_AREA_LEFT + 1; + posX = param.game.playArea.rect.x + 1; } else if ((posX + width) > playArea->w) { @@ -99,7 +99,7 @@ void Item::move() velY += accelY; // Si queda fuera de pantalla, corregimos su posición y cambiamos su sentido - if ((posX < PLAY_AREA_LEFT) || (posX + width > playArea->w)) + if ((posX < param.game.playArea.rect.x) || (posX + width > playArea->w)) { // Corregir posición posX -= velX; @@ -109,10 +109,10 @@ void Item::move() } // Si se sale por arriba rebota (excepto la maquina de café) - if ((posY < PLAY_AREA_TOP) && !(kind == ITEM_COFFEE_MACHINE)) + if ((posY < param.game.playArea.rect.y) && !(kind == ITEM_COFFEE_MACHINE)) { // Corrige - posY = PLAY_AREA_TOP; + posY = param.game.playArea.rect.y; // Invierte el sentido velY = -velY; diff --git a/source/item.h b/source/item.h index 0e2a76a..6726855 100644 --- a/source/item.h +++ b/source/item.h @@ -11,6 +11,7 @@ #define ITEM_CLOCK 4 #define ITEM_COFFEE 5 #define ITEM_COFFEE_MACHINE 6 +#define ITEM_NULL 7 // Clase Item class Item diff --git a/source/logo.h b/source/logo.h index 345e599..6222292 100644 --- a/source/logo.h +++ b/source/logo.h @@ -3,7 +3,6 @@ #include #include #include "asset.h" -#include "const.h" #include "input.h" #include "jail_audio.h" #include "lang.h" diff --git a/source/options.h b/source/options.h index caf4ced..8ce5260 100644 --- a/source/options.h +++ b/source/options.h @@ -2,7 +2,6 @@ #include #include "utils.h" -#include "const.h" // Variables extern options_t options; diff --git a/source/param.h b/source/param.h index 80e15b3..1b62624 100644 --- a/source/param.h +++ b/source/param.h @@ -2,7 +2,6 @@ #include #include "utils.h" -#include "const.h" extern param_t param; diff --git a/source/player.cpp b/source/player.cpp index 74d5933..f0e7c74 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -1,5 +1,5 @@ -#include "const.h" #include "player.h" +#include "param.h" // Constructor Player::Player(int id, float x, int y, SDL_Rect *playArea, std::vector texture, std::vector *> animations) @@ -114,7 +114,7 @@ void Player::move() posX += velX; // Si el jugador abandona el area de juego por los laterales - if ((posX < PLAY_AREA_LEFT - 5) || (posX + width > playArea->w + 5)) + if ((posX < param.game.playArea.rect.x - 5) || (posX + width > playArea->w + 5)) { // Restaura su posición posX -= velX; @@ -131,7 +131,7 @@ void Player::move() playerSprite->update(); // Si el cadaver abandona el area de juego por los laterales - if ((playerSprite->getPosX() < PLAY_AREA_LEFT) || (playerSprite->getPosX() + width > playArea->w)) + if ((playerSprite->getPosX() < param.game.playArea.rect.x) || (playerSprite->getPosX() + width > playArea->w)) { // Restaura su posición const float vx = playerSprite->getVelX(); diff --git a/source/scoreboard.h b/source/scoreboard.h index 58b053b..87b4dab 100644 --- a/source/scoreboard.h +++ b/source/scoreboard.h @@ -6,7 +6,6 @@ #include "sprite.h" #include "text.h" #include "utils.h" -#include "const.h" #include "lang.h" // Defines diff --git a/source/screen.h b/source/screen.h index e98f1ad..db250fb 100644 --- a/source/screen.h +++ b/source/screen.h @@ -5,7 +5,6 @@ #include "utils.h" #include "notify.h" #include "input.h" -#include "const.h" #include #define SCREEN_FILTER_NEAREST 0 diff --git a/source/tiledbg.h b/source/tiledbg.h index 01f55f9..3f854cc 100644 --- a/source/tiledbg.h +++ b/source/tiledbg.h @@ -4,7 +4,6 @@ #include "asset.h" #include "screen.h" #include "sprite.h" -#include "const.h" // Modos de funcionamiento para el tileado de fondo #define TILED_MODE_CIRCLE 0 diff --git a/source/title.h b/source/title.h index 60b9b4c..dc593f7 100644 --- a/source/title.h +++ b/source/title.h @@ -2,25 +2,24 @@ #include #include "asset.h" +#include "define_buttons.h" +#include "fade.h" +#include "game.h" +#include "game_logo.h" +#include "hiscore_table.h" #include "input.h" +#include "instructions.h" +#include "item.h" #include "jail_audio.h" +#include "lang.h" #include "movingsprite.h" #include "screen.h" +#include "section.h" #include "smartsprite.h" #include "sprite.h" #include "text.h" -#include "utils.h" -#include "const.h" -#include "fade.h" -#include "game.h" -#include "hiscore_table.h" -#include "instructions.h" -#include "item.h" -#include "lang.h" #include "tiledbg.h" -#include "game_logo.h" -#include "define_buttons.h" -#include "section.h" +#include "utils.h" // Textos #define TEXT_COPYRIGHT "@2020,2024 JailDesigner" diff --git a/source/utils.cpp b/source/utils.cpp index 3b5c949..d127696 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -1,6 +1,19 @@ #include "utils.h" #include +// Colores +const color_t bgColor = {0x27, 0x27, 0x36}; +const color_t noColor = {0xFF, 0xFF, 0xFF}; +const color_t shdwTxtColor = {0x43, 0x43, 0x4F}; +const color_t separatorColor = {0x0D, 0x1A, 0x2B}; +const color_t scoreboardColor = {0x2E, 0x3F, 0x47}; +const color_t difficultyEasyColor = {0x4B, 0x69, 0x2F}; +const color_t difficultyNormalColor = {0xFF, 0x7A, 0x00}; +const color_t difficultyHardColor = {0x76, 0x42, 0x8A}; +const color_t flashColor = {0xFF, 0xFF, 0xFF}; +const color_t fadeColor = {0x27, 0x27, 0x36}; +const color_t orangeColor = {0xFF, 0x7A, 0x00}; + // Calcula el cuadrado de la distancia entre dos puntos double distanceSquared(int x1, int y1, int x2, int y2) { diff --git a/source/utils.h b/source/utils.h index 869eb07..6047f91 100644 --- a/source/utils.h +++ b/source/utils.h @@ -1,17 +1,19 @@ #pragma once #include -#include "texture.h" -#include "jail_audio.h" -#include "input.h" #include #include +#include "input.h" +#include "jail_audio.h" // Dificultad del juego #define DIFFICULTY_EASY 0 #define DIFFICULTY_NORMAL 1 #define DIFFICULTY_HARD 2 +// Tamaño de bloque +#define BLOCK 8 + // Estructura para definir un circulo struct circle_t { @@ -288,4 +290,17 @@ JA_Music_t *getMusic(std::vector music, std::string name); hiScoreEntry_t sortHiScoreTable(hiScoreEntry_t entry1, hiScoreEntry_t entry2); // Dibuja un circulo -void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_t radius); \ No newline at end of file +void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_t radius); + +// Colores +extern const color_t bgColor; +extern const color_t noColor; +extern const color_t shdwTxtColor; +extern const color_t separatorColor; +extern const color_t scoreboardColor; +extern const color_t difficultyEasyColor; +extern const color_t difficultyNormalColor; +extern const color_t difficultyHardColor; +extern const color_t flashColor; +extern const color_t fadeColor; +extern const color_t orangeColor; \ No newline at end of file