forked from jaildesigner-jailgames/coffee_crisis
600 lines
17 KiB
C++
600 lines
17 KiB
C++
#include "const.h"
|
|
#include "player.h"
|
|
|
|
// Constructor
|
|
Player::Player()
|
|
{
|
|
mSpriteLegs = new AnimatedSprite();
|
|
mSpriteBody = new AnimatedSprite();
|
|
mSpriteHead = 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;
|
|
delete mSpriteHead;
|
|
}
|
|
|
|
// 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;
|
|
mInvulnerableCounter = PLAYER_INVULNERABLE_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);
|
|
|
|
// 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);
|
|
|
|
// 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);
|
|
|
|
// 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);
|
|
|
|
// 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);
|
|
|
|
// 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;
|
|
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);
|
|
}
|
|
}
|
|
|
|
// Pinta el jugador en pantalla
|
|
void Player::render()
|
|
{
|
|
if (isAlive())
|
|
{
|
|
if (mInvulnerable)
|
|
{
|
|
if ((mInvulnerableCounter % 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()
|
|
{
|
|
// Actualiza los frames de la animación en función del número de cafes
|
|
for (Uint8 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);
|
|
}
|
|
|
|
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);
|
|
break;
|
|
|
|
case PLAYER_STATUS_FIRING_LEFT:
|
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
|
|
break;
|
|
|
|
case PLAYER_STATUS_FIRING_RIGHT:
|
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
|
|
break;
|
|
|
|
case PLAYER_STATUS_FIRING_NO:
|
|
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:
|
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
|
|
break;
|
|
|
|
case PLAYER_STATUS_FIRING_LEFT:
|
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
|
|
break;
|
|
|
|
case PLAYER_STATUS_FIRING_RIGHT:
|
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
|
|
break;
|
|
|
|
case PLAYER_STATUS_FIRING_NO:
|
|
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:
|
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
|
|
break;
|
|
|
|
case PLAYER_STATUS_FIRING_LEFT:
|
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
|
|
break;
|
|
|
|
case PLAYER_STATUS_FIRING_RIGHT:
|
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
|
|
break;
|
|
|
|
case PLAYER_STATUS_FIRING_NO:
|
|
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();
|
|
updateInvulnerableCounter();
|
|
}
|
|
|
|
// 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
|
|
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::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 = Uint16(mPosX + (mWidth / 2));
|
|
mCollider.y = mPosY + (mHeight / 2);
|
|
} |