enmig del berenjenal d'afegir estats nous al jugador
This commit is contained in:
@@ -18,7 +18,8 @@ Player::Player(float x, int y, std::vector<Texture *> texture, std::vector<std::
|
||||
powerSprite->setPosY(y - (powerSprite->getHeight() - playerSprite->getHeight()));
|
||||
|
||||
// Inicializa variables
|
||||
enabled = false;
|
||||
// enabled = false;
|
||||
statusPlaying = PLAYER_STATUS_WAITING;
|
||||
init();
|
||||
}
|
||||
|
||||
@@ -35,7 +36,7 @@ void Player::init()
|
||||
// Inicializa variables de estado
|
||||
posX = defaultPosX;
|
||||
posY = defaultPosY;
|
||||
alive = enabled;
|
||||
statusPlaying = PLAYER_STATUS_PLAYING;
|
||||
statusWalking = PLAYER_STATUS_WALKING_STOP;
|
||||
statusFiring = PLAYER_STATUS_FIRING_NO;
|
||||
invulnerable = true;
|
||||
@@ -45,31 +46,17 @@ void Player::init()
|
||||
extraHit = false;
|
||||
coffees = 0;
|
||||
input = true;
|
||||
|
||||
// Establece la altura y el ancho del jugador
|
||||
continueTicks = 0;
|
||||
continueCounter = 9;
|
||||
width = 30;
|
||||
height = 30;
|
||||
|
||||
// Establece el tamaño del circulo de colisión
|
||||
collider.r = 9;
|
||||
|
||||
// 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 la posición del sprite
|
||||
@@ -117,7 +104,7 @@ void Player::setInput(int input)
|
||||
// Mueve el jugador a la posición y animación que le corresponde
|
||||
void Player::move()
|
||||
{
|
||||
if (isAlive())
|
||||
if (isPlaying())
|
||||
{
|
||||
// Mueve el jugador a derecha o izquierda
|
||||
posX += velX;
|
||||
@@ -155,7 +142,7 @@ void Player::move()
|
||||
// Pinta el jugador en pantalla
|
||||
void Player::render()
|
||||
{
|
||||
if (powerUp && alive)
|
||||
if (powerUp && isPlaying())
|
||||
{
|
||||
if (powerUpCounter > (PLAYER_POWERUP_COUNTER / 4) || powerUpCounter % 20 > 4)
|
||||
{
|
||||
@@ -197,7 +184,7 @@ void Player::setAnimation()
|
||||
const SDL_RendererFlip flipFire = statusFiring == PLAYER_STATUS_FIRING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
|
||||
// Establece la animación a partir de las cadenas
|
||||
if (alive)
|
||||
if (isPlaying())
|
||||
{
|
||||
if (statusFiring == PLAYER_STATUS_FIRING_NO)
|
||||
{ // No esta disparando
|
||||
@@ -285,6 +272,7 @@ void Player::update()
|
||||
updateCooldown();
|
||||
updatePowerUpCounter();
|
||||
updateInvulnerable();
|
||||
updateContinueCounter();
|
||||
}
|
||||
|
||||
// Obtiene la puntuación del jugador
|
||||
@@ -302,29 +290,58 @@ void Player::setScore(Uint32 score)
|
||||
// Incrementa la puntuación del jugador
|
||||
void Player::addScore(Uint32 score)
|
||||
{
|
||||
//if (enabled && alive)
|
||||
if (alive)
|
||||
if (isPlaying())
|
||||
{
|
||||
this->score += score;
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool Player::isAlive()
|
||||
// Indica si el jugador está jugando
|
||||
bool Player::isPlaying()
|
||||
{
|
||||
return alive;
|
||||
return statusPlaying == PLAYER_STATUS_PLAYING;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setAlive(bool value)
|
||||
// Indica si el jugador está continuando
|
||||
bool Player::isContinue()
|
||||
{
|
||||
alive = value;
|
||||
return statusPlaying == PLAYER_STATUS_CONTINUE;
|
||||
}
|
||||
|
||||
if (!alive)
|
||||
// Indica si el jugador está esperando
|
||||
bool Player::isWaiting()
|
||||
{
|
||||
return statusPlaying == PLAYER_STATUS_WAITING;
|
||||
}
|
||||
|
||||
// Establece el estado del jugador en el juego
|
||||
void Player::setStatusPlaying(int value)
|
||||
{
|
||||
statusPlaying = value;
|
||||
|
||||
switch (statusPlaying)
|
||||
{
|
||||
case PLAYER_STATUS_PLAYING:
|
||||
init();
|
||||
break;
|
||||
|
||||
case PLAYER_STATUS_CONTINUE:
|
||||
// Activa la animación de morir
|
||||
playerSprite->setAccelY(0.2f);
|
||||
playerSprite->setVelY(-6.6f);
|
||||
rand() % 2 == 0 ? playerSprite->setVelX(3.3f) : playerSprite->setVelX(-3.3f);
|
||||
|
||||
// Inicializa el contador de continuar
|
||||
continueTicks = SDL_GetTicks();
|
||||
continueCounter = 9;
|
||||
break;
|
||||
|
||||
case PLAYER_STATUS_WAITING:
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -510,15 +527,26 @@ void Player::setPlayerTextures(std::vector<Texture *> texture)
|
||||
powerSprite->setTexture(texture[1]);
|
||||
}
|
||||
|
||||
// Activa o descativa el jugador
|
||||
void Player::enable(bool value)
|
||||
// Obtiene el valor de la variable
|
||||
int Player::getContinueCounter()
|
||||
{
|
||||
enabled = value;
|
||||
init();
|
||||
return continueCounter;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool Player::isEnabled()
|
||||
// Actualiza el contador de continue
|
||||
void Player::updateContinueCounter()
|
||||
{
|
||||
return enabled;
|
||||
if (statusPlaying == PLAYER_STATUS_CONTINUE)
|
||||
{
|
||||
const Uint32 ticksSpeed = 1000;
|
||||
|
||||
if (SDL_GetTicks() - continueTicks > ticksSpeed)
|
||||
{
|
||||
// Actualiza el contador de ticks
|
||||
continueTicks = SDL_GetTicks();
|
||||
|
||||
// Decrementa el contador
|
||||
continueCounter--;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user