diff --git a/source/game.cpp b/source/game.cpp index 7cc7b18..cb49473 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -802,10 +802,10 @@ void Game::initEnemyFormations() } } - const Uint16 creationTime = 300; + const int creationTime = 300; int incX = 0; - Uint8 incTime = 0; - Uint8 j = 0; + int incTime = 0; + int j = 0; // #00 - Dos enemigos BALLOON4 uno a cada extremo j = 0; @@ -1094,7 +1094,7 @@ void Game::initEnemyFormations() incTime = 0; for (int i = 0; i < enemyFormation[j].numberOfEnemies; i++) { - Uint8 half = enemyFormation[j].numberOfEnemies / 2; + const int half = enemyFormation[j].numberOfEnemies / 2; if (i < half) { enemyFormation[j].init[i].x = x4_0 + (i * incX); @@ -1117,7 +1117,7 @@ void Game::initEnemyFormations() incTime = 3; for (int i = 0; i < enemyFormation[j].numberOfEnemies; i++) { - Uint8 half = enemyFormation[j].numberOfEnemies / 2; + const int half = enemyFormation[j].numberOfEnemies / 2; if (i < half) { enemyFormation[j].init[i].x = x2_0 + (i * incX); @@ -1141,7 +1141,7 @@ void Game::initEnemyFormations() incTime = 10; for (int i = 0; i < enemyFormation[j].numberOfEnemies; i++) { - Uint8 half = enemyFormation[j].numberOfEnemies / 2; + const int half = enemyFormation[j].numberOfEnemies / 2; if (i < half) { enemyFormation[j].init[i].x = x3_0 + (i * incX); @@ -1165,7 +1165,7 @@ void Game::initEnemyFormations() incTime = 10; for (int i = 0; i < enemyFormation[j].numberOfEnemies; i++) { - Uint8 half = enemyFormation[j].numberOfEnemies / 2; + const int half = enemyFormation[j].numberOfEnemies / 2; if (i < half) { enemyFormation[j].init[i].x = x3_0 + (i * incX); @@ -1189,7 +1189,7 @@ void Game::initEnemyFormations() incTime = 5; for (int i = 0; i < enemyFormation[j].numberOfEnemies; i++) { - Uint8 half = enemyFormation[j].numberOfEnemies / 2; + const int half = enemyFormation[j].numberOfEnemies / 2; if (i < half) { enemyFormation[j].init[i].x = x1_50; @@ -1213,7 +1213,7 @@ void Game::initEnemyFormations() incTime = 5; for (int i = 0; i < enemyFormation[j].numberOfEnemies; i++) { - Uint8 half = enemyFormation[j].numberOfEnemies / 2; + const int half = enemyFormation[j].numberOfEnemies / 2; if (i < half) { enemyFormation[j].init[i].x = x1_50 + 20; @@ -1502,7 +1502,7 @@ void Game::deployEnemyFormation() powerBallCounter > 0 ? powerBallCounter-- : powerBallCounter = 0; // Elige una formación enemiga la azar - Uint8 set = (rand() % 10); + int set = rand() % 10; // Evita repetir la ultima formación enemiga desplegada if (set == lastEnemyDeploy) @@ -1510,7 +1510,7 @@ void Game::deployEnemyFormation() lastEnemyDeploy = set; - const Uint8 numEnemies = stage[currentStage].enemyPool->set[set]->numberOfEnemies; + const int numEnemies = stage[currentStage].enemyPool->set[set]->numberOfEnemies; for (int i = 0; i < numEnemies; ++i) { createBalloon(stage[currentStage].enemyPool->set[set]->init[i].x, @@ -1527,7 +1527,7 @@ void Game::deployEnemyFormation() } // Aumenta el poder de la fase -void Game::increaseStageCurrentPower(Uint8 power) +void Game::increaseStageCurrentPower(int power) { stage[currentStage].currentPower += power; } @@ -1666,7 +1666,7 @@ void Game::updateDeath() if ((deathCounter == 250) || (deathCounter == 200) || (deathCounter == 180) || (deathCounter == 120) || (deathCounter == 60)) { // Hace sonar aleatoriamente uno de los 4 sonidos de burbujas - const Uint8 index = rand() % 4; + const int index = rand() % 4; JA_Sound_t *sound[4] = {bubble1Sound, bubble2Sound, bubble3Sound, bubble4Sound}; JA_PlaySound(sound[index], 0); } @@ -1704,12 +1704,12 @@ void Game::renderBalloons() } // Crea un globo nuevo en el vector de globos -Uint8 Game::createBalloon(float x, int y, Uint8 kind, float velx, float speed, Uint16 creationtimer) +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], renderer); balloons.push_back(b); - return (Uint8)(balloons.size() - 1); + return (int)(balloons.size() - 1); } // Crea una PowerBall @@ -1848,7 +1848,7 @@ void Game::popBalloon(Balloon *balloon) increaseStageCurrentPower(1); balloonsPopped++; - const Uint8 kind = balloon->getKind(); + const int kind = balloon->getKind(); switch (kind) { // Si es del tipo más pequeño, simplemente elimina el globo @@ -1904,7 +1904,7 @@ void Game::popBalloon(Balloon *balloon) void Game::destroyBalloon(Balloon *balloon) { int score = 0; - Uint8 power = 0; + int power = 0; // Calcula la puntuación y el poder que generaria el globo en caso de romperlo a él y a sus hijos switch (balloon->getSize()) @@ -1985,7 +1985,7 @@ void Game::destroyAllBalloons() } // Detiene todos los globos -void Game::stopAllBalloons(Uint16 time) +void Game::stopAllBalloons(int time) { for (auto balloon : balloons) { @@ -2011,9 +2011,9 @@ void Game::startAllBalloons() } // Obtiene el número de globos activos -Uint8 Game::countBalloons() +int Game::countBalloons() { - Uint8 num = 0; + int num = 0; for (auto balloon : balloons) { @@ -2158,7 +2158,7 @@ void Game::checkBulletBalloonCollision() bullet->disable(); // Suelta el item en caso de que salga uno - const Uint8 droppeditem = dropItem(); + const int droppeditem = dropItem(); // if ((droppeditem != NO_KIND) && !(demo.enabled) && !(demo.recording)) if ((droppeditem != NO_KIND) && !(demo.recording)) { @@ -2209,7 +2209,7 @@ void Game::renderBullets() } // Crea un objeto bala -void Game::createBullet(int x, int y, Uint8 kind, bool poweredUp, int owner) +void Game::createBullet(int x, int y, int kind, bool poweredUp, int owner) { Bullet *b = new Bullet(x, y, kind, poweredUp, owner, bulletTexture, renderer); bullets.push_back(b); @@ -2258,10 +2258,10 @@ void Game::renderItems() } // Devuelve un item al azar y luego segun sus probabilidades -Uint8 Game::dropItem() +int Game::dropItem() { - const Uint8 luckyNumber = rand() % 100; - const Uint8 item = rand() % 6; + const int luckyNumber = rand() % 100; + const int item = rand() % 6; switch (item) { @@ -2334,9 +2334,9 @@ Uint8 Game::dropItem() } // Crea un objeto item -void Game::createItem(Uint8 kind, float x, float y) +void Game::createItem(int kind, float x, float y) { - Item *item = new Item(kind, x, y, itemTextures[kind], itemAnimations[kind], renderer); + Item *item = new Item(kind, x, y, itemTextures[kind - 1], itemAnimations[kind - 1], renderer); items.push_back(item); } @@ -2481,7 +2481,7 @@ void Game::evaluateAndSetMenace() } // Obtiene el valor de la variable -Uint8 Game::getMenace() +int Game::getMenace() { return menaceCurrent; } @@ -2499,13 +2499,13 @@ bool Game::isTimeStopped() } // Establece el valor de la variable -void Game::setTimeStoppedCounter(Uint16 value) +void Game::setTimeStoppedCounter(int value) { timeStoppedCounter = value; } // Incrementa el valor de la variable -void Game::incTimeStoppedCounter(Uint16 value) +void Game::incTimeStoppedCounter(int value) { timeStoppedCounter += value; } @@ -2749,7 +2749,7 @@ void Game::updateMenace() } const float percent = stage[currentStage].currentPower / stage[currentStage].powerToComplete; - const Uint8 difference = stage[currentStage].maxMenace - stage[currentStage].minMenace; + const int difference = stage[currentStage].maxMenace - stage[currentStage].minMenace; // Aumenta el nivel de amenaza en función de la puntuación menaceThreshold = stage[currentStage].minMenace + (difference * percent); diff --git a/source/game.h b/source/game.h index 8d7bf4f..41aba01 100644 --- a/source/game.h +++ b/source/game.h @@ -56,16 +56,16 @@ class Game private: struct enemyInits_t { - int x; // Posición en el eje X donde crear al enemigo - int y; // Posición en el eje Y donde crear al enemigo - float velX; // Velocidad inicial en el eje X - Uint8 kind; // Tipo de enemigo - Uint16 creationCounter; // Temporizador para la creación del enemigo + int x; // Posición en el eje X donde crear al enemigo + int y; // Posición en el eje Y donde crear al enemigo + float velX; // Velocidad inicial en el eje X + int kind; // Tipo de enemigo + int creationCounter; // Temporizador para la creación del enemigo }; struct enemyFormation_t // Contiene la información de una formación enemiga { - Uint8 numberOfEnemies; // Cantidad de enemigos que forman la formación + int numberOfEnemies; // Cantidad de enemigos que forman la formación enemyInits_t init[MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION]; // Vector con todas las inicializaciones de los enemigos de la formación }; @@ -77,11 +77,11 @@ private: struct stage_t // Contiene todas las variables relacionadas con una fase { enemyPool_t *enemyPool; // El conjunto de formaciones enemigas de la fase - Uint16 currentPower; // Cantidad actual de poder - Uint16 powerToComplete; // Cantidad de poder que se necesita para completar la fase - Uint8 maxMenace; // Umbral máximo de amenaza de la fase - Uint8 minMenace; // Umbral mínimo de amenaza de la fase - Uint8 number; // Número de fase + int currentPower; // Cantidad actual de poder + int powerToComplete; // Cantidad de poder que se necesita para completar la fase + int maxMenace; // Umbral máximo de amenaza de la fase + int minMenace; // Umbral mínimo de amenaza de la fase + int number; // Número de fase }; struct helper_t @@ -174,41 +174,41 @@ private: // Variables Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa - Uint8 ticksSpeed; // Velocidad a la que se repiten los bucles del programa + Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 hiScore; // Puntuación máxima bool hiScoreAchieved; // Indica si se ha superado la puntuación máxima std::string hiScoreName; // Nombre del jugador que ostenta la máxima puntuación stage_t stage[10]; // Variable con los datos de cada pantalla - Uint8 currentStage; // Indica la fase actual - Uint8 stageBitmapCounter; // Contador para el tiempo visible del texto de Stage + int currentStage; // Indica la fase actual + int stageBitmapCounter; // Contador para el tiempo visible del texto de Stage float stageBitmapPath[STAGE_COUNTER]; // Vector con los puntos Y por donde se desplaza el texto float getReadyBitmapPath[STAGE_COUNTER]; // Vector con los puntos X por donde se desplaza el texto - Uint16 deathCounter; // Contador para la animación de muerte del jugador - Uint8 menaceCurrent; // Nivel de amenaza actual - Uint8 menaceThreshold; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el número de globos + int deathCounter; // Contador para la animación de muerte del jugador + int menaceCurrent; // Nivel de amenaza actual + int menaceThreshold; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el número de globos bool timeStopped; // Indica si el tiempo está detenido - Uint16 timeStoppedCounter; // Temporizador para llevar la cuenta del tiempo detenido + int timeStoppedCounter; // Temporizador para llevar la cuenta del tiempo detenido Uint32 counter; // Contador para el juego Uint32 scoreDataFile[TOTAL_SCORE_DATA]; // Datos del fichero de puntos - Uint16 balloonsPopped; // Lleva la cuenta de los globos explotados - Uint8 lastEnemyDeploy; // Guarda cual ha sido la última formación desplegada para no repetir; + int balloonsPopped; // Lleva la cuenta de los globos explotados + int lastEnemyDeploy; // Guarda cual ha sido la última formación desplegada para no repetir; int enemyDeployCounter; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero float enemySpeed; // Velocidad a la que se mueven los enemigos float defaultEnemySpeed; // Velocidad base de los enemigos, sin incrementar helper_t helper; // Variable para gestionar las ayudas bool powerBallEnabled; // Indica si hay una powerball ya activa - Uint8 powerBallCounter; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra + int powerBallCounter; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra bool coffeeMachineEnabled; // Indica si hay una máquina de café en el terreno de juego bool gameCompleted; // Indica si se ha completado la partida, llegando al final de la ultima pantalla int gameCompletedCounter; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más enemigos - Uint8 difficulty; // Dificultad del juego + int difficulty; // Dificultad del juego float difficultyScoreMultiplier; // Multiplicador de puntos en función de la dificultad color_t difficultyColor; // Color asociado a la dificultad options_t *options; // Variable con todas las opciones del programa param_t *param; // Puntero con todos los parametros del programa 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 - Uint8 lastStageReached; // Contiene el número de la última pantalla que se ha alcanzado + 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 bool paused; // Indica si el juego está pausado (no se deberia de poder utilizar en el modo arcade) @@ -254,7 +254,7 @@ private: void deployEnemyFormation(); // Aumenta el poder de la fase - void increaseStageCurrentPower(Uint8 power); + void increaseStageCurrentPower(int power); // Establece el valor de la variable void setHiScore(Uint32 score); @@ -281,7 +281,7 @@ private: void renderBalloons(); // Crea un globo nuevo en el vector de globos - Uint8 createBalloon(float x, int y, Uint8 kind, float velx, float speed, Uint16 stoppedcounter); + int createBalloon(float x, int y, int kind, float velx, float speed, int stoppedcounter); // Crea una PowerBall void createPowerBall(); @@ -311,13 +311,13 @@ private: void destroyAllBalloons(); // Detiene todos los globos - void stopAllBalloons(Uint16 time); + void stopAllBalloons(int time); // Pone en marcha todos los globos void startAllBalloons(); // Obtiene el número de globos activos - Uint8 countBalloons(); + int countBalloons(); // Vacia el vector de globos void freeBalloons(); @@ -338,7 +338,7 @@ private: void renderBullets(); // Crea un objeto bala - void createBullet(int x, int y, Uint8 kind, bool poweredUp, int owner); + void createBullet(int x, int y, int kind, bool poweredUp, int owner); // Vacia el vector de balas void freeBullets(); @@ -350,10 +350,10 @@ private: void renderItems(); // Devuelve un item en función del azar - Uint8 dropItem(); + int dropItem(); // Crea un objeto item - void createItem(Uint8 kind, float x, float y); + void createItem(int kind, float x, float y); // Vacia el vector de items void freeItems(); @@ -380,7 +380,7 @@ private: void evaluateAndSetMenace(); // Obtiene el valor de la variable - Uint8 getMenace(); + int getMenace(); // Establece el valor de la variable void setTimeStopped(bool value); @@ -389,10 +389,10 @@ private: bool isTimeStopped(); // Establece el valor de la variable - void setTimeStoppedCounter(Uint16 value); + void setTimeStoppedCounter(int value); // Incrementa el valor de la variable - void incTimeStoppedCounter(Uint16 value); + void incTimeStoppedCounter(int value); // Actualiza la variable EnemyDeployCounter void updateEnemyDeployCounter(); diff --git a/source/item.cpp b/source/item.cpp index e6f67a0..834837d 100644 --- a/source/item.cpp +++ b/source/item.cpp @@ -2,7 +2,7 @@ #include "item.h" // Constructor -Item::Item(Uint8 kind, float x, float y, Texture *texture, std::vector *animation, SDL_Renderer *renderer) +Item::Item(int kind, float x, float y, Texture *texture, std::vector *animation, SDL_Renderer *renderer) { sprite = new AnimatedSprite(texture, renderer, "", animation); diff --git a/source/item.h b/source/item.h index 0d74777..396d9b0 100644 --- a/source/item.h +++ b/source/item.h @@ -8,12 +8,12 @@ #define ITEM_H // Tipos de objetos -#define ITEM_POINTS_1_DISK 0 -#define ITEM_POINTS_2_GAVINA 1 -#define ITEM_POINTS_3_PACMAR 2 -#define ITEM_CLOCK 3 -#define ITEM_COFFEE 4 -#define ITEM_COFFEE_MACHINE 5 +#define ITEM_POINTS_1_DISK 1 +#define ITEM_POINTS_2_GAVINA 2 +#define ITEM_POINTS_3_PACMAR 3 +#define ITEM_CLOCK 4 +#define ITEM_COFFEE 5 +#define ITEM_COFFEE_MACHINE 6 // Clase Item class Item @@ -25,14 +25,14 @@ private: // Variables float posX; // Posición X del objeto float posY; // Posición Y del objeto - Uint8 width; // Ancho del objeto - Uint8 height; // Alto del objeto + int width; // Ancho del objeto + int height; // Alto del objeto float velX; // Velocidad en el eje X float velY; // Velocidad en el eje Y float accelX; // Aceleración en el eje X float accelY; // Aceleración en el eje Y bool floorCollision; // Indica si el objeto colisiona con el suelo - Uint8 kind; // Especifica el tipo de objeto que es + int kind; // Especifica el tipo de objeto que es bool enabled; // Especifica si el objeto está habilitado circle_t collider; // Circulo de colisión del objeto @@ -41,11 +41,12 @@ private: // Actualiza la posición y estados del objeto void move(); + public: Uint16 timeToLive; // Temporizador con el tiempo que el objeto está presente // Constructor - Item(Uint8 kind, float x, float y, Texture *texture, std::vector *animation, SDL_Renderer *renderer); + Item(int kind, float x, float y, Texture *texture, std::vector *animation, SDL_Renderer *renderer); // Destructor ~Item(); @@ -56,7 +57,6 @@ public: // Pinta el objeto en la pantalla void render(); - // Pone a cero todos los valores del objeto void disable(); diff --git a/source/player.cpp b/source/player.cpp index 350a96e..d23667a 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -94,7 +94,7 @@ void Player::init() } // Actua en consecuencia de la entrada recibida -void Player::setInput(Uint8 input) +void Player::setInput(int input) { switch (input) { @@ -208,7 +208,7 @@ void Player::render() } // Establece el estado del jugador cuando camina -void Player::setWalkingStatus(Uint8 status) +void Player::setWalkingStatus(int status) { // Si cambiamos de estado, reiniciamos la animación if (statusWalking != status) @@ -218,7 +218,7 @@ void Player::setWalkingStatus(Uint8 status) } // Establece el estado del jugador cuando dispara -void Player::setFiringStatus(Uint8 status) +void Player::setFiringStatus(int status) { // Si cambiamos de estado, reiniciamos la animación if (statusFiring != status) @@ -546,7 +546,7 @@ void Player::disableInput() } // Devuelve el número de cafes actuales -Uint8 Player::getCoffees() +int Player::getCoffees() { return coffees; } diff --git a/source/player.h b/source/player.h index 0dfe5c8..2808e43 100644 --- a/source/player.h +++ b/source/player.h @@ -43,8 +43,8 @@ private: float defaultPosX; // Posición inicial para el jugador int defaultPosY; // Posición inicial para el jugador - Uint8 width; // Anchura - Uint8 height; // Altura + int width; // Anchura + int height; // Altura float velX; // Cantidad de pixeles a desplazarse en el eje X int velY; // Cantidad de pixeles a desplazarse en el eje Y @@ -55,13 +55,13 @@ private: Uint32 score; // Puntos del jugador float scoreMultiplier; // Multiplicador de puntos - Uint8 statusWalking; // Estado del jugador - Uint8 statusFiring; // Estado del jugador + int statusWalking; // Estado del jugador + int statusFiring; // Estado del jugador bool invulnerable; // Indica si el jugador es invulnerable Uint16 invulnerableCounter; // Contador para la invulnerabilidad bool extraHit; // Indica si el jugador tiene un toque extra - Uint8 coffees; // Indica cuantos cafes lleva acumulados + int coffees; // Indica cuantos cafes lleva acumulados bool powerUp; // Indica si el jugador tiene activo el modo PowerUp Uint16 powerUpCounter; // Temporizador para el modo PowerUp bool input; // Indica si puede recibir ordenes de entrada @@ -98,16 +98,16 @@ public: void setPlayerTextures(std::vector texture); // Actua en consecuencia de la entrada recibida - void setInput(Uint8 input); + void setInput(int input); // Mueve el jugador a la posición y animación que le corresponde void move(); // Establece el estado del jugador - void setWalkingStatus(Uint8 status); + void setWalkingStatus(int status); // Establece el estado del jugador - void setFiringStatus(Uint8 status); + void setFiringStatus(int status); // Establece la animación correspondiente al estado void setAnimation(); @@ -203,7 +203,7 @@ public: void disableInput(); // Devuelve el número de cafes actuales - Uint8 getCoffees(); + int getCoffees(); // Obtiene el circulo de colisión circle_t &getCollider();