#include "const.h"
#include "player.h"

// Constructor
Player::Player()
{
	mSpriteLegs = new AnimatedSprite();
	mSpriteBody = new AnimatedSprite();
	init(0, 0, nullptr, nullptr, nullptr);
}

// Destructor
Player::~Player()
{
	init(0, 0, nullptr, nullptr, nullptr);
	mSpriteLegs = nullptr;
	mSpriteBody = nullptr;
	delete mSpriteLegs;
	delete mSpriteBody;
}

// Iniciador
void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody, SDL_Renderer *renderer)
{
	// Inicializa variables de estado
	mAlive = true;
	mStatusWalking = PLAYER_STATUS_WALKING_STOP;
	mStatusFiring = PLAYER_STATUS_FIRING_NO;
	mInvulnerable = false;
	mInvulnerableTimer = PLAYER_INVULNERABLE_TIMER;
	mExtraHit = false;

	// 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 el numero inicial de vidas
	mStartingLives = 3;
	mLives = mStartingLives;

	// 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);

	// Establece el alto y ancho del sprite
	mSpriteLegs->setWidth(mWidth);
	mSpriteLegs->setHeight(mHeight);

	mSpriteBody->setWidth(mWidth);
	mSpriteBody->setHeight(mHeight);

	// Establece la posición del sprite
	mSpriteLegs->setPosX(int(mPosX));
	mSpriteLegs->setPosY(mPosY);

	mSpriteBody->setPosX(int(mPosX));
	mSpriteBody->setPosY(mPosY);

	// Inicializa las variables para la animación
	mSpriteLegs->setCurrentFrame(0);
	mSpriteLegs->setAnimationCounter(0);

	mSpriteBody->setCurrentFrame(0);
	mSpriteBody->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);
	mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 4);
	mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 4);
	mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 4);
	mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 4);
	mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 4);
	mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 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);
	mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 5);
	mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 5);
	mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 5);
	mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 5);
	mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 10);
	mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 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);
	mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, true);
	mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, true);
	mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, true);
	mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, true);
	mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, true);
	mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 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);

	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 0, mWidth * 0, mHeight * 6, mWidth, mHeight);
	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 1, mWidth * 1, mHeight * 6, mWidth, mHeight);
	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 2, mWidth * 2, mHeight * 6, mWidth, mHeight);
	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 3, mWidth * 3, mHeight * 6, mWidth, mHeight);

	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 0, mWidth * 0, mHeight * 7, mWidth, mHeight);
	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 1, mWidth * 1, mHeight * 7, mWidth, mHeight);
	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 2, mWidth * 2, mHeight * 7, mWidth, mHeight);
	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 3, mWidth * 3, mHeight * 7, mWidth, mHeight);

	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 0, mWidth * 0, mHeight * 8, mWidth, mHeight);
	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 1, mWidth * 1, mHeight * 8, mWidth, mHeight);
	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 2, mWidth * 2, mHeight * 8, mWidth, mHeight);
	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 3, mWidth * 3, mHeight * 8, mWidth, mHeight);

	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 0, mWidth * 0, mHeight * 9, mWidth, mHeight);
	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 1, mWidth * 1, mHeight * 9, mWidth, mHeight);
	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 2, mWidth * 2, mHeight * 9, mWidth, mHeight);
	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 3, mWidth * 3, mHeight * 9, mWidth, mHeight);

	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 0, mWidth * 0, mHeight * 10, mWidth, mHeight);
	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 1, mWidth * 1, mHeight * 10, mWidth, mHeight);
	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 2, mWidth * 2, mHeight * 10, mWidth, mHeight);
	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 3, mWidth * 3, mHeight * 10, mWidth, mHeight);

	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 0, mWidth * 0, mHeight * 11, mWidth, mHeight);
	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 1, mWidth * 1, mHeight * 11, mWidth, mHeight);
	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 2, mWidth * 2, mHeight * 11, mWidth, mHeight);
	mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 3, mWidth * 3, mHeight * 11, 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));
}

// Actua en consecuencia de la entrada recibida
void Player::setInput(Uint8 input)
{
	switch (input)
	{
	case INPUT_LEFT:
		mVelX = -mBaseSpeed;
		if (mExtraHit)
		{
			setWalkingStatus(PLAYER_STATUS_WALKING_LEFT);
		}
		else
		{
			setWalkingStatus(PLAYER_STATUS_WALKING_LEFT);
		}
		break;

	case INPUT_RIGHT:
		mVelX = mBaseSpeed;
		if (mExtraHit)
		{
			setWalkingStatus(PLAYER_STATUS_WALKING_RIGHT);
		}
		else
		{
			setWalkingStatus(PLAYER_STATUS_WALKING_RIGHT);
		}
		break;

	case INPUT_FIRE_UP:
		if (mExtraHit)
		{
			setFiringStatus(PLAYER_STATUS_FIRING_UP);
		}
		else
		{
			setFiringStatus(PLAYER_STATUS_FIRING_UP);
		}
		break;

	case INPUT_FIRE_LEFT:
		if (mExtraHit)
		{
			setFiringStatus(PLAYER_STATUS_FIRING_LEFT);
		}
		else
		{
			setFiringStatus(PLAYER_STATUS_FIRING_LEFT);
		}
		break;

	case INPUT_FIRE_RIGHT:
		if (mExtraHit)
		{
			setFiringStatus(PLAYER_STATUS_FIRING_RIGHT);
		}
		else
		{
			setFiringStatus(PLAYER_STATUS_FIRING_RIGHT);
		}
		break;

	default:
		mVelX = 0;
		if (mExtraHit)
		{
			setWalkingStatus(PLAYER_STATUS_WALKING_STOP);
		}
		else
		{
			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) || (mPosX + mWidth > PLAY_AREA_RIGHT))
		{
			// Restaura su posición
			mPosX -= mVelX;
		}

		// Actualiza la posición del sprite
		mSpriteLegs->setPosX(getPosX());
		mSpriteLegs->setPosY(mPosY);

		mSpriteBody->setPosX(getPosX());
		mSpriteBody->setPosY(mPosY);
	}
}

