829 lines
25 KiB
C++
829 lines
25 KiB
C++
#include "const.h"
|
|
#include "player.h"
|
|
|
|
// Constructor
|
|
Player::Player(SDL_Renderer *renderer, Asset *asset, float x, int y)
|
|
{
|
|
// Copia los punteros
|
|
this->renderer = renderer;
|
|
this->asset = asset;
|
|
|
|
// 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
|
|
posX = x;
|
|
posY = y;
|
|
|
|
init();
|
|
}
|
|
|
|
// Destructor
|
|
Player::~Player()
|
|
{
|
|
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
|
|
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
|
|
width = 3 * BLOCK;
|
|
height = 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
|
|
velX = 0;
|
|
velY = 0;
|
|
|
|
// Establece la velocidad base
|
|
baseSpeed = 1.5;
|
|
|
|
// Establece la puntuación inicial
|
|
score = 0;
|
|
|
|
// Establece el multiplicador de puntos inicial
|
|
scoreMultiplier = 1.0f;
|
|
|
|
// Inicia el contador para la cadencia de disparo
|
|
cooldown = 10;
|
|
|
|
// Establece el alto y ancho del sprite
|
|
legsSprite->setWidth(width);
|
|
legsSprite->setHeight(height);
|
|
|
|
bodySprite->setWidth(width);
|
|
bodySprite->setHeight(height);
|
|
|
|
headSprite->setWidth(width);
|
|
headSprite->setHeight(height);
|
|
|
|
// Establece la posición del sprite
|
|
legsSprite->setPosX(int(posX));
|
|
legsSprite->setPosY(posY);
|
|
|
|
bodySprite->setPosX(int(posX));
|
|
bodySprite->setPosY(posY);
|
|
|
|
headSprite->setPosX(int(posX));
|
|
headSprite->setPosY(posY);
|
|
|
|
// Inicializa las variables para la animación
|
|
legsSprite->setCurrentFrame(0);
|
|
legsSprite->setAnimationCounter(0);
|
|
|
|
bodySprite->setCurrentFrame(0);
|
|
bodySprite->setAnimationCounter(0);
|
|
|
|
headSprite->setCurrentFrame(0);
|
|
headSprite->setAnimationCounter(0);
|
|
|
|
// Establece la velocidad de cada animación
|
|
legsSprite->setAnimationSpeed(PLAYER_ANIMATION_LEGS_WALKING_STOP, 10);
|
|
legsSprite->setAnimationSpeed(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 5);
|
|
legsSprite->setAnimationSpeed(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 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);
|
|
|
|
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
|
|
legsSprite->setAnimationLoop(PLAYER_ANIMATION_LEGS_WALKING_STOP, true);
|
|
legsSprite->setAnimationLoop(PLAYER_ANIMATION_LEGS_WALKING_LEFT, true);
|
|
legsSprite->setAnimationLoop(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 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);
|
|
|
|
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
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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
|
|
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
|
|
void Player::setInput(Uint8 input)
|
|
{
|
|
switch (input)
|
|
{
|
|
case INPUT_LEFT:
|
|
velX = -baseSpeed;
|
|
setWalkingStatus(PLAYER_STATUS_WALKING_LEFT);
|
|
break;
|
|
|
|
case INPUT_RIGHT:
|
|
velX = baseSpeed;
|
|
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:
|
|
velX = 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
|
|
posX += velX;
|
|
|
|
// Si el jugador abandona el area de juego por los laterales
|
|
if ((posX < PLAY_AREA_LEFT - 5) || (posX + width > PLAY_AREA_RIGHT + 5))
|
|
posX -= velX; // Restaura su posición
|
|
|
|
// Actualiza la posición del sprite
|
|
legsSprite->setPosX(getPosX());
|
|
legsSprite->setPosY(posY);
|
|
|
|
bodySprite->setPosX(getPosX());
|
|
bodySprite->setPosY(posY);
|
|
|
|
headSprite->setPosX(getPosX());
|
|
headSprite->setPosY(posY);
|
|
}
|
|
}
|
|
|
|
// Pinta el jugador en pantalla
|
|
void Player::render()
|
|
{
|
|
if (isAlive())
|
|
{
|
|
if (invulnerable)
|
|
{
|
|
if ((invulnerableCounter % 10) > 4)
|
|
{
|
|
legsSprite->render();
|
|
bodySprite->render();
|
|
headSprite->render();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
legsSprite->render();
|
|
bodySprite->render();
|
|
headSprite->render();
|
|
}
|
|
}
|
|
}
|
|
|
|
// Establece el estado del jugador cuando camina
|
|
void Player::setWalkingStatus(Uint8 status)
|
|
{
|
|
// Si cambiamos de estado, reiniciamos la animación
|
|
if (statusWalking != status)
|
|
{
|
|
statusWalking = status;
|
|
legsSprite->setCurrentFrame(0);
|
|
}
|
|
}
|
|
|
|
// Establece el estado del jugador cuando dispara
|
|
void Player::setFiringStatus(Uint8 status)
|
|
{
|
|
// Si cambiamos de estado, reiniciamos la animación
|
|
if (statusFiring != status)
|
|
{
|
|
statusFiring = status;
|
|
bodySprite->setCurrentFrame(0);
|
|
headSprite->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++)
|
|
{
|
|
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++)
|
|
{
|
|
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 (statusWalking)
|
|
{
|
|
case PLAYER_STATUS_WALKING_LEFT:
|
|
legsSprite->setCurrentAnimation(PLAYER_ANIMATION_LEGS_WALKING_LEFT);
|
|
legsSprite->animate();
|
|
switch (statusFiring)
|
|
{
|
|
case PLAYER_STATUS_FIRING_UP:
|
|
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_UP);
|
|
bodySprite->animate();
|
|
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_UP);
|
|
headSprite->animate();
|
|
break;
|
|
|
|
case PLAYER_STATUS_FIRING_LEFT:
|
|
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_LEFT);
|
|
bodySprite->animate();
|
|
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_LEFT);
|
|
headSprite->animate();
|
|
break;
|
|
|
|
case PLAYER_STATUS_FIRING_RIGHT:
|
|
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
|
|
bodySprite->animate();
|
|
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_RIGHT);
|
|
headSprite->animate();
|
|
break;
|
|
|
|
case PLAYER_STATUS_FIRING_NO:
|
|
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_WALKING_LEFT);
|
|
bodySprite->animate();
|
|
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_WALKING_LEFT);
|
|
headSprite->animate();
|
|
break;
|
|
|
|
default:
|
|
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:
|
|
legsSprite->setCurrentAnimation(PLAYER_ANIMATION_LEGS_WALKING_RIGHT);
|
|
legsSprite->animate();
|
|
switch (statusFiring)
|
|
{
|
|
case PLAYER_STATUS_FIRING_UP:
|
|
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_UP);
|
|
bodySprite->animate();
|
|
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_UP);
|
|
headSprite->animate();
|
|
break;
|
|
|
|
case PLAYER_STATUS_FIRING_LEFT:
|
|
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_LEFT);
|
|
bodySprite->animate();
|
|
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_LEFT);
|
|
headSprite->animate();
|
|
break;
|
|
|
|
case PLAYER_STATUS_FIRING_RIGHT:
|
|
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
|
|
bodySprite->animate();
|
|
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_RIGHT);
|
|
headSprite->animate();
|
|
break;
|
|
|
|
case PLAYER_STATUS_FIRING_NO:
|
|
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_WALKING_RIGHT);
|
|
bodySprite->animate();
|
|
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_WALKING_RIGHT);
|
|
headSprite->animate();
|
|
break;
|
|
|
|
default:
|
|
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:
|
|
legsSprite->setCurrentAnimation(PLAYER_ANIMATION_LEGS_WALKING_STOP);
|
|
legsSprite->animate();
|
|
switch (statusFiring)
|
|
{
|
|
case PLAYER_STATUS_FIRING_UP:
|
|
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_UP);
|
|
bodySprite->animate();
|
|
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_UP);
|
|
headSprite->animate();
|
|
break;
|
|
|
|
case PLAYER_STATUS_FIRING_LEFT:
|
|
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_LEFT);
|
|
bodySprite->animate();
|
|
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_LEFT);
|
|
headSprite->animate();
|
|
break;
|
|
|
|
case PLAYER_STATUS_FIRING_RIGHT:
|
|
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
|
|
bodySprite->animate();
|
|
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_FIRING_RIGHT);
|
|
headSprite->animate();
|
|
break;
|
|
|
|
case PLAYER_STATUS_FIRING_NO:
|
|
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_WALKING_STOP);
|
|
bodySprite->animate();
|
|
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_WALKING_STOP);
|
|
headSprite->animate();
|
|
break;
|
|
|
|
default:
|
|
bodySprite->setCurrentAnimation(PLAYER_ANIMATION_BODY_WALKING_STOP);
|
|
bodySprite->animate();
|
|
headSprite->setCurrentAnimation(PLAYER_ANIMATION_HEAD_WALKING_STOP);
|
|
headSprite->animate();
|
|
break;
|
|
}
|
|
break;
|
|
|
|
default:
|
|
legsSprite->setCurrentAnimation(PLAYER_ANIMATION_LEGS_WALKING_STOP);
|
|
legsSprite->animate();
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Obtiene el valor de la variable
|
|
int Player::getPosX()
|
|
{
|
|
return int(posX);
|
|
}
|
|
|
|
// Obtiene el valor de la variable
|
|
int Player::getPosY()
|
|
{
|
|
return posY;
|
|
}
|
|
|
|
// Obtiene el valor de la variable
|
|
int Player::getWidth()
|
|
{
|
|
return width;
|
|
}
|
|
|
|
// Obtiene el valor de la variable
|
|
int Player::getHeight()
|
|
{
|
|
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 (cooldown > 0)
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Player::setFireCooldown(int time)
|
|
{
|
|
cooldown = time;
|
|
}
|
|
|
|
// Actualiza el valor de la variable
|
|
void Player::updateCooldown()
|
|
{
|
|
if (cooldown > 0)
|
|
{
|
|
cooldown--;
|
|
if (powerUp)
|
|
cooldown--;
|
|
}
|
|
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 score;
|
|
}
|
|
|
|
// Asigna un valor a la puntuación del jugador
|
|
void Player::setScore(Uint32 score)
|
|
{
|
|
this->score = score;
|
|
}
|
|
|
|
// Incrementa la puntuación del jugador
|
|
void Player::addScore(Uint32 score)
|
|
{
|
|
this->score += score;
|
|
}
|
|
|
|
// Obtiene el valor de la variable
|
|
bool Player::isAlive()
|
|
{
|
|
return alive;
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Player::setAlive(bool value)
|
|
{
|
|
alive = value;
|
|
}
|
|
|
|
// Obtiene el valor de la variable
|
|
float Player::getScoreMultiplier()
|
|
{
|
|
return scoreMultiplier;
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Player::setScoreMultiplier(float value)
|
|
{
|
|
scoreMultiplier = value;
|
|
}
|
|
|
|
// Aumenta el valor de la variable hasta un máximo
|
|
void Player::incScoreMultiplier()
|
|
{
|
|
if (scoreMultiplier < 5.0f)
|
|
{
|
|
scoreMultiplier += 0.1f;
|
|
}
|
|
else
|
|
{
|
|
scoreMultiplier = 5.0f;
|
|
}
|
|
}
|
|
|
|
// Decrementa el valor de la variable hasta un mínimo
|
|
void Player::decScoreMultiplier()
|
|
{
|
|
if (scoreMultiplier > 1.0f)
|
|
{
|
|
scoreMultiplier -= 0.1f;
|
|
}
|
|
else
|
|
{
|
|
scoreMultiplier = 1.0f;
|
|
}
|
|
}
|
|
|
|
// Obtiene el valor de la variable
|
|
bool Player::isInvulnerable()
|
|
{
|
|
return invulnerable;
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Player::setInvulnerable(bool value)
|
|
{
|
|
invulnerable = value;
|
|
}
|
|
|
|
// Obtiene el valor de la variable
|
|
Uint16 Player::getInvulnerableCounter()
|
|
{
|
|
return invulnerableCounter;
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Player::setInvulnerableCounter(Uint16 value)
|
|
{
|
|
invulnerableCounter = value;
|
|
}
|
|
|
|
// Actualiza el valor de la variable
|
|
void Player::updateInvulnerableCounter()
|
|
{
|
|
if (invulnerable)
|
|
{
|
|
if (invulnerableCounter > 0)
|
|
{
|
|
invulnerableCounter--;
|
|
}
|
|
else
|
|
{
|
|
invulnerable = false;
|
|
invulnerableCounter = PLAYER_INVULNERABLE_COUNTER;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Actualiza el valor de la variable
|
|
void Player::updateDeathCounter()
|
|
{
|
|
if (!alive)
|
|
{
|
|
if (deathCounter > 0)
|
|
{
|
|
deathCounter--;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Obtiene el valor de la variable
|
|
bool Player::isPowerUp()
|
|
{
|
|
return powerUp;
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Player::setPowerUp(bool value)
|
|
{
|
|
powerUp = value;
|
|
}
|
|
|
|
// Obtiene el valor de la variable
|
|
Uint16 Player::getPowerUpCounter()
|
|
{
|
|
return powerUpCounter;
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Player::setPowerUpCounter(Uint16 value)
|
|
{
|
|
powerUpCounter = value;
|
|
}
|
|
|
|
// Actualiza el valor de la variable
|
|
void Player::updatePowerUpCounter()
|
|
{
|
|
if ((powerUpCounter > 0) && (powerUp))
|
|
{
|
|
powerUpCounter--;
|
|
}
|
|
else
|
|
{
|
|
powerUp = false;
|
|
powerUpCounter = PLAYER_POWERUP_COUNTER;
|
|
}
|
|
}
|
|
|
|
// Obtiene el valor de la variable
|
|
bool Player::hasExtraHit()
|
|
{
|
|
return extraHit;
|
|
}
|
|
|
|
// Concede un toque extra al jugador
|
|
void Player::giveExtraHit()
|
|
{
|
|
extraHit = true;
|
|
coffees++;
|
|
if (coffees > 2)
|
|
{
|
|
coffees = 2;
|
|
}
|
|
}
|
|
|
|
// Quita el toque extra al jugador
|
|
void Player::removeExtraHit()
|
|
{
|
|
if (coffees > 0)
|
|
{
|
|
coffees--;
|
|
}
|
|
if (coffees == 0)
|
|
{
|
|
extraHit = false;
|
|
}
|
|
invulnerable = true;
|
|
invulnerableCounter = PLAYER_INVULNERABLE_COUNTER;
|
|
}
|
|
|
|
// Habilita la entrada de ordenes
|
|
void Player::enableInput()
|
|
{
|
|
input = true;
|
|
}
|
|
|
|
// Deshabilita la entrada de ordenes
|
|
void Player::disableInput()
|
|
{
|
|
input = false;
|
|
}
|
|
|
|
// Devuelve el numero de cafes actuales
|
|
Uint8 Player::getCoffees()
|
|
{
|
|
return coffees;
|
|
}
|
|
|
|
// 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(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 deathTexture;
|
|
}
|
|
|
|
// Obtiene el valor de la variable
|
|
Uint16 Player::getDeathCounter()
|
|
{
|
|
return deathCounter;
|
|
}
|
|
|
|
// Actualiza el valor de la variable
|
|
void Player::updatePowerUpHeadOffset()
|
|
{
|
|
if (!powerUp)
|
|
{
|
|
powerUpHeadOffset = 0;
|
|
}
|
|
else
|
|
{
|
|
powerUpHeadOffset = 96;
|
|
if (powerUpCounter < 300)
|
|
{
|
|
if (powerUpCounter % 10 > 4)
|
|
{
|
|
powerUpHeadOffset = 96;
|
|
}
|
|
else
|
|
{
|
|
powerUpHeadOffset = 0;
|
|
}
|
|
}
|
|
}
|
|
} |