Acomodats els estats del jugador

El compte enrrere per a continuar ara ix al acabar la animació de morir
Afegit el estat "entering_name"
This commit is contained in:
2024-09-29 10:40:35 +02:00
parent 945eaa68e7
commit 8ce09d1355
9 changed files with 193 additions and 68 deletions

View File

@@ -1,12 +1,12 @@
#include "player.h"
#include <SDL2/SDL_render.h> // for SDL_FLIP_HORIZONTAL, SDL_FLIP_NONE, SDL...
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <stdlib.h> // for rand
#include <algorithm> // for max, min
#include "animated_sprite.h" // for AnimatedSprite
#include "input.h" // for inputs_e
#include "param.h" // for param
#include "texture.h" // for Texture
#include <SDL2/SDL_render.h> // for SDL_FLIP_HORIZONTAL, SDL_FLIP_NONE, SDL...
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <stdlib.h> // for rand
#include <algorithm> // for max, min
#include "animated_sprite.h" // for AnimatedSprite
#include "input.h" // for inputs_e
#include "param.h" // for param
#include "texture.h" // for Texture
// Constructor
Player::Player(int id, float x, int y, SDL_Rect *playArea, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations)
@@ -58,7 +58,7 @@ void Player::init()
coffees = 0;
input = true;
continueTicks = 0;
continueCounter = 9;
continueCounter = 20;
width = 30;
height = 30;
collider.r = 9;
@@ -133,7 +133,7 @@ void Player::move()
powerSprite->setPosX(getPosX() - powerUpDespX);
}
else
else if (isDying())
{
playerSprite->update();
@@ -147,6 +147,12 @@ void Player::move()
// Rebota
playerSprite->setVelX(-vx);
}
// Si el cadaver abandona el area de juego por abajo
if (playerSprite->getPosY() > param.game.playArea.rect.h)
{
setStatusPlaying(PLAYER_STATUS_DIED);
}
}
}
@@ -327,6 +333,24 @@ bool Player::isWaiting()
return statusPlaying == PLAYER_STATUS_WAITING;
}
// Indica si el jugador está introduciendo su nombre
bool Player::isEnteringName()
{
return statusPlaying == PLAYER_STATUS_ENTERING_NAME;
}
// Indica si el jugador está muriendose
bool Player::isDying()
{
return statusPlaying == PLAYER_STATUS_DYING;
}
// Indica si el jugador ha terminado de morir
bool Player::hasDied()
{
return statusPlaying == PLAYER_STATUS_DIED;
}
// Establece el estado del jugador en el juego
void Player::setStatusPlaying(int value)
{
@@ -340,18 +364,25 @@ void Player::setStatusPlaying(int value)
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;
case PLAYER_STATUS_ENTERING_NAME:
break;
case PLAYER_STATUS_DYING:
// 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);
break;
case PLAYER_STATUS_DIED:
break;
default:
@@ -578,7 +609,6 @@ void Player::decContinueCounter()
{
continueTicks = SDL_GetTicks();
continueCounter--;
if (continueCounter < 0)
{
setStatusPlaying(PLAYER_STATUS_WAITING);