|
|
|
|
@@ -9,10 +9,10 @@ Player::Player(SDL_Renderer *renderer, Asset *asset, float x, int y)
|
|
|
|
|
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"));
|
|
|
|
|
legsTexture = new LTexture(renderer, asset->get("new_player1_legs.png"));
|
|
|
|
|
bodyTexture = new LTexture(renderer, asset->get("new_player1_body.png"));
|
|
|
|
|
headTexture = new LTexture(renderer, asset->get("new_player1_head.png"));
|
|
|
|
|
deathTexture = new LTexture(renderer, asset->get("new_player1_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"));
|
|
|
|
|
@@ -57,17 +57,16 @@ void Player::init()
|
|
|
|
|
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;
|
|
|
|
|
width = 24;
|
|
|
|
|
height = 24;
|
|
|
|
|
|
|
|
|
|
// Establece el tamaño del circulo de colisión
|
|
|
|
|
mCollider.r = 7;
|
|
|
|
|
collider.r = 7;
|
|
|
|
|
|
|
|
|
|
// Actualiza la posición del circulo de colisión
|
|
|
|
|
shiftColliders();
|
|
|
|
|
@@ -88,154 +87,20 @@ void Player::init()
|
|
|
|
|
// 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->setPosX(posX);
|
|
|
|
|
legsSprite->setPosY(posY);
|
|
|
|
|
|
|
|
|
|
bodySprite->setPosX(int(posX));
|
|
|
|
|
bodySprite->setPosX(posX);
|
|
|
|
|
bodySprite->setPosY(posY);
|
|
|
|
|
|
|
|
|
|
headSprite->setPosX(int(posX));
|
|
|
|
|
headSprite->setPosX(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));
|
|
|
|
|
legsSprite->setCurrentAnimation("stand");
|
|
|
|
|
bodySprite->setCurrentAnimation("stand");
|
|
|
|
|
headSprite->setCurrentAnimation("stand");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Actua en consecuencia de la entrada recibida
|
|
|
|
|
@@ -326,7 +191,7 @@ void Player::setWalkingStatus(Uint8 status)
|
|
|
|
|
if (statusWalking != status)
|
|
|
|
|
{
|
|
|
|
|
statusWalking = status;
|
|
|
|
|
legsSprite->setCurrentFrame(0);
|
|
|
|
|
// legsSprite->setCurrentFrame(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -337,169 +202,52 @@ void Player::setFiringStatus(Uint8 status)
|
|
|
|
|
if (statusFiring != status)
|
|
|
|
|
{
|
|
|
|
|
statusFiring = status;
|
|
|
|
|
bodySprite->setCurrentFrame(0);
|
|
|
|
|
headSprite->setCurrentFrame(0);
|
|
|
|
|
// 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++)
|
|
|
|
|
// Crea cadenas de texto para componer el nombre de la animación
|
|
|
|
|
std::string aBodyCoffees = "";
|
|
|
|
|
std::string aHeadCoffees = "";
|
|
|
|
|
if (coffees > 0)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
aBodyCoffees = coffees == 1 ? "_1C" : "_2C";
|
|
|
|
|
aHeadCoffees = "_1C";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
const std::string aPowerUp = powerUp ? "_pwr" : "";
|
|
|
|
|
const std::string aWalking = statusWalking == PLAYER_STATUS_WALKING_STOP ? "stand" : "walk";
|
|
|
|
|
const std::string aFiring = statusFiring == PLAYER_STATUS_FIRING_UP ? "centershoot" : "sideshoot";
|
|
|
|
|
|
|
|
|
|
const SDL_RendererFlip flipWalk = statusWalking == PLAYER_STATUS_WALKING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
|
|
|
|
const SDL_RendererFlip flipFire = statusFiring == PLAYER_STATUS_FIRING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
|
|
|
|
|
|
|
|
|
// Establece la animación a partir de las cadenas
|
|
|
|
|
legsSprite->setCurrentAnimation(aWalking);
|
|
|
|
|
legsSprite->setFlip(flipWalk);
|
|
|
|
|
if (statusFiring == PLAYER_STATUS_FIRING_NO)
|
|
|
|
|
{ // No esta disparando
|
|
|
|
|
bodySprite->setCurrentAnimation(aWalking + aBodyCoffees);
|
|
|
|
|
bodySprite->setFlip(flipWalk);
|
|
|
|
|
headSprite->setCurrentAnimation(aWalking + aHeadCoffees);
|
|
|
|
|
headSprite->setFlip(flipWalk);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ // Está disparando
|
|
|
|
|
bodySprite->setCurrentAnimation(aFiring + aBodyCoffees);
|
|
|
|
|
bodySprite->setFlip(flipFire);
|
|
|
|
|
headSprite->setCurrentAnimation(aFiring + aHeadCoffees + aPowerUp);
|
|
|
|
|
headSprite->setFlip(flipFire);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (statusWalking)
|
|
|
|
|
{
|
|
|
|
|
case PLAYER_STATUS_WALKING_LEFT:
|
|
|
|
|
legsSprite->setCurrentAnimation(PLAYER_ANIMATION_LEGS_WALKING_LEFT);
|
|
|
|
|
// Actualiza las animaciones de los sprites
|
|
|
|
|
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
|
|
|
|
|
@@ -531,10 +279,14 @@ 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)
|
|
|
|
|
@@ -549,8 +301,10 @@ void Player::updateCooldown()
|
|
|
|
|
{
|
|
|
|
|
cooldown--;
|
|
|
|
|
if (powerUp)
|
|
|
|
|
{
|
|
|
|
|
cooldown--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
setFiringStatus(PLAYER_STATUS_FIRING_NO);
|
|
|
|
|
@@ -782,14 +536,14 @@ Uint8 Player::getCoffees()
|
|
|
|
|
// Obtiene el circulo de colisión
|
|
|
|
|
circle_t &Player::getCollider()
|
|
|
|
|
{
|
|
|
|
|
return mCollider;
|
|
|
|
|
return collider;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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));
|
|
|
|
|
collider.x = int(posX + (width / 2));
|
|
|
|
|
collider.y = int(posY + (height / 2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Obtiene el puntero a la textura con los gráficos de la animación de morir
|
|
|
|
|
@@ -809,20 +563,20 @@ void Player::updatePowerUpHeadOffset()
|
|
|
|
|
{
|
|
|
|
|
if (!powerUp)
|
|
|
|
|
{
|
|
|
|
|
powerUpHeadOffset = 0;
|
|
|
|
|
//powerUpHeadOffset = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
powerUpHeadOffset = 96;
|
|
|
|
|
//powerUpHeadOffset = 96;
|
|
|
|
|
if (powerUpCounter < 300)
|
|
|
|
|
{
|
|
|
|
|
if (powerUpCounter % 10 > 4)
|
|
|
|
|
{
|
|
|
|
|
powerUpHeadOffset = 96;
|
|
|
|
|
//powerUpHeadOffset = 96;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
powerUpHeadOffset = 0;
|
|
|
|
|
//powerUpHeadOffset = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|