// Pinta el jugador en pantalla
void Player::render()
{
	if (isAlive())
	{
		if (mInvulnerable)
		{
			if ((mInvulnerableTimer % 10) > 4)
			{
				mSpriteLegs->render();
				mSpriteBody->render();
			}
		}
		else
		{
			mSpriteLegs->render();
			mSpriteBody->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);
	}
}

// Establece la animación correspondiente al estado
void Player::setAnimation()
{
	switch (mStatusWalking)
	{
	case PLAYER_STATUS_WALKING_LEFT:
		mSpriteLegs->animate(PLAYER_ANIMATION_LEGS_WALKING_LEFT);
		switch (mStatusFiring)
		{
		case PLAYER_STATUS_FIRING_UP:
			if (mExtraHit)
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT);
			}
			else
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
			}

			break;

		case PLAYER_STATUS_FIRING_LEFT:
			if (mExtraHit)
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT);
			}
			else
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
			}

			break;

		case PLAYER_STATUS_FIRING_RIGHT:
			if (mExtraHit)
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT);
			}
			else
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
			}

			break;

		case PLAYER_STATUS_FIRING_NO:
			if (mExtraHit)
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT);
			}
			else
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_LEFT);
			}

			break;

		default:
			mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
			break;
		}
		break;

	case PLAYER_STATUS_WALKING_RIGHT:
		mSpriteLegs->animate(PLAYER_ANIMATION_LEGS_WALKING_RIGHT);
		switch (mStatusFiring)
		{
		case PLAYER_STATUS_FIRING_UP:
			if (mExtraHit)
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT);
			}
			else
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
			}

			break;

		case PLAYER_STATUS_FIRING_LEFT:
			if (mExtraHit)
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT);
			}
			else
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
			}

			break;

		case PLAYER_STATUS_FIRING_RIGHT:
			if (mExtraHit)
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT);
			}
			else
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
			}

			break;

		case PLAYER_STATUS_FIRING_NO:
			if (mExtraHit)
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT);
			}
			else
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_RIGHT);
			}

			break;

		default:
			mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
			break;
		}
		break;

	case PLAYER_STATUS_WALKING_STOP:
		mSpriteLegs->animate(PLAYER_ANIMATION_LEGS_WALKING_STOP);
		switch (mStatusFiring)
		{
		case PLAYER_STATUS_FIRING_UP:
			if (mExtraHit)
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT);
			}
			else
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
			}

			break;

		case PLAYER_STATUS_FIRING_LEFT:
			if (mExtraHit)
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT);
			}
			else
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
			}

			break;

		case PLAYER_STATUS_FIRING_RIGHT:
			if (mExtraHit)
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT);
			}
			else
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
			}

			break;

		case PLAYER_STATUS_FIRING_NO:
			if (mExtraHit)
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT);
			}
			else
			{
				mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
			}

			break;

		default:
			mSpriteBody->animate(PLAYER_ANIMATION_BODY_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;
	}
	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();
	updateInvulnerableTimer();
}

// Obtiene la puntuación del jugador
int Player::getScore()
{
	return mScore;
}

// Asigna un valor a la puntuación del jugador
void Player::setScore(int score)
{
	mScore = score;
}

// Incrementa la puntuación del jugador
void Player::addScore(int 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;
	}
}

// Decrementa el valor de la variable hasta un mínimo
void Player::decScoreMultiplier()
{
	if (mScoreMultiplier > 1.0f)
	{
		mScoreMultiplier -= 0.1f;
	}
}

// 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
bool Player::getInvulnerableTimer()
{
	return mInvulnerableTimer;
}

// Establece el valor de la variable
void Player::setInvulnerableTimer(Uint16 value)
{
	mInvulnerableTimer = value;
}

// Actualiza el valor de la variable
void Player::updateInvulnerableTimer()
{
	if (mInvulnerableTimer > 0)
	{
		--mInvulnerableTimer;
	}
	else
	{
		mInvulnerable = false;
		mInvulnerableTimer = PLAYER_INVULNERABLE_TIMER;
	}
}

// Obtiene el valor de la variable
bool Player::hasExtraHit()
{
	return mExtraHit;
}

// Concede un toque extra al jugador
void Player::giveExtraHit()
{
	mExtraHit = true;
}

// Quita el toque extra al jugador
void Player::removeExtraHit()
{
	mExtraHit = false;
	mInvulnerable = true;
	mInvulnerableTimer = PLAYER_INVULNERABLE_TIMER;
}

// Obtiene el circulo de colisión
Circle &Player::getCollider()
{
	return mCollider;
}

// Actualiza el circulo de colisión a la posición del jugador
void Player::shiftColliders()
{
	mCollider.x = Uint16(mPosX + (mWidth / 2));
	mCollider.y = mPosY + (mHeight / 2);
}