added power up on the player
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
Bullet::Bullet()
|
||||
{
|
||||
mSprite = new Sprite();
|
||||
//init(0, 0, NO_KIND, nullptr, nullptr);
|
||||
mKind = NO_KIND;
|
||||
}
|
||||
|
||||
@@ -18,7 +17,7 @@ Bullet::~Bullet()
|
||||
}
|
||||
|
||||
// Iniciador
|
||||
void Bullet::init(int x, int y, int kind, LTexture *texture, SDL_Renderer *renderer)
|
||||
void Bullet::init(int x, int y, int kind, bool poweredUp, LTexture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
// Posición inicial del objeto
|
||||
mPosX = x;
|
||||
@@ -56,7 +55,10 @@ void Bullet::init(int x, int y, int kind, LTexture *texture, SDL_Renderer *rende
|
||||
mVelX = 0;
|
||||
|
||||
// Rectangulo con los gráficos del objeto
|
||||
mSprite->setSpriteClip(0 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||
if (!poweredUp)
|
||||
mSprite->setSpriteClip(0 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||
else
|
||||
mSprite->setSpriteClip((0 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||
break;
|
||||
|
||||
case BULLET_LEFT:
|
||||
@@ -64,7 +66,10 @@ void Bullet::init(int x, int y, int kind, LTexture *texture, SDL_Renderer *rende
|
||||
mVelX = -2;
|
||||
|
||||
// Rectangulo con los gráficos del objeto
|
||||
mSprite->setSpriteClip(1 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||
if (!poweredUp)
|
||||
mSprite->setSpriteClip(1 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||
else
|
||||
mSprite->setSpriteClip((1 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||
break;
|
||||
|
||||
case BULLET_RIGHT:
|
||||
@@ -72,7 +77,10 @@ void Bullet::init(int x, int y, int kind, LTexture *texture, SDL_Renderer *rende
|
||||
mVelX = 2;
|
||||
|
||||
// Rectangulo con los gráficos del objeto
|
||||
mSprite->setSpriteClip(2 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||
if (!poweredUp)
|
||||
mSprite->setSpriteClip(2 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||
else
|
||||
mSprite->setSpriteClip((2 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -149,7 +157,7 @@ void Bullet::testMove()
|
||||
// Deshabilita el objeto
|
||||
void Bullet::erase()
|
||||
{
|
||||
init(0, 0, 0, nullptr, nullptr);
|
||||
init(0, 0, 0, false, nullptr, nullptr);
|
||||
}
|
||||
|
||||
// Comprueba si el objeto está activo
|
||||
|
||||
@@ -16,7 +16,7 @@ public:
|
||||
~Bullet();
|
||||
|
||||
// Iniciador
|
||||
void init(int x, int y, int kind, LTexture* texture, SDL_Renderer *renderer);
|
||||
void init(int x, int y, int kind, bool poweredUp, LTexture* texture, SDL_Renderer *renderer);
|
||||
|
||||
// Pinta el objeto en pantalla
|
||||
void render();
|
||||
|
||||
@@ -134,8 +134,16 @@ const int SCREEN_THIRD_QUARTER_Y = (SCREEN_HEIGHT / 4) * 3;
|
||||
#define PLAYER_ANIMATION_BODY_WALKING_STOP 4
|
||||
#define PLAYER_ANIMATION_BODY_FIRING_UP 5
|
||||
|
||||
#define PLAYER_ANIMATION_HEAD_WALKING_LEFT 0
|
||||
#define PLAYER_ANIMATION_HEAD_FIRING_LEFT 1
|
||||
#define PLAYER_ANIMATION_HEAD_WALKING_RIGHT 2
|
||||
#define PLAYER_ANIMATION_HEAD_FIRING_RIGHT 3
|
||||
#define PLAYER_ANIMATION_HEAD_WALKING_STOP 4
|
||||
#define PLAYER_ANIMATION_HEAD_FIRING_UP 5
|
||||
|
||||
// Variables del jugador
|
||||
#define PLAYER_INVULNERABLE_COUNTER 200
|
||||
#define PLAYER_POWERUP_COUNTER 2500
|
||||
|
||||
// Secciones del programa
|
||||
#define PROG_SECTION_LOGO 0
|
||||
|
||||
@@ -214,6 +214,7 @@ void Director::setFileList()
|
||||
mFileList[38] = mExecutablePath + "/" + "../media/gfx/player_death.png";
|
||||
mFileList[39] = mExecutablePath + "/" + "../media/gfx/player_legs.png";
|
||||
mFileList[40] = mExecutablePath + "/" + "../media/gfx/title.png";
|
||||
mFileList[41] = mExecutablePath + "/" + "../media/gfx/player_head.png";
|
||||
}
|
||||
|
||||
// Comprueba que todos los ficheros existen
|
||||
|
||||
@@ -31,6 +31,7 @@ Game::Game(SDL_Renderer *renderer, std::string *filelist, std::string *textStrin
|
||||
mTextureGameBG = new LTexture();
|
||||
mTextureGameText = new LTexture();
|
||||
mTextureItems = new LTexture();
|
||||
mTexturePlayerHead = new LTexture();
|
||||
mTexturePlayerBody = new LTexture();
|
||||
mTexturePlayerDeath = new LTexture();
|
||||
mTexturePlayerLegs = new LTexture();
|
||||
@@ -123,6 +124,10 @@ Game::~Game()
|
||||
delete mTextureItems;
|
||||
mTextureItems = nullptr;
|
||||
|
||||
mTexturePlayerHead->unload();
|
||||
delete mTexturePlayerHead;
|
||||
mTexturePlayerHead = nullptr;
|
||||
|
||||
mTexturePlayerBody->unload();
|
||||
delete mTexturePlayerBody;
|
||||
mTexturePlayerBody = nullptr;
|
||||
@@ -352,7 +357,7 @@ void Game::init()
|
||||
mSpritePowerMeter->setSpriteClip(256, 192 - 8, 40, 8);
|
||||
|
||||
// Objeto jugador
|
||||
mPlayer->init(PLAY_AREA_CENTER_X - 11, PLAY_AREA_BOTTOM - 24, mTexturePlayerLegs, mTexturePlayerBody, mRenderer);
|
||||
mPlayer->init(PLAY_AREA_CENTER_X - 11, PLAY_AREA_BOTTOM - 24, mTexturePlayerLegs, mTexturePlayerBody, mTexturePlayerHead, mRenderer);
|
||||
|
||||
// Establece a cero todos los valores del vector de objetos globo
|
||||
resetBalloons();
|
||||
@@ -439,6 +444,7 @@ bool Game::loadMedia()
|
||||
success &= loadTextureFromFile(mTextureText, mFileList[30], mRenderer);
|
||||
success &= loadTextureFromFile(mTextureText2, mFileList[29], mRenderer);
|
||||
success &= loadTextureFromFile(mTexturePlayerLegs, mFileList[39], mRenderer);
|
||||
success &= loadTextureFromFile(mTexturePlayerHead, mFileList[41], mRenderer);
|
||||
success &= loadTextureFromFile(mTexturePlayerBody, mFileList[37], mRenderer);
|
||||
success &= loadTextureFromFile(mTexturePlayerDeath, mFileList[38], mRenderer);
|
||||
success &= loadTextureFromFile(mTextureBalloon, mFileList[24], mRenderer);
|
||||
@@ -2085,9 +2091,9 @@ void Game::resetBullets()
|
||||
}
|
||||
|
||||
// Crea un objeto bala
|
||||
void Game::createBullet(int x, int y, Uint8 kind)
|
||||
void Game::createBullet(int x, int y, Uint8 kind, bool poweredUp)
|
||||
{
|
||||
mBullet[getBulletFreeIndex()]->init(x, y, kind, mTextureBullet, mRenderer);
|
||||
mBullet[getBulletFreeIndex()]->init(x, y, kind, poweredUp, mTextureBullet, mRenderer);
|
||||
}
|
||||
|
||||
// Actualiza los items
|
||||
@@ -2582,7 +2588,7 @@ void Game::checkGameInput()
|
||||
if (mPlayer->canFire())
|
||||
{
|
||||
mPlayer->setInput(INPUT_FIRE_UP);
|
||||
createBullet(mPlayer->getPosX() + (mPlayer->getWidth() / 2) - 4, mPlayer->getPosY() + (mPlayer->getHeight() / 2), BULLET_UP);
|
||||
createBullet(mPlayer->getPosX() + (mPlayer->getWidth() / 2) - 4, mPlayer->getPosY() + (mPlayer->getHeight() / 2), BULLET_UP, mPlayer->isPowerUp());
|
||||
mPlayer->setFireCooldown(10);
|
||||
}
|
||||
|
||||
@@ -2590,7 +2596,7 @@ void Game::checkGameInput()
|
||||
if (mPlayer->canFire())
|
||||
{
|
||||
mPlayer->setInput(INPUT_FIRE_LEFT);
|
||||
createBullet(mPlayer->getPosX() + (mPlayer->getWidth() / 2) - 4, mPlayer->getPosY() + (mPlayer->getHeight() / 2), BULLET_UP);
|
||||
createBullet(mPlayer->getPosX() + (mPlayer->getWidth() / 2) - 4, mPlayer->getPosY() + (mPlayer->getHeight() / 2), BULLET_UP, mPlayer->isPowerUp());
|
||||
mPlayer->setFireCooldown(10);
|
||||
}
|
||||
|
||||
@@ -2598,7 +2604,7 @@ void Game::checkGameInput()
|
||||
if (mPlayer->canFire())
|
||||
{
|
||||
mPlayer->setInput(INPUT_FIRE_RIGHT);
|
||||
createBullet(mPlayer->getPosX() + (mPlayer->getWidth() / 2) - 4, mPlayer->getPosY() + (mPlayer->getHeight() / 2), BULLET_UP);
|
||||
createBullet(mPlayer->getPosX() + (mPlayer->getWidth() / 2) - 4, mPlayer->getPosY() + (mPlayer->getHeight() / 2), BULLET_UP, mPlayer->isPowerUp());
|
||||
mPlayer->setFireCooldown(10);
|
||||
}
|
||||
|
||||
@@ -2642,7 +2648,7 @@ void Game::checkGameInput()
|
||||
if (mPlayer->canFire())
|
||||
{
|
||||
mPlayer->setInput(INPUT_FIRE_UP);
|
||||
createBullet(mPlayer->getPosX() + (mPlayer->getWidth() / 2) - 4, mPlayer->getPosY() + (mPlayer->getHeight() / 2), BULLET_UP);
|
||||
createBullet(mPlayer->getPosX() + (mPlayer->getWidth() / 2) - 4, mPlayer->getPosY() + (mPlayer->getHeight() / 2), BULLET_UP, mPlayer->isPowerUp());
|
||||
mPlayer->setFireCooldown(10);
|
||||
|
||||
// Reproduce el sonido de disparo
|
||||
@@ -2652,13 +2658,13 @@ void Game::checkGameInput()
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba el input de desiparar a la izquierda
|
||||
// Comprueba el input de disparar a la izquierda
|
||||
if (mInput->checkInput(INPUT_BUTTON_1, REPEAT_TRUE))
|
||||
{
|
||||
if (mPlayer->canFire())
|
||||
{
|
||||
mPlayer->setInput(INPUT_FIRE_LEFT);
|
||||
createBullet(mPlayer->getPosX() + (mPlayer->getWidth() / 2) - 4, mPlayer->getPosY() + (mPlayer->getHeight() / 2), BULLET_LEFT);
|
||||
createBullet(mPlayer->getPosX() + (mPlayer->getWidth() / 2) - 4, mPlayer->getPosY() + (mPlayer->getHeight() / 2), BULLET_LEFT, mPlayer->isPowerUp());
|
||||
mPlayer->setFireCooldown(10);
|
||||
|
||||
// Reproduce el sonido de disparo
|
||||
@@ -2674,7 +2680,7 @@ void Game::checkGameInput()
|
||||
if (mPlayer->canFire())
|
||||
{
|
||||
mPlayer->setInput(INPUT_FIRE_RIGHT);
|
||||
createBullet(mPlayer->getPosX() + (mPlayer->getWidth() / 2) - 4, mPlayer->getPosY() + (mPlayer->getHeight() / 2), BULLET_RIGHT);
|
||||
createBullet(mPlayer->getPosX() + (mPlayer->getWidth() / 2) - 4, mPlayer->getPosY() + (mPlayer->getHeight() / 2), BULLET_RIGHT, mPlayer->isPowerUp());
|
||||
mPlayer->setFireCooldown(10);
|
||||
|
||||
// Reproduce el sonido de disparo
|
||||
|
||||
@@ -82,6 +82,7 @@ private:
|
||||
LTexture *mTextureGameBG; // Textura para el fondo del juego
|
||||
LTexture *mTextureGameText; // Textura para los sprites con textos
|
||||
LTexture *mTextureItems; // Textura para los items
|
||||
LTexture *mTexturePlayerHead; // Textura para la cabeza del jugador
|
||||
LTexture *mTexturePlayerBody; // Textura para el cuerpo del jugador
|
||||
LTexture *mTexturePlayerDeath; // Textura para la animación de muerte del jugador
|
||||
LTexture *mTexturePlayerLegs; // Textura para las piernas del jugador
|
||||
@@ -325,7 +326,7 @@ public:
|
||||
void resetBullets();
|
||||
|
||||
// Crea un objeto bala
|
||||
void createBullet(int x, int y, Uint8 kind);
|
||||
void createBullet(int x, int y, Uint8 kind, bool poweredUp);
|
||||
|
||||
// Actualiza los items
|
||||
void updateItems();
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
/*
|
||||
This source code copyrighted by JailDesigner (2020)
|
||||
started on Castalla 15-07-2020.
|
||||
*/
|
||||
Código fuente creado por JailDesigner (2020)
|
||||
Empezado en Castalla el 15/07/2020.
|
||||
|
||||
/*
|
||||
Descripción del enfoque utilizado para crear el juego.
|
||||
|
||||
El programa contine una serie de clases/objetos básicos: la clase sprite
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -33,6 +33,8 @@ private:
|
||||
Uint16 mInvulnerableCounter; // Temporizador para la invulnerabilidad
|
||||
bool mExtraHit; // Indica si el jugador tiene un toque extra
|
||||
Uint8 mCoffees; // Indica cuantos cafes lleva acumulados
|
||||
bool mPowerUp; // Indica si el jugador tiene activo el modo PowerUp
|
||||
Uint16 mPowerUpCounter; // Temporizador para el modo PowerUp
|
||||
bool mInput; // Indica si puede recibir ordenes de entrada
|
||||
|
||||
AnimatedSprite *mSpriteLegs; // Sprite para dibujar las piernas
|
||||
@@ -50,7 +52,7 @@ public:
|
||||
~Player();
|
||||
|
||||
// Iniciador
|
||||
void init(float x, int y, LTexture *textureLegs, LTexture *textureBody, SDL_Renderer *renderer);
|
||||
void init(float x, int y, LTexture *textureLegs, LTexture *textureBody, LTexture *textureHead, SDL_Renderer *renderer);
|
||||
|
||||
// Actua en consecuencia de la entrada recibida
|
||||
void setInput(Uint8 input);
|
||||
@@ -134,6 +136,21 @@ public:
|
||||
// Actualiza el valor de la variable
|
||||
void updateInvulnerableCounter();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool isPowerUp();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPowerUp(bool value);
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
Uint16 getPowerUpCounter();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPowerUpCounter(Uint16 value);
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void updatePowerUpCounter();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool hasExtraHit();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user