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

// Constructor
Player::Player(float x, int y, LTexture *textureLegs, LTexture *textureBody, LTexture *textureHead, LTexture *textureDead, SDL_Renderer *renderer)
{
	mSpriteLegs = new AnimatedSprite(textureLegs, renderer);
	mSpriteBody = new AnimatedSprite(textureBody, renderer);
	mSpriteHead = new AnimatedSprite(textureHead, renderer);

	// Copia punteros
	mPlayerDeadTexture = textureDead;

	// Establece la posición inicial del jugador
	mPosX = x;
	mPosY = y;

	init();
}

// Destructor
Player::~Player()
{
	delete mSpriteLegs;
	delete mSpriteBody;
	delete mSpriteHead;
}

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

	// Establece la altura y el ancho del jugador
	mWidth = 3 * BLOCK;
	mHeight = 3 * BLOCK;

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

	// 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 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_BUTTON_2:
		setFiringStatus(PLAYER_STATUS_FIRING_UP);
		break;

	case INPUT_BUTTON_1:
		setFiringStatus(PLAYER_STATUS_FIRING_LEFT);
		break;

	case INPUT_BUTTON_3:
		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))
			mPosX -= mVelX; // Restaura su posición

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

	switch (mStatusWalking)
	{
	case PLAYER_STATUS_WALKING_LEFT:
		mSpriteLegs->setCurrentAnimation(PLAYER_ANIMATION_LEGS_WALKING_LEFT);
		mSpriteLegs->animate();
		switch (mStatusFiring)
		{
		case PLAYER_STATUS_FIRING_UP:
			mSpriteBody->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_UP);
			mSpriteBody->animate();
			mSpriteHead->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_UP);
			mSpriteHead->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();
			break;

		case PLAYER_STATUS_FIRING_RIGHT:
			mSpriteBody->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
			mSpriteBody->animate();
			mSpriteHead->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_RIGHT);
			mSpriteHead->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();
			break;

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

	case PLAYER_STATUS_WALKING_RIGHT:
		mSpriteLegs->setCurrentAnimation(PLAYER_ANIMATION_LEGS_WALKING_RIGHT);
		mSpriteLegs->animate();
		switch (mStatusFiring)
		{
		case PLAYER_STATUS_FIRING_UP:
			mSpriteBody->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_UP);
			mSpriteBody->animate();
			mSpriteHead->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_UP);
			mSpriteHead->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();
			break;

		case PLAYER_STATUS_FIRING_RIGHT:
			mSpriteBody->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
			mSpriteBody->animate();
			mSpriteHead->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_RIGHT);
			mSpriteHead->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();
			break;

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

	case PLAYER_STATUS_WALKING_STOP:
		mSpriteLegs->setCurrentAnimation(PLAYER_ANIMATION_LEGS_WALKING_STOP);
		mSpriteLegs->animate();
		switch (mStatusFiring)
		{
		case PLAYER_STATUS_FIRING_UP:
			mSpriteBody->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_UP);
			mSpriteBody->animate();
			mSpriteHead->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_UP);
			mSpriteHead->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();
			break;

		case PLAYER_STATUS_FIRING_RIGHT:
			mSpriteBody->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
			mSpriteBody->animate();
			mSpriteHead->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_RIGHT);
			mSpriteHead->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();
			break;

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

	default:
		mSpriteLegs->setCurrentAnimation(PLAYER_ANIMATION_LEGS_WALKING_STOP);
		mSpriteLegs->animate();
		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();
	updateDeathCounter();
	updatePowerUpHeadOffset();
}

// 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 (mInvulnerable)
	{
		if (mInvulnerableCounter > 0)
		{
			mInvulnerableCounter--;
		}
		else
		{
			mInvulnerable = false;
			mInvulnerableCounter = PLAYER_INVULNERABLE_COUNTER;
		}
	}
}

// Actualiza el valor de la variable
void Player::updateDeathCounter()
{
	if (!mAlive)
		if (mDeathCounter > 0)
			mDeathCounter--;
}

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

// Obtiene el valor de la variable
Uint16 Player::getDeathCounter()
{
	return mDeathCounter;
}

// Actualiza el valor de la variable
void Player::updatePowerUpHeadOffset()
{
	if (!mPowerUp)
		mPowerUpHeadOffset = 0;
	else
	{
		mPowerUpHeadOffset = 96;
		if (mPowerUpCounter < 300)
		{
			if (mPowerUpCounter % 10 > 4)
				mPowerUpHeadOffset = 96;
			else
				mPowerUpHeadOffset = 0;
		}
	}
}