#include "const.h" #include "player.h" // Constructor Player::Player() { mSpriteLegs = new AnimatedSprite(); mSpriteBody = new AnimatedSprite(); mSpriteHead = new AnimatedSprite(); } // Destructor Player::~Player() { delete mSpriteLegs; mSpriteLegs = nullptr; delete mSpriteBody; mSpriteBody = nullptr; delete mSpriteHead; mSpriteHead = nullptr; } // Iniciador void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody, LTexture *textureHead, LTexture *textureDead, SDL_Renderer *renderer) { // Copia punteros mPlayerDeadTexture = textureDead; // Inicializa variables de estado mAlive = true; mStatusWalking = PLAYER_STATUS_WALKING_STOP; mStatusFiring = PLAYER_STATUS_FIRING_NO; mInvulnerable = false; mInvulnerableCounter = PLAYER_INVULNERABLE_COUNTER; mPowerUp = false; mPowerUpCounter = PLAYER_POWERUP_COUNTER; mExtraHit = false; mCoffees = 0; mInput = true; // Establece la altura y el ancho del jugador mWidth = 3 * BLOCK; mHeight = 3 * BLOCK; // Establece la posición inicial del jugador mPosX = x; mPosY = y; // Establece el tamaño del circulo de colisión mCollider.r = 7; // Actualiza la posición del circulo de colisión shiftColliders(); // Establece la velocidad inicial mVelX = 0; mVelY = 0; // Establece la velocidad base mBaseSpeed = 1.5; // Establece la puntuación inicial mScore = 0; // Establece el multiplicador de puntos inicial mScoreMultiplier = 1.0f; // Inicia el contador para la cadencia de disparo mCooldown = 10; // Inicia el sprite mSpriteLegs->init(textureLegs, renderer); mSpriteBody->init(textureBody, renderer); mSpriteHead->init(textureHead, renderer); // Establece el alto y ancho del sprite mSpriteLegs->setWidth(mWidth); mSpriteLegs->setHeight(mHeight); mSpriteBody->setWidth(mWidth); mSpriteBody->setHeight(mHeight); mSpriteHead->setWidth(mWidth); mSpriteHead->setHeight(mHeight); // Establece la posición del sprite mSpriteLegs->setPosX(int(mPosX)); mSpriteLegs->setPosY(mPosY); mSpriteBody->setPosX(int(mPosX)); mSpriteBody->setPosY(mPosY); mSpriteHead->setPosX(int(mPosX)); mSpriteHead->setPosY(mPosY); // Inicializa las variables para la animación mSpriteLegs->setCurrentFrame(0); mSpriteLegs->setAnimationCounter(0); mSpriteBody->setCurrentFrame(0); mSpriteBody->setAnimationCounter(0); mSpriteHead->setCurrentFrame(0); mSpriteHead->setAnimationCounter(0); // Establece el numero de frames de cada animacion mSpriteLegs->setAnimationNumFrames(PLAYER_ANIMATION_LEGS_WALKING_STOP, 4); mSpriteLegs->setAnimationNumFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 4); mSpriteLegs->setAnimationNumFrames(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 4); mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, 4); mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, 4); mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, 4); mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 4); mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 4); mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 4); mSpriteHead->setAnimationNumFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 4); mSpriteHead->setAnimationNumFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 4); mSpriteHead->setAnimationNumFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 4); mSpriteHead->setAnimationNumFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 4); mSpriteHead->setAnimationNumFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, 4); mSpriteHead->setAnimationNumFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, 4); // 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); 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); 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); // 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); 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); 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); // 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); // 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)); } // Actua en consecuencia de la entrada recibida void Player::setInput(Uint8 input) { switch (input) { case INPUT_LEFT: mVelX = -mBaseSpeed; setWalkingStatus(PLAYER_STATUS_WALKING_LEFT); break; case INPUT_RIGHT: mVelX = mBaseSpeed; setWalkingStatus(PLAYER_STATUS_WALKING_RIGHT); break; case INPUT_FIRE_UP: setFiringStatus(PLAYER_STATUS_FIRING_UP); break; case INPUT_FIRE_LEFT: setFiringStatus(PLAYER_STATUS_FIRING_LEFT); break; case INPUT_FIRE_RIGHT: setFiringStatus(PLAYER_STATUS_FIRING_RIGHT); break; default: mVelX = 0; setWalkingStatus(PLAYER_STATUS_WALKING_STOP); break; } } // Mueve el jugador a la posición y animación que le corresponde void Player::move() { if (isAlive()) { // Mueve el jugador a derecha o izquierda mPosX += mVelX; // Si el jugador abandona el area de juego por los laterales if ((mPosX < PLAY_AREA_LEFT - 5) || (mPosX + mWidth > PLAY_AREA_RIGHT + 5)) { // Restaura su posición mPosX -= mVelX; } // Actualiza la posición del sprite mSpriteLegs->setPosX(getPosX()); mSpriteLegs->setPosY(mPosY); mSpriteBody->setPosX(getPosX()); mSpriteBody->setPosY(mPosY); mSpriteHead->setPosX(getPosX()); mSpriteHead->setPosY(mPosY); } } // Pinta el jugador en pantalla void Player::render() { if (isAlive()) { if (mInvulnerable) { if ((mInvulnerableCounter % 10) > 4) { mSpriteLegs->render(); mSpriteBody->render(); mSpriteHead->render(); } } else { mSpriteLegs->render(); mSpriteBody->render(); mSpriteHead->render(); } } } // Establece el estado del jugador cuando camina void Player::setWalkingStatus(Uint8 status) { // Si cambiamos de estado, reiniciamos la animación if (mStatusWalking != status) { mStatusWalking = status; mSpriteLegs->setCurrentFrame(0); } } // Establece el estado del jugador cuando dispara void Player::setFiringStatus(Uint8 status) { // Si cambiamos de estado, reiniciamos la animación if (mStatusFiring != status) { mStatusFiring = status; mSpriteBody->setCurrentFrame(0); mSpriteHead->setCurrentFrame(0); } } // Establece la animación correspondiente al estado 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); } // 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) + (mPowerUp * 96), mHeight * (0 + (6 * mCoffees)), mWidth, mHeight); mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, i, (mWidth * i) + (mPowerUp * 96), mHeight * (1 + (6 * mCoffees)), mWidth, mHeight); mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, i, (mWidth * i) + (mPowerUp * 96), mHeight * (2 + (6 * mCoffees)), mWidth, mHeight); mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, i, (mWidth * i) + (mPowerUp * 96), mHeight * (3 + (6 * mCoffees)), mWidth, mHeight); mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, i, (mWidth * i) + (mPowerUp * 96), mHeight * (4 + (6 * mCoffees)), mWidth, mHeight); mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, i, (mWidth * i) + (mPowerUp * 96), mHeight * (5 + (6 * mCoffees)), mWidth, mHeight); } switch (mStatusWalking) { case PLAYER_STATUS_WALKING_LEFT: mSpriteLegs->animate(PLAYER_ANIMATION_LEGS_WALKING_LEFT); switch (mStatusFiring) { case PLAYER_STATUS_FIRING_UP: mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP); mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_UP); break; case PLAYER_STATUS_FIRING_LEFT: mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT); mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_LEFT); break; case PLAYER_STATUS_FIRING_RIGHT: mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT); mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_RIGHT); break; case PLAYER_STATUS_FIRING_NO: mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_LEFT); mSpriteHead->animate(PLAYER_ANIMATION_HEAD_WALKING_LEFT); break; default: mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP); mSpriteHead->animate(PLAYER_ANIMATION_HEAD_WALKING_STOP); break; } break; case PLAYER_STATUS_WALKING_RIGHT: mSpriteLegs->animate(PLAYER_ANIMATION_LEGS_WALKING_RIGHT); switch (mStatusFiring) { case PLAYER_STATUS_FIRING_UP: mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP); mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_UP); break; case PLAYER_STATUS_FIRING_LEFT: mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT); mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_LEFT); break; case PLAYER_STATUS_FIRING_RIGHT: mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT); mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_RIGHT); break; case PLAYER_STATUS_FIRING_NO: mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_RIGHT); mSpriteHead->animate(PLAYER_ANIMATION_HEAD_WALKING_RIGHT); break; default: mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP); mSpriteHead->animate(PLAYER_ANIMATION_HEAD_WALKING_STOP); break; } break; case PLAYER_STATUS_WALKING_STOP: mSpriteLegs->animate(PLAYER_ANIMATION_LEGS_WALKING_STOP); switch (mStatusFiring) { case PLAYER_STATUS_FIRING_UP: mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP); mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_UP); break; case PLAYER_STATUS_FIRING_LEFT: mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT); mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_LEFT); break; case PLAYER_STATUS_FIRING_RIGHT: mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT); mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_RIGHT); break; case PLAYER_STATUS_FIRING_NO: mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP); mSpriteHead->animate(PLAYER_ANIMATION_HEAD_WALKING_STOP); break; default: mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP); mSpriteHead->animate(PLAYER_ANIMATION_HEAD_WALKING_STOP); break; } break; default: mSpriteLegs->animate(PLAYER_ANIMATION_LEGS_WALKING_STOP); break; } } // Obtiene el valor de la variable int Player::getPosX() { return int(mPosX); } // Obtiene el valor de la variable int Player::getPosY() { return mPosY; } // Obtiene el valor de la variable int Player::getWidth() { return mWidth; } // Obtiene el valor de la variable int Player::getHeight() { return mHeight; } // 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) { return false; } else { return true; } } // Establece el valor de la variable void Player::setFireCooldown(int time) { mCooldown = time; } // Actualiza el valor de la variable void Player::updateCooldown() { if (mCooldown > 0) { mCooldown--; if (mPowerUp) mCooldown--; } else { setFiringStatus(PLAYER_STATUS_FIRING_NO); } } // Actualiza al jugador a su posicion, animación y controla los contadores void Player::update() { move(); setAnimation(); shiftColliders(); updateCooldown(); updatePowerUpCounter(); updateInvulnerableCounter(); } // Obtiene la puntuación del jugador Uint32 Player::getScore() { return mScore; } // Asigna un valor a la puntuación del jugador void Player::setScore(Uint32 score) { mScore = score; } // Incrementa la puntuación del jugador void Player::addScore(Uint32 score) { mScore += score; } // Obtiene el valor de la variable bool Player::isAlive() { return mAlive; } // Establece el valor de la variable void Player::setAlive(bool value) { mAlive = value; } // Obtiene el valor de la variable float Player::getScoreMultiplier() { return mScoreMultiplier; } // Establece el valor de la variable void Player::setScoreMultiplier(float value) { mScoreMultiplier = value; } // Aumenta el valor de la variable hasta un máximo void Player::incScoreMultiplier() { if (mScoreMultiplier < 5.0f) mScoreMultiplier += 0.1f; else mScoreMultiplier = 5.0f; } // Decrementa el valor de la variable hasta un mínimo void Player::decScoreMultiplier() { if (mScoreMultiplier > 1.0f) mScoreMultiplier -= 0.1f; else mScoreMultiplier = 1.0f; } // Obtiene el valor de la variable bool Player::isInvulnerable() { return mInvulnerable; } // Establece el valor de la variable void Player::setInvulnerable(bool value) { mInvulnerable = value; } // Obtiene el valor de la variable Uint16 Player::getInvulnerableCounter() { return mInvulnerableCounter; } // Establece el valor de la variable void Player::setInvulnerableCounter(Uint16 value) { mInvulnerableCounter = value; } // Actualiza el valor de la variable void Player::updateInvulnerableCounter() { if (mInvulnerableCounter > 0) { --mInvulnerableCounter; } else { mInvulnerable = false; mInvulnerableCounter = PLAYER_INVULNERABLE_COUNTER; } } // Obtiene el valor de la variable bool Player::isPowerUp() { return mPowerUp; } // Establece el valor de la variable void Player::setPowerUp(bool value) { mPowerUp = value; } // Obtiene el valor de la variable Uint16 Player::getPowerUpCounter() { return mPowerUpCounter; } // Establece el valor de la variable void Player::setPowerUpCounter(Uint16 value) { mPowerUpCounter = value; } // Actualiza el valor de la variable void Player::updatePowerUpCounter() { if ((mPowerUpCounter > 0) && (mPowerUp)) { mPowerUpCounter--; } else { mPowerUp = false; mPowerUpCounter = PLAYER_POWERUP_COUNTER; } } // Obtiene el valor de la variable bool Player::hasExtraHit() { return mExtraHit; } // Concede un toque extra al jugador void Player::giveExtraHit() { mExtraHit = true; mCoffees++; if (mCoffees > 2) mCoffees = 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; } // Habilita la entrada de ordenes void Player::enableInput() { mInput = true; } // Deshabilita la entrada de ordenes void Player::disableInput() { mInput = false; } // Devuelve el numero de cafes actuales Uint8 Player::getCoffees() { return mCoffees; } // Obtiene el circulo de colisión circle_t &Player::getCollider() { return mCollider; } // 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)); } // Obtiene el puntero a la textura con los gráficos de la animación de morir LTexture *Player::getDeadTexture() { return mPlayerDeadTexture; }