diff --git a/source/game.cpp b/source/game.cpp index 142313a..4b99c4d 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -27,14 +27,14 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr // Vector de jugadores if (mNumPlayers == 1) { - Player *player = new Player(PLAY_AREA_CENTER_X - 11, PLAY_AREA_BOTTOM - 24, mTexturePlayer1Legs, mTexturePlayer1Body, mTexturePlayer1Head, mTexturePlayer1Death, mRenderer); + Player *player = new Player(mRenderer, mAsset, PLAY_AREA_CENTER_X - 11, PLAY_AREA_BOTTOM - 24); players.push_back(player); } else if (mNumPlayers == 2) { - Player *player1 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((0 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24, mTexturePlayer1Legs, mTexturePlayer1Body, mTexturePlayer1Head, mTexturePlayer1Death, mRenderer); - Player *player2 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((1 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24, mTexturePlayer2Legs, mTexturePlayer2Body, mTexturePlayer2Head, mTexturePlayer2Death, mRenderer); + Player *player1 = new Player(mRenderer, mAsset, (PLAY_AREA_CENTER_FIRST_QUARTER_X * ((0 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24); + Player *player2 = new Player(mRenderer, mAsset, (PLAY_AREA_CENTER_FIRST_QUARTER_X * ((1 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24); players.push_back(player1); players.push_back(player2); } @@ -45,16 +45,6 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr mTextureGameText = new LTexture(mRenderer, mAsset->get("game_text.png")); mTextureItems = new LTexture(mRenderer, mAsset->get("items.png")); - mTexturePlayer1Head = new LTexture(mRenderer, mAsset->get("player1_head.png")); - mTexturePlayer1Body = new LTexture(mRenderer, mAsset->get("player1_body.png")); - mTexturePlayer1Legs = new LTexture(mRenderer, mAsset->get("player1_legs.png")); - mTexturePlayer1Death = new LTexture(mRenderer, mAsset->get("player1_death.png")); - - mTexturePlayer2Head = new LTexture(mRenderer, mAsset->get("player2_head.png")); - mTexturePlayer2Body = new LTexture(mRenderer, mAsset->get("player2_body.png")); - mTexturePlayer2Legs = new LTexture(mRenderer, mAsset->get("player2_legs.png")); - mTexturePlayer2Death = new LTexture(mRenderer, mAsset->get("player2_death.png")); - mText = new Text(mAsset->get("smb2.png"), mAsset->get("smb2.txt"), mRenderer); mTextScoreBoard = new Text(mAsset->get("8bithud.png"), mAsset->get("8bithud.txt"), mRenderer); mTextBig = new Text(mAsset->get("smb2_big.png"), mAsset->get("smb2_big.txt"), mRenderer); @@ -142,38 +132,6 @@ Game::~Game() delete mTextureItems; mTextureItems = nullptr; - mTexturePlayer1Head->unload(); - delete mTexturePlayer1Head; - mTexturePlayer1Head = nullptr; - - mTexturePlayer1Body->unload(); - delete mTexturePlayer1Body; - mTexturePlayer1Body = nullptr; - - mTexturePlayer1Death->unload(); - delete mTexturePlayer1Death; - mTexturePlayer1Death = nullptr; - - mTexturePlayer1Legs->unload(); - delete mTexturePlayer1Legs; - mTexturePlayer1Legs = nullptr; - - mTexturePlayer2Head->unload(); - delete mTexturePlayer2Head; - mTexturePlayer2Head = nullptr; - - mTexturePlayer2Body->unload(); - delete mTexturePlayer2Body; - mTexturePlayer2Body = nullptr; - - mTexturePlayer2Death->unload(); - delete mTexturePlayer2Death; - mTexturePlayer2Death = nullptr; - - mTexturePlayer2Legs->unload(); - delete mTexturePlayer2Legs; - mTexturePlayer2Legs = nullptr; - delete mText; mText = nullptr; @@ -1670,46 +1628,46 @@ void Game::updateDeath() { allAreDead &= (!player->isAlive()); - if (!player->isAlive()) + /*if (!player->isAlive()) { // Animación if ((player->getDeathCounter() / 5) % 4 == 0) { - smartSprites[player->mDeathIndex]->setSpriteClip(24 * 0, 24, 24, 24); + smartSprites[player->deathIndex]->setSpriteClip(24 * 0, 24, 24, 24); } else if ((player->getDeathCounter() / 5) % 4 == 1) { - smartSprites[player->mDeathIndex]->setSpriteClip(24 * 1, 24, 24, 24); + smartSprites[player->deathIndex]->setSpriteClip(24 * 1, 24, 24, 24); } else if ((player->getDeathCounter() / 5) % 4 == 2) { - smartSprites[player->mDeathIndex]->setSpriteClip(24 * 2, 24, 24, 24); + smartSprites[player->deathIndex]->setSpriteClip(24 * 2, 24, 24, 24); } else if ((player->getDeathCounter() / 5) % 4 == 3) { - smartSprites[player->mDeathIndex]->setSpriteClip(24 * 3, 24, 24, 24); + smartSprites[player->deathIndex]->setSpriteClip(24 * 3, 24, 24, 24); } // Rebote en los laterales - if (smartSprites[player->mDeathIndex]->getVelX() > 0) + if (smartSprites[player->deathIndex]->getVelX() > 0) { - if (smartSprites[player->mDeathIndex]->getPosX() > (GAME_WIDTH - smartSprites[player->mDeathIndex]->getWidth())) + if (smartSprites[player->deathIndex]->getPosX() > (GAME_WIDTH - smartSprites[player->deathIndex]->getWidth())) { - smartSprites[player->mDeathIndex]->setPosX(GAME_WIDTH - smartSprites[player->mDeathIndex]->getWidth()); - smartSprites[player->mDeathIndex]->setVelX(smartSprites[player->mDeathIndex]->getVelX() * (-1)); - smartSprites[player->mDeathIndex]->setDestX(smartSprites[player->mDeathIndex]->getDestX() * (-1)); + smartSprites[player->deathIndex]->setPosX(GAME_WIDTH - smartSprites[player->deathIndex]->getWidth()); + smartSprites[player->deathIndex]->setVelX(smartSprites[player->deathIndex]->getVelX() * (-1)); + smartSprites[player->deathIndex]->setDestX(smartSprites[player->deathIndex]->getDestX() * (-1)); } } else { - if (smartSprites[player->mDeathIndex]->getPosX() < 0) + if (smartSprites[player->deathIndex]->getPosX() < 0) { - smartSprites[player->mDeathIndex]->setPosX(0); - smartSprites[player->mDeathIndex]->setVelX(smartSprites[player->mDeathIndex]->getVelX() * (-1)); - smartSprites[player->mDeathIndex]->setDestX(smartSprites[player->mDeathIndex]->getDestX() * (-1)); + smartSprites[player->deathIndex]->setPosX(0); + smartSprites[player->deathIndex]->setVelX(smartSprites[player->deathIndex]->getVelX() * (-1)); + smartSprites[player->deathIndex]->setDestX(smartSprites[player->deathIndex]->getDestX() * (-1)); } } - } + }*/ } if (allAreDead) @@ -1719,7 +1677,7 @@ void Game::updateDeath() mDeathCounter--; if ((mDeathCounter == 250) || (mDeathCounter == 200) || (mDeathCounter == 180) || (mDeathCounter == 120) || (mDeathCounter == 60)) { - Uint8 sound = rand() % 4; + const Uint8 sound = rand() % 4; switch (sound) { case 0: @@ -2440,7 +2398,7 @@ void Game::throwPlayer(int x, int y, Player *player) { const int sentit = ((rand() % 2) ? 1 : -1); - //player->mDeathIndex = getSmartSpriteFreeIndex(); + //player->deathIndex = getSmartSpriteFreeIndex(); SmartSprite *ss = new SmartSprite(nullptr, mRenderer); smartSprites.push_back(ss); diff --git a/source/game.h b/source/game.h index 4fa0720..2fd7b83 100644 --- a/source/game.h +++ b/source/game.h @@ -146,14 +146,6 @@ private: LTexture *mTextureGameBG; // Textura para el fondo del juego LTexture *mTextureGameText; // Textura para los sprites con textos LTexture *mTextureItems; // Textura para los items - LTexture *mTexturePlayer1Head; // Textura para la cabeza del jugador1 - LTexture *mTexturePlayer1Body; // Textura para el cuerpo del jugador1 - LTexture *mTexturePlayer1Death; // Textura para la animación de muerte del jugador1 - LTexture *mTexturePlayer1Legs; // Textura para las piernas del jugador - LTexture *mTexturePlayer2Head; // Textura para la cabeza del jugador2 - LTexture *mTexturePlayer2Body; // Textura para el cuerpo del jugador2 - LTexture *mTexturePlayer2Death; // Textura para la animación de muerte del jugador2 - LTexture *mTexturePlayer2Legs; // Textura para las piernas del jugador Text *mText; // Fuente para los textos del juego Text *mTextBig; // Fuente de texto grande diff --git a/source/player.cpp b/source/player.cpp index 73064c0..76f7bb7 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -2,18 +2,24 @@ #include "player.h" // Constructor -Player::Player(float x, int y, LTexture *textureLegs, LTexture *textureBody, LTexture *textureHead, LTexture *textureDead, SDL_Renderer *renderer) +Player::Player(SDL_Renderer *renderer, Asset *asset, float x, int y) { - mSpriteLegs = new AnimatedSprite(textureLegs, renderer); - mSpriteBody = new AnimatedSprite(textureBody, renderer); - mSpriteHead = new AnimatedSprite(textureHead, renderer); + // Copia los punteros + this->renderer = renderer; + this->asset = asset; - // Copia punteros - mPlayerDeadTexture = textureDead; + // Reserva memoria para los objetos + legsTexture = new LTexture(renderer, asset->get("new_player_legs.png")); + bodyTexture = new LTexture(renderer, asset->get("new_player_body.png")); + headTexture = new LTexture(renderer, asset->get("new_player_head.png")); + deathTexture = new LTexture(renderer, asset->get("new_player_death.png")); + legsSprite = new AnimatedSprite(legsTexture, renderer, asset->get("new_player1_legs.ani")); + bodySprite = new AnimatedSprite(bodyTexture, renderer, asset->get("new_player1_body.ani")); + headSprite = new AnimatedSprite(headTexture, renderer, asset->get("new_player1_head.ani")); // Establece la posición inicial del jugador - mPosX = x; - mPosY = y; + posX = x; + posY = y; init(); } @@ -21,32 +27,44 @@ Player::Player(float x, int y, LTexture *textureLegs, LTexture *textureBody, LTe // Destructor Player::~Player() { - delete mSpriteLegs; - delete mSpriteBody; - delete mSpriteHead; + legsTexture->unload(); + delete legsTexture; + + bodyTexture->unload(); + delete bodyTexture; + + headTexture->unload(); + delete headTexture; + + deathTexture->unload(); + delete deathTexture; + + delete legsSprite; + delete bodySprite; + delete headSprite; } // Iniciador void Player::init() { // Inicializa variables de estado - mAlive = true; - mDeathCounter = DEATH_COUNTER; - mDeathIndex = 0; - mStatusWalking = PLAYER_STATUS_WALKING_STOP; - mStatusFiring = PLAYER_STATUS_FIRING_NO; - mInvulnerable = false; - mInvulnerableCounter = PLAYER_INVULNERABLE_COUNTER; - mPowerUp = false; - mPowerUpCounter = PLAYER_POWERUP_COUNTER; - mPowerUpHeadOffset = 0; - mExtraHit = false; - mCoffees = 0; - mInput = true; + alive = true; + deathCounter = DEATH_COUNTER; + deathIndex = 0; + statusWalking = PLAYER_STATUS_WALKING_STOP; + statusFiring = PLAYER_STATUS_FIRING_NO; + invulnerable = false; + invulnerableCounter = PLAYER_INVULNERABLE_COUNTER; + powerUp = false; + powerUpCounter = PLAYER_POWERUP_COUNTER; + powerUpHeadOffset = 0; + extraHit = false; + coffees = 0; + input = true; // Establece la altura y el ancho del jugador - mWidth = 3 * BLOCK; - mHeight = 3 * BLOCK; + width = 3 * BLOCK; + height = 3 * BLOCK; // Establece el tamaño del circulo de colisión mCollider.r = 7; @@ -55,169 +73,169 @@ void Player::init() shiftColliders(); // Establece la velocidad inicial - mVelX = 0; - mVelY = 0; + velX = 0; + velY = 0; // Establece la velocidad base - mBaseSpeed = 1.5; + baseSpeed = 1.5; // Establece la puntuación inicial - mScore = 0; + score = 0; // Establece el multiplicador de puntos inicial - mScoreMultiplier = 1.0f; + scoreMultiplier = 1.0f; // Inicia el contador para la cadencia de disparo - mCooldown = 10; + cooldown = 10; // Establece el alto y ancho del sprite - mSpriteLegs->setWidth(mWidth); - mSpriteLegs->setHeight(mHeight); + legsSprite->setWidth(width); + legsSprite->setHeight(height); - mSpriteBody->setWidth(mWidth); - mSpriteBody->setHeight(mHeight); + bodySprite->setWidth(width); + bodySprite->setHeight(height); - mSpriteHead->setWidth(mWidth); - mSpriteHead->setHeight(mHeight); + headSprite->setWidth(width); + headSprite->setHeight(height); // Establece la posición del sprite - mSpriteLegs->setPosX(int(mPosX)); - mSpriteLegs->setPosY(mPosY); + legsSprite->setPosX(int(posX)); + legsSprite->setPosY(posY); - mSpriteBody->setPosX(int(mPosX)); - mSpriteBody->setPosY(mPosY); + bodySprite->setPosX(int(posX)); + bodySprite->setPosY(posY); - mSpriteHead->setPosX(int(mPosX)); - mSpriteHead->setPosY(mPosY); + headSprite->setPosX(int(posX)); + headSprite->setPosY(posY); // Inicializa las variables para la animación - mSpriteLegs->setCurrentFrame(0); - mSpriteLegs->setAnimationCounter(0); + legsSprite->setCurrentFrame(0); + legsSprite->setAnimationCounter(0); - mSpriteBody->setCurrentFrame(0); - mSpriteBody->setAnimationCounter(0); + bodySprite->setCurrentFrame(0); + bodySprite->setAnimationCounter(0); - mSpriteHead->setCurrentFrame(0); - mSpriteHead->setAnimationCounter(0); + headSprite->setCurrentFrame(0); + headSprite->setAnimationCounter(0); // Establece la velocidad de cada animación - mSpriteLegs->setAnimationSpeed(PLAYER_ANIMATION_LEGS_WALKING_STOP, 10); - mSpriteLegs->setAnimationSpeed(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 5); - mSpriteLegs->setAnimationSpeed(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 5); + legsSprite->setAnimationSpeed(PLAYER_ANIMATION_LEGS_WALKING_STOP, 10); + legsSprite->setAnimationSpeed(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 5); + legsSprite->setAnimationSpeed(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 5); - mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_LEFT, 5); - mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_LEFT, 5); - mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_RIGHT, 5); - mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 5); - mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_STOP, 10); - mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_UP, 5); + bodySprite->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_LEFT, 5); + bodySprite->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_LEFT, 5); + bodySprite->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_RIGHT, 5); + bodySprite->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 5); + bodySprite->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_STOP, 10); + bodySprite->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_UP, 5); - mSpriteHead->setAnimationSpeed(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 5); - mSpriteHead->setAnimationSpeed(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 5); - mSpriteHead->setAnimationSpeed(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 5); - mSpriteHead->setAnimationSpeed(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 5); - mSpriteHead->setAnimationSpeed(PLAYER_ANIMATION_HEAD_WALKING_STOP, 10); - mSpriteHead->setAnimationSpeed(PLAYER_ANIMATION_HEAD_FIRING_UP, 5); + headSprite->setAnimationSpeed(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 5); + headSprite->setAnimationSpeed(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 5); + headSprite->setAnimationSpeed(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 5); + headSprite->setAnimationSpeed(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 5); + headSprite->setAnimationSpeed(PLAYER_ANIMATION_HEAD_WALKING_STOP, 10); + headSprite->setAnimationSpeed(PLAYER_ANIMATION_HEAD_FIRING_UP, 5); // Establece si la animación se reproduce en bucle - mSpriteLegs->setAnimationLoop(PLAYER_ANIMATION_LEGS_WALKING_STOP, true); - mSpriteLegs->setAnimationLoop(PLAYER_ANIMATION_LEGS_WALKING_LEFT, true); - mSpriteLegs->setAnimationLoop(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, true); + legsSprite->setAnimationLoop(PLAYER_ANIMATION_LEGS_WALKING_STOP, true); + legsSprite->setAnimationLoop(PLAYER_ANIMATION_LEGS_WALKING_LEFT, true); + legsSprite->setAnimationLoop(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, true); - mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_LEFT, true); - mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_LEFT, true); - mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_RIGHT, true); - mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_RIGHT, true); - mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_STOP, true); - mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_UP, true); + bodySprite->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_LEFT, true); + bodySprite->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_LEFT, true); + bodySprite->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_RIGHT, true); + bodySprite->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_RIGHT, true); + bodySprite->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_STOP, true); + bodySprite->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_UP, true); - mSpriteHead->setAnimationLoop(PLAYER_ANIMATION_HEAD_WALKING_LEFT, true); - mSpriteHead->setAnimationLoop(PLAYER_ANIMATION_HEAD_FIRING_LEFT, true); - mSpriteHead->setAnimationLoop(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, true); - mSpriteHead->setAnimationLoop(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, true); - mSpriteHead->setAnimationLoop(PLAYER_ANIMATION_HEAD_WALKING_STOP, true); - mSpriteHead->setAnimationLoop(PLAYER_ANIMATION_HEAD_FIRING_UP, true); + headSprite->setAnimationLoop(PLAYER_ANIMATION_HEAD_WALKING_LEFT, true); + headSprite->setAnimationLoop(PLAYER_ANIMATION_HEAD_FIRING_LEFT, true); + headSprite->setAnimationLoop(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, true); + headSprite->setAnimationLoop(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, true); + headSprite->setAnimationLoop(PLAYER_ANIMATION_HEAD_WALKING_STOP, true); + headSprite->setAnimationLoop(PLAYER_ANIMATION_HEAD_FIRING_UP, true); // Establece los frames de cada animación - mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 0, mWidth * 0, mHeight * 0, mWidth, mHeight); - mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 1, mWidth * 1, mHeight * 0, mWidth, mHeight); - mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 2, mWidth * 2, mHeight * 0, mWidth, mHeight); - mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 3, mWidth * 3, mHeight * 0, mWidth, mHeight); + legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 0, width * 0, height * 0, width, height); + legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 1, width * 1, height * 0, width, height); + legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 2, width * 2, height * 0, width, height); + legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 3, width * 3, height * 0, width, height); - mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 0, mWidth * 0, mHeight * 1, mWidth, mHeight); - mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 1, mWidth * 1, mHeight * 1, mWidth, mHeight); - mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 2, mWidth * 2, mHeight * 1, mWidth, mHeight); - mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 3, mWidth * 3, mHeight * 1, mWidth, mHeight); + legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 0, width * 0, height * 1, width, height); + legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 1, width * 1, height * 1, width, height); + legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 2, width * 2, height * 1, width, height); + legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 3, width * 3, height * 1, width, height); - mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_STOP, 0, mWidth * 0, mHeight * 2, mWidth, mHeight); - mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_STOP, 1, mWidth * 1, mHeight * 2, mWidth, mHeight); - mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_STOP, 2, mWidth * 2, mHeight * 2, mWidth, mHeight); - mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_STOP, 3, mWidth * 3, mHeight * 2, mWidth, mHeight); + legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_STOP, 0, width * 0, height * 2, width, height); + legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_STOP, 1, width * 1, height * 2, width, height); + legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_STOP, 2, width * 2, height * 2, width, height); + legsSprite->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_STOP, 3, width * 3, height * 2, width, height); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, 0, mWidth * 0, mHeight * 0, mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, 1, mWidth * 1, mHeight * 0, mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, 2, mWidth * 2, mHeight * 0, mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, 3, mWidth * 3, mHeight * 0, mWidth, mHeight); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, 0, width * 0, height * 0, width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, 1, width * 1, height * 0, width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, 2, width * 2, height * 0, width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, 3, width * 3, height * 0, width, height); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, 0, mWidth * 0, mHeight * 1, mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, 1, mWidth * 1, mHeight * 1, mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, 2, mWidth * 2, mHeight * 1, mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, 3, mWidth * 3, mHeight * 1, mWidth, mHeight); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, 0, width * 0, height * 1, width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, 1, width * 1, height * 1, width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, 2, width * 2, height * 1, width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, 3, width * 3, height * 1, width, height); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, 0, mWidth * 0, mHeight * 2, mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, 1, mWidth * 1, mHeight * 2, mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, 2, mWidth * 2, mHeight * 2, mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, 3, mWidth * 3, mHeight * 2, mWidth, mHeight); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, 0, width * 0, height * 2, width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, 1, width * 1, height * 2, width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, 2, width * 2, height * 2, width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, 3, width * 3, height * 2, width, height); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 0, mWidth * 0, mHeight * 3, mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 1, mWidth * 1, mHeight * 3, mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 2, mWidth * 2, mHeight * 3, mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 3, mWidth * 3, mHeight * 3, mWidth, mHeight); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 0, width * 0, height * 3, width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 1, width * 1, height * 3, width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 2, width * 2, height * 3, width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 3, width * 3, height * 3, width, height); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 0, mWidth * 0, mHeight * 4, mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 1, mWidth * 1, mHeight * 4, mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 2, mWidth * 2, mHeight * 4, mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 3, mWidth * 3, mHeight * 4, mWidth, mHeight); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 0, width * 0, height * 4, width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 1, width * 1, height * 4, width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 2, width * 2, height * 4, width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 3, width * 3, height * 4, width, height); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 0, mWidth * 0, mHeight * 5, mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 1, mWidth * 1, mHeight * 5, mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 2, mWidth * 2, mHeight * 5, mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 3, mWidth * 3, mHeight * 5, mWidth, mHeight); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 0, width * 0, height * 5, width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 1, width * 1, height * 5, width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 2, width * 2, height * 5, width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 3, width * 3, height * 5, width, height); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 0, mWidth * 0, mHeight * 0, mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 1, mWidth * 1, mHeight * 0, mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 2, mWidth * 2, mHeight * 0, mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 3, mWidth * 3, mHeight * 0, mWidth, mHeight); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 0, width * 0, height * 0, width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 1, width * 1, height * 0, width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 2, width * 2, height * 0, width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 3, width * 3, height * 0, width, height); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 0, mWidth * 0, mHeight * 1, mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 1, mWidth * 1, mHeight * 1, mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 2, mWidth * 2, mHeight * 1, mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 3, mWidth * 3, mHeight * 1, mWidth, mHeight); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 0, width * 0, height * 1, width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 1, width * 1, height * 1, width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 2, width * 2, height * 1, width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 3, width * 3, height * 1, width, height); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 0, mWidth * 0, mHeight * 2, mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 1, mWidth * 1, mHeight * 2, mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 2, mWidth * 2, mHeight * 2, mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 3, mWidth * 3, mHeight * 2, mWidth, mHeight); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 0, width * 0, height * 2, width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 1, width * 1, height * 2, width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 2, width * 2, height * 2, width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 3, width * 3, height * 2, width, height); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 0, mWidth * 0, mHeight * 3, mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 1, mWidth * 1, mHeight * 3, mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 2, mWidth * 2, mHeight * 3, mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 3, mWidth * 3, mHeight * 3, mWidth, mHeight); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 0, width * 0, height * 3, width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 1, width * 1, height * 3, width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 2, width * 2, height * 3, width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 3, width * 3, height * 3, width, height); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, 0, mWidth * 0, mHeight * 4, mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, 1, mWidth * 1, mHeight * 4, mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, 2, mWidth * 2, mHeight * 4, mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, 3, mWidth * 3, mHeight * 4, mWidth, mHeight); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, 0, width * 0, height * 4, width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, 1, width * 1, height * 4, width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, 2, width * 2, height * 4, width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, 3, width * 3, height * 4, width, height); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, 0, mWidth * 0, mHeight * 5, mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, 1, mWidth * 1, mHeight * 5, mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, 2, mWidth * 2, mHeight * 5, mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, 3, mWidth * 3, mHeight * 5, mWidth, mHeight); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, 0, width * 0, height * 5, width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, 1, width * 1, height * 5, width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, 2, width * 2, height * 5, width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, 3, width * 3, height * 5, width, height); // Selecciona un frame para pintar - mSpriteLegs->setSpriteClip(mSpriteLegs->getAnimationClip(PLAYER_ANIMATION_LEGS_WALKING_STOP, 0)); - mSpriteBody->setSpriteClip(mSpriteBody->getAnimationClip(PLAYER_ANIMATION_BODY_WALKING_STOP, 0)); - mSpriteHead->setSpriteClip(mSpriteHead->getAnimationClip(PLAYER_ANIMATION_HEAD_WALKING_STOP, 0)); + legsSprite->setSpriteClip(legsSprite->getAnimationClip(PLAYER_ANIMATION_LEGS_WALKING_STOP, 0)); + bodySprite->setSpriteClip(bodySprite->getAnimationClip(PLAYER_ANIMATION_BODY_WALKING_STOP, 0)); + headSprite->setSpriteClip(headSprite->getAnimationClip(PLAYER_ANIMATION_HEAD_WALKING_STOP, 0)); } // Actua en consecuencia de la entrada recibida @@ -226,12 +244,12 @@ void Player::setInput(Uint8 input) switch (input) { case INPUT_LEFT: - mVelX = -mBaseSpeed; + velX = -baseSpeed; setWalkingStatus(PLAYER_STATUS_WALKING_LEFT); break; case INPUT_RIGHT: - mVelX = mBaseSpeed; + velX = baseSpeed; setWalkingStatus(PLAYER_STATUS_WALKING_RIGHT); break; @@ -248,7 +266,7 @@ void Player::setInput(Uint8 input) break; default: - mVelX = 0; + velX = 0; setWalkingStatus(PLAYER_STATUS_WALKING_STOP); break; } @@ -260,21 +278,21 @@ void Player::move() if (isAlive()) { // Mueve el jugador a derecha o izquierda - mPosX += mVelX; + posX += velX; // Si el jugador abandona el area de juego por los laterales - if ((mPosX < PLAY_AREA_LEFT - 5) || (mPosX + mWidth > PLAY_AREA_RIGHT + 5)) - mPosX -= mVelX; // Restaura su posición + if ((posX < PLAY_AREA_LEFT - 5) || (posX + width > PLAY_AREA_RIGHT + 5)) + posX -= velX; // Restaura su posición // Actualiza la posición del sprite - mSpriteLegs->setPosX(getPosX()); - mSpriteLegs->setPosY(mPosY); + legsSprite->setPosX(getPosX()); + legsSprite->setPosY(posY); - mSpriteBody->setPosX(getPosX()); - mSpriteBody->setPosY(mPosY); + bodySprite->setPosX(getPosX()); + bodySprite->setPosY(posY); - mSpriteHead->setPosX(getPosX()); - mSpriteHead->setPosY(mPosY); + headSprite->setPosX(getPosX()); + headSprite->setPosY(posY); } } @@ -283,20 +301,20 @@ void Player::render() { if (isAlive()) { - if (mInvulnerable) + if (invulnerable) { - if ((mInvulnerableCounter % 10) > 4) + if ((invulnerableCounter % 10) > 4) { - mSpriteLegs->render(); - mSpriteBody->render(); - mSpriteHead->render(); + legsSprite->render(); + bodySprite->render(); + headSprite->render(); } } else { - mSpriteLegs->render(); - mSpriteBody->render(); - mSpriteHead->render(); + legsSprite->render(); + bodySprite->render(); + headSprite->render(); } } } @@ -305,10 +323,10 @@ void Player::render() void Player::setWalkingStatus(Uint8 status) { // Si cambiamos de estado, reiniciamos la animación - if (mStatusWalking != status) + if (statusWalking != status) { - mStatusWalking = status; - mSpriteLegs->setCurrentFrame(0); + statusWalking = status; + legsSprite->setCurrentFrame(0); } } @@ -316,11 +334,11 @@ void Player::setWalkingStatus(Uint8 status) void Player::setFiringStatus(Uint8 status) { // Si cambiamos de estado, reiniciamos la animación - if (mStatusFiring != status) + if (statusFiring != status) { - mStatusFiring = status; - mSpriteBody->setCurrentFrame(0); - mSpriteHead->setCurrentFrame(0); + statusFiring = status; + bodySprite->setCurrentFrame(0); + headSprite->setCurrentFrame(0); } } @@ -330,156 +348,156 @@ void Player::setAnimation() // Actualiza los frames de la animación en función del número de cafes for (int i = 0; i < 4; i++) { - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, i, mWidth * i, mHeight * (0 + (6 * mCoffees)), mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, i, mWidth * i, mHeight * (1 + (6 * mCoffees)), mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, i, mWidth * i, mHeight * (2 + (6 * mCoffees)), mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, i, mWidth * i, mHeight * (3 + (6 * mCoffees)), mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, i, mWidth * i, mHeight * (4 + (6 * mCoffees)), mWidth, mHeight); - mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, i, mWidth * i, mHeight * (5 + (6 * mCoffees)), mWidth, mHeight); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, i, width * i, height * (0 + (6 * coffees)), width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, i, width * i, height * (1 + (6 * coffees)), width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, i, width * i, height * (2 + (6 * coffees)), width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, i, width * i, height * (3 + (6 * coffees)), width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, i, width * i, height * (4 + (6 * coffees)), width, height); + bodySprite->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, i, width * i, height * (5 + (6 * coffees)), width, height); } // Actualiza los frames de la animación en función de si se tiene el PowerUp for (int i = 0; i < 4; i++) { - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, i, (mWidth * i) + mPowerUpHeadOffset, mHeight * (0 + (6 * mCoffees)), mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, i, (mWidth * i) + mPowerUpHeadOffset, mHeight * (1 + (6 * mCoffees)), mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, i, (mWidth * i) + mPowerUpHeadOffset, mHeight * (2 + (6 * mCoffees)), mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, i, (mWidth * i) + mPowerUpHeadOffset, mHeight * (3 + (6 * mCoffees)), mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, i, (mWidth * i) + mPowerUpHeadOffset, mHeight * (4 + (6 * mCoffees)), mWidth, mHeight); - mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, i, (mWidth * i) + mPowerUpHeadOffset, mHeight * (5 + (6 * mCoffees)), mWidth, mHeight); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, i, (width * i) + powerUpHeadOffset, height * (0 + (6 * coffees)), width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, i, (width * i) + powerUpHeadOffset, height * (1 + (6 * coffees)), width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, i, (width * i) + powerUpHeadOffset, height * (2 + (6 * coffees)), width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, i, (width * i) + powerUpHeadOffset, height * (3 + (6 * coffees)), width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, i, (width * i) + powerUpHeadOffset, height * (4 + (6 * coffees)), width, height); + headSprite->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, i, (width * i) + powerUpHeadOffset, height * (5 + (6 * coffees)), width, height); } - switch (mStatusWalking) + switch (statusWalking) { case PLAYER_STATUS_WALKING_LEFT: - mSpriteLegs->setCurrentAnimation(PLAYER_ANIMATION_LEGS_WALKING_LEFT); - mSpriteLegs->animate(); - switch (mStatusFiring) + legsSprite->setCurrentAnimation(PLAYER_ANIMATION_LEGS_WALKING_LEFT); + legsSprite->animate(); + switch (statusFiring) { case PLAYER_STATUS_FIRING_UP: - mSpriteBody->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_UP); - mSpriteBody->animate(); - mSpriteHead->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_UP); - mSpriteHead->animate(); + bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_UP); + bodySprite->animate(); + headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_UP); + headSprite->animate(); break; case PLAYER_STATUS_FIRING_LEFT: - mSpriteBody->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_LEFT); - mSpriteBody->animate(); - mSpriteHead->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_LEFT); - mSpriteHead->animate(); + bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_LEFT); + bodySprite->animate(); + headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_LEFT); + headSprite->animate(); break; case PLAYER_STATUS_FIRING_RIGHT: - mSpriteBody->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_RIGHT); - mSpriteBody->animate(); - mSpriteHead->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_RIGHT); - mSpriteHead->animate(); + bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_RIGHT); + bodySprite->animate(); + headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_RIGHT); + headSprite->animate(); break; case PLAYER_STATUS_FIRING_NO: - mSpriteBody->setCurrentAnimation(PLAYER_ANIMATION_BODY_WALKING_LEFT); - mSpriteBody->animate(); - mSpriteHead->setCurrentAnimation(PLAYER_ANIMATION_HEAD_WALKING_LEFT); - mSpriteHead->animate(); + bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_WALKING_LEFT); + bodySprite->animate(); + headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_WALKING_LEFT); + headSprite->animate(); break; default: - mSpriteBody->setCurrentAnimation(PLAYER_ANIMATION_BODY_WALKING_STOP); - mSpriteBody->animate(); - mSpriteHead->setCurrentAnimation(PLAYER_ANIMATION_HEAD_WALKING_STOP); - mSpriteHead->animate(); + bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_WALKING_STOP); + bodySprite->animate(); + headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_WALKING_STOP); + headSprite->animate(); break; } break; case PLAYER_STATUS_WALKING_RIGHT: - mSpriteLegs->setCurrentAnimation(PLAYER_ANIMATION_LEGS_WALKING_RIGHT); - mSpriteLegs->animate(); - switch (mStatusFiring) + legsSprite->setCurrentAnimation(PLAYER_ANIMATION_LEGS_WALKING_RIGHT); + legsSprite->animate(); + switch (statusFiring) { case PLAYER_STATUS_FIRING_UP: - mSpriteBody->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_UP); - mSpriteBody->animate(); - mSpriteHead->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_UP); - mSpriteHead->animate(); + bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_UP); + bodySprite->animate(); + headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_UP); + headSprite->animate(); break; case PLAYER_STATUS_FIRING_LEFT: - mSpriteBody->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_LEFT); - mSpriteBody->animate(); - mSpriteHead->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_LEFT); - mSpriteHead->animate(); + bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_LEFT); + bodySprite->animate(); + headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_LEFT); + headSprite->animate(); break; case PLAYER_STATUS_FIRING_RIGHT: - mSpriteBody->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_RIGHT); - mSpriteBody->animate(); - mSpriteHead->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_RIGHT); - mSpriteHead->animate(); + bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_RIGHT); + bodySprite->animate(); + headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_RIGHT); + headSprite->animate(); break; case PLAYER_STATUS_FIRING_NO: - mSpriteBody->setCurrentAnimation(PLAYER_ANIMATION_BODY_WALKING_RIGHT); - mSpriteBody->animate(); - mSpriteHead->setCurrentAnimation(PLAYER_ANIMATION_HEAD_WALKING_RIGHT); - mSpriteHead->animate(); + bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_WALKING_RIGHT); + bodySprite->animate(); + headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_WALKING_RIGHT); + headSprite->animate(); break; default: - mSpriteBody->setCurrentAnimation(PLAYER_ANIMATION_BODY_WALKING_STOP); - mSpriteBody->animate(); - mSpriteHead->setCurrentAnimation(PLAYER_ANIMATION_HEAD_WALKING_STOP); - mSpriteHead->animate(); + bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_WALKING_STOP); + bodySprite->animate(); + headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_WALKING_STOP); + headSprite->animate(); break; } break; case PLAYER_STATUS_WALKING_STOP: - mSpriteLegs->setCurrentAnimation(PLAYER_ANIMATION_LEGS_WALKING_STOP); - mSpriteLegs->animate(); - switch (mStatusFiring) + legsSprite->setCurrentAnimation(PLAYER_ANIMATION_LEGS_WALKING_STOP); + legsSprite->animate(); + switch (statusFiring) { case PLAYER_STATUS_FIRING_UP: - mSpriteBody->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_UP); - mSpriteBody->animate(); - mSpriteHead->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_UP); - mSpriteHead->animate(); + bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_UP); + bodySprite->animate(); + headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_UP); + headSprite->animate(); break; case PLAYER_STATUS_FIRING_LEFT: - mSpriteBody->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_LEFT); - mSpriteBody->animate(); - mSpriteHead->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_LEFT); - mSpriteHead->animate(); + bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_LEFT); + bodySprite->animate(); + headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_LEFT); + headSprite->animate(); break; case PLAYER_STATUS_FIRING_RIGHT: - mSpriteBody->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_RIGHT); - mSpriteBody->animate(); - mSpriteHead->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_RIGHT); - mSpriteHead->animate(); + bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_RIGHT); + bodySprite->animate(); + headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_RIGHT); + headSprite->animate(); break; case PLAYER_STATUS_FIRING_NO: - mSpriteBody->setCurrentAnimation(PLAYER_ANIMATION_BODY_WALKING_STOP); - mSpriteBody->animate(); - mSpriteHead->setCurrentAnimation(PLAYER_ANIMATION_HEAD_WALKING_STOP); - mSpriteHead->animate(); + bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_WALKING_STOP); + bodySprite->animate(); + headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_WALKING_STOP); + headSprite->animate(); break; default: - mSpriteBody->setCurrentAnimation(PLAYER_ANIMATION_BODY_WALKING_STOP); - mSpriteBody->animate(); - mSpriteHead->setCurrentAnimation(PLAYER_ANIMATION_HEAD_WALKING_STOP); - mSpriteHead->animate(); + bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_WALKING_STOP); + bodySprite->animate(); + headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_WALKING_STOP); + headSprite->animate(); break; } break; default: - mSpriteLegs->setCurrentAnimation(PLAYER_ANIMATION_LEGS_WALKING_STOP); - mSpriteLegs->animate(); + legsSprite->setCurrentAnimation(PLAYER_ANIMATION_LEGS_WALKING_STOP); + legsSprite->animate(); break; } } @@ -487,32 +505,32 @@ void Player::setAnimation() // Obtiene el valor de la variable int Player::getPosX() { - return int(mPosX); + return int(posX); } // Obtiene el valor de la variable int Player::getPosY() { - return mPosY; + return posY; } // Obtiene el valor de la variable int Player::getWidth() { - return mWidth; + return width; } // Obtiene el valor de la variable int Player::getHeight() { - return mHeight; + return height; } // Indica si el jugador puede disparar bool Player::canFire() { // Si el contador a llegado a cero, podemos disparar. En caso contrario decrementamos el contador - if (mCooldown > 0) + if (cooldown > 0) return false; else return true; @@ -521,17 +539,17 @@ bool Player::canFire() // Establece el valor de la variable void Player::setFireCooldown(int time) { - mCooldown = time; + cooldown = time; } // Actualiza el valor de la variable void Player::updateCooldown() { - if (mCooldown > 0) + if (cooldown > 0) { - mCooldown--; - if (mPowerUp) - mCooldown--; + cooldown--; + if (powerUp) + cooldown--; } else { @@ -555,100 +573,108 @@ void Player::update() // Obtiene la puntuación del jugador Uint32 Player::getScore() { - return mScore; + return score; } // Asigna un valor a la puntuación del jugador void Player::setScore(Uint32 score) { - mScore = score; + this->score = score; } // Incrementa la puntuación del jugador void Player::addScore(Uint32 score) { - mScore += score; + this->score += score; } // Obtiene el valor de la variable bool Player::isAlive() { - return mAlive; + return alive; } // Establece el valor de la variable void Player::setAlive(bool value) { - mAlive = value; + alive = value; } // Obtiene el valor de la variable float Player::getScoreMultiplier() { - return mScoreMultiplier; + return scoreMultiplier; } // Establece el valor de la variable void Player::setScoreMultiplier(float value) { - mScoreMultiplier = value; + scoreMultiplier = value; } // Aumenta el valor de la variable hasta un máximo void Player::incScoreMultiplier() { - if (mScoreMultiplier < 5.0f) - mScoreMultiplier += 0.1f; + if (scoreMultiplier < 5.0f) + { + scoreMultiplier += 0.1f; + } else - mScoreMultiplier = 5.0f; + { + scoreMultiplier = 5.0f; + } } // Decrementa el valor de la variable hasta un mínimo void Player::decScoreMultiplier() { - if (mScoreMultiplier > 1.0f) - mScoreMultiplier -= 0.1f; + if (scoreMultiplier > 1.0f) + { + scoreMultiplier -= 0.1f; + } else - mScoreMultiplier = 1.0f; + { + scoreMultiplier = 1.0f; + } } // Obtiene el valor de la variable bool Player::isInvulnerable() { - return mInvulnerable; + return invulnerable; } // Establece el valor de la variable void Player::setInvulnerable(bool value) { - mInvulnerable = value; + invulnerable = value; } // Obtiene el valor de la variable Uint16 Player::getInvulnerableCounter() { - return mInvulnerableCounter; + return invulnerableCounter; } // Establece el valor de la variable void Player::setInvulnerableCounter(Uint16 value) { - mInvulnerableCounter = value; + invulnerableCounter = value; } // Actualiza el valor de la variable void Player::updateInvulnerableCounter() { - if (mInvulnerable) + if (invulnerable) { - if (mInvulnerableCounter > 0) + if (invulnerableCounter > 0) { - mInvulnerableCounter--; + invulnerableCounter--; } else { - mInvulnerable = false; - mInvulnerableCounter = PLAYER_INVULNERABLE_COUNTER; + invulnerable = false; + invulnerableCounter = PLAYER_INVULNERABLE_COUNTER; } } } @@ -656,91 +682,101 @@ void Player::updateInvulnerableCounter() // Actualiza el valor de la variable void Player::updateDeathCounter() { - if (!mAlive) - if (mDeathCounter > 0) - mDeathCounter--; + if (!alive) + { + if (deathCounter > 0) + { + deathCounter--; + } + } } // Obtiene el valor de la variable bool Player::isPowerUp() { - return mPowerUp; + return powerUp; } // Establece el valor de la variable void Player::setPowerUp(bool value) { - mPowerUp = value; + powerUp = value; } // Obtiene el valor de la variable Uint16 Player::getPowerUpCounter() { - return mPowerUpCounter; + return powerUpCounter; } // Establece el valor de la variable void Player::setPowerUpCounter(Uint16 value) { - mPowerUpCounter = value; + powerUpCounter = value; } // Actualiza el valor de la variable void Player::updatePowerUpCounter() { - if ((mPowerUpCounter > 0) && (mPowerUp)) + if ((powerUpCounter > 0) && (powerUp)) { - mPowerUpCounter--; + powerUpCounter--; } else { - mPowerUp = false; - mPowerUpCounter = PLAYER_POWERUP_COUNTER; + powerUp = false; + powerUpCounter = PLAYER_POWERUP_COUNTER; } } // Obtiene el valor de la variable bool Player::hasExtraHit() { - return mExtraHit; + return extraHit; } // Concede un toque extra al jugador void Player::giveExtraHit() { - mExtraHit = true; - mCoffees++; - if (mCoffees > 2) - mCoffees = 2; + extraHit = true; + coffees++; + if (coffees > 2) + { + coffees = 2; + } } // Quita el toque extra al jugador void Player::removeExtraHit() { - if (mCoffees > 0) - mCoffees--; - if (mCoffees == 0) - mExtraHit = false; - mInvulnerable = true; - mInvulnerableCounter = PLAYER_INVULNERABLE_COUNTER; + if (coffees > 0) + { + coffees--; + } + if (coffees == 0) + { + extraHit = false; + } + invulnerable = true; + invulnerableCounter = PLAYER_INVULNERABLE_COUNTER; } // Habilita la entrada de ordenes void Player::enableInput() { - mInput = true; + input = true; } // Deshabilita la entrada de ordenes void Player::disableInput() { - mInput = false; + input = false; } // Devuelve el numero de cafes actuales Uint8 Player::getCoffees() { - return mCoffees; + return coffees; } // Obtiene el circulo de colisión @@ -752,36 +788,42 @@ circle_t &Player::getCollider() // Actualiza el circulo de colisión a la posición del jugador void Player::shiftColliders() { - mCollider.x = int(mPosX + (mWidth / 2)); - mCollider.y = int(mPosY + (mHeight / 2)); + mCollider.x = int(posX + (width / 2)); + mCollider.y = int(posY + (height / 2)); } // Obtiene el puntero a la textura con los gráficos de la animación de morir LTexture *Player::getDeadTexture() { - return mPlayerDeadTexture; + return deathTexture; } // Obtiene el valor de la variable Uint16 Player::getDeathCounter() { - return mDeathCounter; + return deathCounter; } // Actualiza el valor de la variable void Player::updatePowerUpHeadOffset() { - if (!mPowerUp) - mPowerUpHeadOffset = 0; + if (!powerUp) + { + powerUpHeadOffset = 0; + } else { - mPowerUpHeadOffset = 96; - if (mPowerUpCounter < 300) + powerUpHeadOffset = 96; + if (powerUpCounter < 300) { - if (mPowerUpCounter % 10 > 4) - mPowerUpHeadOffset = 96; + if (powerUpCounter % 10 > 4) + { + powerUpHeadOffset = 96; + } else - mPowerUpHeadOffset = 0; + { + powerUpHeadOffset = 0; + } } } } \ No newline at end of file diff --git a/source/player.h b/source/player.h index 8a249af..5489516 100644 --- a/source/player.h +++ b/source/player.h @@ -3,6 +3,8 @@ #include #include "utils.h" #include "input.h" +#include "asset.h" +#include "ltexture.h" #include "animatedsprite.h" #ifndef PLAYER_H @@ -47,41 +49,49 @@ class Player { private: - float mPosX; // Posicion en el eje X - int mPosY; // Posicion en el eje Y + // Objetos + SDL_Renderer *renderer; // El renderizador de la ventana + Asset *asset; // Objeto que gestiona todos los ficheros de recursos + LTexture *headTexture; // Textura para la cabeza del jugador + LTexture *bodyTexture; // Textura para el cuerpo del jugador + LTexture *deathTexture; // Textura para la animación de muerte del jugador + LTexture *legsTexture; // Textura para las piernas del jugador + AnimatedSprite *legsSprite; // Sprite para dibujar las piernas + AnimatedSprite *bodySprite; // Sprite para dibujar el cuerpo + AnimatedSprite *headSprite; // Sprite para dibujar la cabeza - Uint8 mWidth; // Anchura - Uint8 mHeight; // Altura + // Variables + float posX; // Posicion en el eje X + int posY; // Posicion en el eje Y - float mVelX; // Cantidad de pixeles a desplazarse en el eje X - int mVelY; // Cantidad de pixeles a desplazarse en el eje Y + Uint8 width; // Anchura + Uint8 height; // Altura - float mBaseSpeed; // Velocidad base del jugador - int mCooldown; // Contador durante el cual no puede disparar + float velX; // Cantidad de pixeles a desplazarse en el eje X + int velY; // Cantidad de pixeles a desplazarse en el eje Y - Uint32 mScore; // Puntos del jugador - float mScoreMultiplier; // Multiplicador de puntos + float baseSpeed; // Velocidad base del jugador + int cooldown; // Contador durante el cual no puede disparar - Uint8 mStatusWalking; // Estado del jugador - Uint8 mStatusFiring; // Estado del jugador + Uint32 score; // Puntos del jugador + float scoreMultiplier; // Multiplicador de puntos - bool mAlive; // Indica si el jugador está vivo - Uint16 mDeathCounter; // Contador para la animación de morirse - bool mInvulnerable; // Indica si el jugador es invulnerable - Uint16 mInvulnerableCounter; // Contador para la invulnerabilidad - bool mExtraHit; // Indica si el jugador tiene un toque extra - Uint8 mCoffees; // Indica cuantos cafes lleva acumulados - bool mPowerUp; // Indica si el jugador tiene activo el modo PowerUp - Uint8 mPowerUpHeadOffset; // Variable para dibujar la cabeza normal o la del powerup - bool mInput; // Indica si puede recibir ordenes de entrada + Uint8 statusWalking; // Estado del jugador + Uint8 statusFiring; // Estado del jugador - AnimatedSprite *mSpriteLegs; // Sprite para dibujar las piernas - AnimatedSprite *mSpriteBody; // Sprite para dibujar el cuerpo - AnimatedSprite *mSpriteHead; // Sprite para dibujar la cabeza - LTexture *mPlayerDeadTexture; // Textura con los gráficos para la animación de muerte + 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 + Uint8 coffees; // Indica cuantos cafes lleva acumulados + bool powerUp; // Indica si el jugador tiene activo el modo PowerUp + Uint8 powerUpHeadOffset; // Variable para dibujar la cabeza normal o la del powerup + bool input; // Indica si puede recibir ordenes de entrada + circle_t mCollider; // Circulo de colisión del jugador - circle_t mCollider; // Circulo de colisión del jugador - void shiftColliders(); // Actualiza el circulo de colisión a la posición del jugador + // Actualiza el circulo de colisión a la posición del jugador + void shiftColliders(); // Actualiza el valor de la variable void updateInvulnerableCounter(); @@ -93,11 +103,11 @@ private: void updatePowerUpHeadOffset(); public: - Uint8 mDeathIndex; // Apaño rapidito. Indice de SmartSprite donde esta ubicado el sprite de morirse - Uint16 mPowerUpCounter; // Temporizador para el modo PowerUp + Uint8 deathIndex; // Apaño rapidito. Indice de SmartSprite donde esta ubicado el sprite de morirse + Uint16 powerUpCounter; // Temporizador para el modo PowerUp // Constructor - Player(float x, int y, LTexture *textureLegs, LTexture *textureBody, LTexture *textureHead, LTexture *textureDead, SDL_Renderer *renderer); + Player(SDL_Renderer *renderer, Asset *asset, float x, int y); // Destructor ~Player(); @@ -105,15 +115,18 @@ public: // Iniciador void init(); + // Actualiza al jugador a su posicion, animación y controla los contadores + void update(); + + // Pinta el jugador en pantalla + void render(); + // Actua en consecuencia de la entrada recibida void setInput(Uint8 input); // Mueve el jugador a la posición y animación que le corresponde void move(); - // Pinta el jugador en pantalla - void render(); - // Establece el estado del jugador void setWalkingStatus(Uint8 status); @@ -144,9 +157,6 @@ public: // Actualiza el valor de la variable void updateCooldown(); - // Actualiza al jugador a su posicion, animación y controla los contadores - void update(); - // Obtiene la puntuación del jugador Uint32 getScore();