El juego ya empieza con el jugador que ha pulsado el botón

This commit is contained in:
2024-07-05 16:59:14 +02:00
parent a734c01dc5
commit dc09c189e9
6 changed files with 58 additions and 23 deletions

View File

@@ -19,6 +19,8 @@ Player::Player(float x, int y, SDL_Renderer *renderer, std::vector<Texture *> te
defaultPosX = posX = x;
defaultPosY = posY = y;
// Inicializa variables
enabled = false;
init();
}
@@ -135,7 +137,7 @@ void Player::move()
// Si el jugador abandona el area de juego por los laterales
if ((posX < PLAY_AREA_LEFT - 5) || (posX + width > PLAY_AREA_RIGHT + 5))
{
{
// Restaura su posición
posX -= velX;
}
@@ -159,7 +161,7 @@ void Player::move()
// Si el cadaver abandona el area de juego por los laterales
if ((deathSprite->getPosX() < PLAY_AREA_LEFT) || (deathSprite->getPosX() + width > PLAY_AREA_RIGHT))
{
{
// Restaura su posición
const float vx = deathSprite->getVelX();
deathSprite->setPosX(deathSprite->getPosX() - vx);
@@ -173,6 +175,11 @@ void Player::move()
// Pinta el jugador en pantalla
void Player::render()
{
if (!enabled)
{
return;
}
if (isAlive())
{
if (invulnerable)
@@ -248,7 +255,7 @@ void Player::setAnimation()
legsSprite->setCurrentAnimation(aWalking);
legsSprite->setFlip(flipWalk);
if (statusFiring == PLAYER_STATUS_FIRING_NO)
{
{
// No esta disparando
bodySprite->setCurrentAnimation(aWalking + aBodyCoffees + aPowerUp);
bodySprite->setFlip(flipWalk);
@@ -256,7 +263,7 @@ void Player::setAnimation()
headSprite->setFlip(flipWalk);
}
else
{
{
// Está disparando
bodySprite->setCurrentAnimation(aFiring + aBodyCoffees + aPowerUp);
bodySprite->setFlip(flipFire);
@@ -330,6 +337,11 @@ void Player::updateCooldown()
// Actualiza al jugador a su posicion, animación y controla los contadores
void Player::update()
{
if (!enabled)
{
return;
}
move();
setAnimation();
shiftColliders();
@@ -602,4 +614,16 @@ void Player::setPlayerTextures(std::vector<Texture *> texture)
legsSprite->setTexture(texture[2]);
deathSprite->setTexture(texture[3]);
fireSprite->setTexture(texture[4]);
}
// Activa o descativa el jugador
void Player::enable(bool value)
{
enabled = value;
}
// Obtiene el valor de la variable
bool Player::isEnabled()
{
return enabled;
}