added power up on the player
This commit is contained in:
@@ -14,16 +14,16 @@ Player::~Player()
|
||||
{
|
||||
delete mSpriteLegs;
|
||||
mSpriteLegs = nullptr;
|
||||
|
||||
|
||||
delete mSpriteBody;
|
||||
mSpriteBody = nullptr;
|
||||
|
||||
|
||||
delete mSpriteHead;
|
||||
mSpriteHead = nullptr;
|
||||
}
|
||||
|
||||
// Iniciador
|
||||
void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody, SDL_Renderer *renderer)
|
||||
void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody, LTexture *textureHead, SDL_Renderer *renderer)
|
||||
{
|
||||
// Inicializa variables de estado
|
||||
mAlive = true;
|
||||
@@ -31,6 +31,8 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
|
||||
mStatusFiring = PLAYER_STATUS_FIRING_NO;
|
||||
mInvulnerable = false;
|
||||
mInvulnerableCounter = PLAYER_INVULNERABLE_COUNTER;
|
||||
mPowerUp = true;
|
||||
mPowerUpCounter = PLAYER_POWERUP_COUNTER;
|
||||
mExtraHit = false;
|
||||
mCoffees = 0;
|
||||
mInput = true;
|
||||
@@ -68,6 +70,7 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
|
||||
// Inicia el sprite
|
||||
mSpriteLegs->init(textureLegs, renderer);
|
||||
mSpriteBody->init(textureBody, renderer);
|
||||
mSpriteHead->init(textureHead, renderer);
|
||||
|
||||
// Establece el alto y ancho del sprite
|
||||
mSpriteLegs->setWidth(mWidth);
|
||||
@@ -76,6 +79,9 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
|
||||
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);
|
||||
@@ -83,6 +89,9 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
|
||||
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);
|
||||
@@ -90,6 +99,9 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
|
||||
mSpriteBody->setCurrentFrame(0);
|
||||
mSpriteBody->setAnimationCounter(0);
|
||||
|
||||
mSpriteHead->setCurrentFrame(0);
|
||||
mSpriteHead->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);
|
||||
@@ -102,6 +114,13 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
|
||||
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 4);
|
||||
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 4);
|
||||
|
||||
mSpriteHead->setAnimationNumFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 4);
|
||||
mSpriteHead->setAnimationNumFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 4);
|
||||
mSpriteHead->setAnimationNumFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 4);
|
||||
mSpriteHead->setAnimationNumFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 4);
|
||||
mSpriteHead->setAnimationNumFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, 4);
|
||||
mSpriteHead->setAnimationNumFrames(PLAYER_ANIMATION_HEAD_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);
|
||||
@@ -114,6 +133,13 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
|
||||
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);
|
||||
@@ -126,6 +152,13 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
|
||||
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);
|
||||
@@ -172,9 +205,40 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
|
||||
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
|
||||
@@ -232,6 +296,9 @@ void Player::move()
|
||||
|
||||
mSpriteBody->setPosX(getPosX());
|
||||
mSpriteBody->setPosY(mPosY);
|
||||
|
||||
mSpriteHead->setPosX(getPosX());
|
||||
mSpriteHead->setPosY(mPosY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,12 +313,14 @@ void Player::render()
|
||||
{
|
||||
mSpriteLegs->render();
|
||||
mSpriteBody->render();
|
||||
mSpriteHead->render();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mSpriteLegs->render();
|
||||
mSpriteBody->render();
|
||||
mSpriteHead->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -275,6 +344,7 @@ void Player::setFiringStatus(Uint8 status)
|
||||
{
|
||||
mStatusFiring = status;
|
||||
mSpriteBody->setCurrentFrame(0);
|
||||
mSpriteHead->setCurrentFrame(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,6 +362,17 @@ void Player::setAnimation()
|
||||
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) + (mPowerUp * 96), mHeight * (0 + (6 * mCoffees)), mWidth, mHeight);
|
||||
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, i, (mWidth * i) + (mPowerUp * 96), mHeight * (1 + (6 * mCoffees)), mWidth, mHeight);
|
||||
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, i, (mWidth * i) + (mPowerUp * 96), mHeight * (2 + (6 * mCoffees)), mWidth, mHeight);
|
||||
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, i, (mWidth * i) + (mPowerUp * 96), mHeight * (3 + (6 * mCoffees)), mWidth, mHeight);
|
||||
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, i, (mWidth * i) + (mPowerUp * 96), mHeight * (4 + (6 * mCoffees)), mWidth, mHeight);
|
||||
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, i, (mWidth * i) + (mPowerUp * 96), mHeight * (5 + (6 * mCoffees)), mWidth, mHeight);
|
||||
}
|
||||
|
||||
switch (mStatusWalking)
|
||||
{
|
||||
case PLAYER_STATUS_WALKING_LEFT:
|
||||
@@ -300,22 +381,27 @@ void Player::setAnimation()
|
||||
{
|
||||
case PLAYER_STATUS_FIRING_UP:
|
||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
|
||||
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_UP);
|
||||
break;
|
||||
|
||||
case PLAYER_STATUS_FIRING_LEFT:
|
||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
|
||||
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_LEFT);
|
||||
break;
|
||||
|
||||
case PLAYER_STATUS_FIRING_RIGHT:
|
||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
|
||||
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_RIGHT);
|
||||
break;
|
||||
|
||||
case PLAYER_STATUS_FIRING_NO:
|
||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_LEFT);
|
||||
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_WALKING_LEFT);
|
||||
break;
|
||||
|
||||
default:
|
||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
|
||||
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_WALKING_STOP);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -326,22 +412,27 @@ void Player::setAnimation()
|
||||
{
|
||||
case PLAYER_STATUS_FIRING_UP:
|
||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
|
||||
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_UP);
|
||||
break;
|
||||
|
||||
case PLAYER_STATUS_FIRING_LEFT:
|
||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
|
||||
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_LEFT);
|
||||
break;
|
||||
|
||||
case PLAYER_STATUS_FIRING_RIGHT:
|
||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
|
||||
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_RIGHT);
|
||||
break;
|
||||
|
||||
case PLAYER_STATUS_FIRING_NO:
|
||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_RIGHT);
|
||||
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_WALKING_RIGHT);
|
||||
break;
|
||||
|
||||
default:
|
||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
|
||||
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_WALKING_STOP);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -352,22 +443,27 @@ void Player::setAnimation()
|
||||
{
|
||||
case PLAYER_STATUS_FIRING_UP:
|
||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
|
||||
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_UP);
|
||||
break;
|
||||
|
||||
case PLAYER_STATUS_FIRING_LEFT:
|
||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
|
||||
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_LEFT);
|
||||
break;
|
||||
|
||||
case PLAYER_STATUS_FIRING_RIGHT:
|
||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
|
||||
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_RIGHT);
|
||||
break;
|
||||
|
||||
case PLAYER_STATUS_FIRING_NO:
|
||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
|
||||
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_WALKING_STOP);
|
||||
break;
|
||||
|
||||
default:
|
||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
|
||||
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_WALKING_STOP);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -427,7 +523,9 @@ void Player::updateCooldown()
|
||||
{
|
||||
if (mCooldown > 0)
|
||||
{
|
||||
--mCooldown;
|
||||
mCooldown--;
|
||||
if (mPowerUp)
|
||||
mCooldown--;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -442,6 +540,7 @@ void Player::update()
|
||||
setAnimation();
|
||||
shiftColliders();
|
||||
updateCooldown();
|
||||
updatePowerUpCounter();
|
||||
updateInvulnerableCounter();
|
||||
}
|
||||
|
||||
@@ -543,6 +642,44 @@ void Player::updateInvulnerableCounter()
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
--mPowerUpCounter;
|
||||
}
|
||||
else
|
||||
{
|
||||
mPowerUp = false;
|
||||
mPowerUpCounter = PLAYER_POWERUP_COUNTER;
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool Player::hasExtraHit()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user