From 0d8207013c9d300939becdf19bd207a7d320da70 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sun, 30 Jun 2024 20:10:10 +0200 Subject: [PATCH] Eliminados metodos y variables sobrantes de la clase player --- source/game.cpp | 7 +++++-- source/game.h | 2 +- source/player.cpp | 43 +++++++++---------------------------------- source/player.h | 12 +----------- 4 files changed, 16 insertions(+), 48 deletions(-) diff --git a/source/game.cpp b/source/game.cpp index ccda8b3..361b297 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -1,5 +1,7 @@ #include "game.h" +#define DEATH_COUNTER 350 + // Constructor Game::Game(int playerID, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, param_t *param, options_t *options, section_t *section) { @@ -46,7 +48,7 @@ Game::Game(int playerID, int currentStage, SDL_Renderer *renderer, Screen *scree SDL_SetTextureBlendMode(canvas, SDL_BLENDMODE_BLEND); // Inicializa las variables necesarias para la sección 'Game' - init(); + init(playerID); } Game::~Game() @@ -154,7 +156,7 @@ Game::~Game() } // Inicializa las variables necesarias para la sección 'Game' -void Game::init() +void Game::init(int playerID) { ticks = 0; ticksSpeed = 15; @@ -174,6 +176,7 @@ void Game::init() players.push_back(player2); + // Variables relacionadas con la dificultad switch (difficulty) diff --git a/source/game.h b/source/game.h index c517fbb..9b59870 100644 --- a/source/game.h +++ b/source/game.h @@ -225,7 +225,7 @@ private: void checkEvents(); // Inicializa las variables necesarias para la sección 'Game' - void init(); + void init(int playerID); // Carga los recursos necesarios para la sección 'Game' void loadMedia(); diff --git a/source/player.cpp b/source/player.cpp index 88eb2d8..f26ee75 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -39,7 +39,6 @@ void Player::init() posX = defaultPosX; posY = defaultPosY; alive = true; - deathCounter = DEATH_COUNTER; statusWalking = PLAYER_STATUS_WALKING_STOP; statusFiring = PLAYER_STATUS_FIRING_NO; invulnerable = true; @@ -136,7 +135,8 @@ void Player::move() // Si el jugador abandona el area de juego por los laterales if ((posX < PLAY_AREA_LEFT - 5) || (posX + width > PLAY_AREA_RIGHT + 5)) - { // Restaura su posición + { + // Restaura su posición posX -= velX; } @@ -159,7 +159,8 @@ void Player::move() // Si el cadaver abandona el area de juego por los laterales if ((deathSprite->getPosX() < PLAY_AREA_LEFT) || (deathSprite->getPosX() + width > PLAY_AREA_RIGHT)) - { // Restaura su posición + { + // Restaura su posición const float vx = deathSprite->getVelX(); deathSprite->setPosX(deathSprite->getPosX() - vx); @@ -211,7 +212,6 @@ void Player::setWalkingStatus(Uint8 status) if (statusWalking != status) { statusWalking = status; - // legsSprite->setCurrentFrame(0); } } @@ -248,14 +248,16 @@ void Player::setAnimation() legsSprite->setCurrentAnimation(aWalking); legsSprite->setFlip(flipWalk); if (statusFiring == PLAYER_STATUS_FIRING_NO) - { // No esta disparando + { + // No esta disparando bodySprite->setCurrentAnimation(aWalking + aBodyCoffees + aPowerUp); bodySprite->setFlip(flipWalk); headSprite->setCurrentAnimation(aWalking + aHeadCoffees + aPowerUp); headSprite->setFlip(flipWalk); } else - { // Está disparando + { + // Está disparando bodySprite->setCurrentAnimation(aFiring + aBodyCoffees + aPowerUp); bodySprite->setFlip(flipFire); headSprite->setCurrentAnimation(aFiring + aHeadCoffees + aPowerUp); @@ -299,14 +301,7 @@ int Player::getHeight() bool Player::canFire() { // Si el contador a llegado a cero, podemos disparar. En caso contrario decrementamos el contador - if (cooldown > 0) - { - return false; - } - else - { - return true; - } + return cooldown > 0 ? false : true; } // Establece el valor de la variable @@ -341,7 +336,6 @@ void Player::update() updateCooldown(); updatePowerUpCounter(); updateInvulnerableCounter(); - updateDeathCounter(); updatePowerUpHeadOffset(); } @@ -467,18 +461,6 @@ void Player::updateInvulnerableCounter() } } -// Actualiza el valor de la variable -void Player::updateDeathCounter() -{ - if (!alive) - { - if (deathCounter > 0) - { - deathCounter--; - } - } -} - // Obtiene el valor de la variable bool Player::isPowerUp() { @@ -584,13 +566,6 @@ void Player::shiftColliders() Texture *Player::getDeadTexture() { return deathSprite->getTexture(); - ; -} - -// Obtiene el valor de la variable -Uint16 Player::getDeathCounter() -{ - return deathCounter; } // Actualiza el valor de la variable diff --git a/source/player.h b/source/player.h index 6dd576a..e33d019 100644 --- a/source/player.h +++ b/source/player.h @@ -10,9 +10,6 @@ #ifndef PLAYER_H #define PLAYER_H -// Contadores -#define DEATH_COUNTER 350 - // Estados del jugador #define PLAYER_STATUS_WALKING_LEFT 0 #define PLAYER_STATUS_WALKING_RIGHT 1 @@ -61,8 +58,6 @@ private: Uint8 statusWalking; // Estado del jugador Uint8 statusFiring; // Estado del jugador - bool alive; // Indica si el jugador está vivo - Uint16 deathCounter; // Contador para la animación de morirse bool invulnerable; // Indica si el jugador es invulnerable Uint16 invulnerableCounter; // Contador para la invulnerabilidad bool extraHit; // Indica si el jugador tiene un toque extra @@ -71,6 +66,7 @@ private: Uint16 powerUpCounter; // Temporizador para el modo PowerUp bool input; // Indica si puede recibir ordenes de entrada circle_t collider; // Circulo de colisión del jugador + bool alive; // Indica si el jugador está vivo // Actualiza el circulo de colisión a la posición del jugador void shiftColliders(); @@ -78,9 +74,6 @@ private: // Actualiza el valor de la variable void updateInvulnerableCounter(); - // Actualiza el valor de la variable - void updateDeathCounter(); - // Actualiza el valor de la variable void updatePowerUpHeadOffset(); @@ -216,9 +209,6 @@ public: // Obtiene el puntero a la textura con los gráficos de la animación de morir Texture *getDeadTexture(); - - // Obtiene el valor de la variable - Uint16 getDeathCounter(); }; #endif