Ya muere al caer de alto

This commit is contained in:
2022-09-15 17:01:56 +02:00
parent d53f2695a0
commit 8ad496b510
5 changed files with 33 additions and 0 deletions

View File

@@ -188,6 +188,7 @@ void Game::update()
checkPlayerOnBorder();
checkPlayerAndItems();
checkPlayerAndEnemies();
checkIfPlayerIsAlive();
scoreboard->update();
updateDebugInfo();
}
@@ -330,6 +331,15 @@ void Game::checkPlayerAndItems()
room->itemCollision(player->getCollider());
}
// Comprueba si el jugador esta vivo
void Game::checkIfPlayerIsAlive()
{
if (!player->isAlive())
{
killPlayer();
}
}
// Mata al jugador
void Game::killPlayer()
{

View File

@@ -77,6 +77,9 @@ private:
// Comprueba las colisiones del jugador con los objetos
void checkPlayerAndItems();
// Comprueba si el jugador esta vivo
void checkIfPlayerIsAlive();
// Mata al jugador
void killPlayer();

View File

@@ -21,6 +21,8 @@ Player::Player(player_t ini, std::string tileset, std::string animation, SDL_Ren
onBorder = false;
border = BORDER_TOP;
invincible = false;
alive = true;
maxFallHeight = BLOCK * 4;
jumpIni = ini.jumpIni;
state = ini.state;
@@ -229,6 +231,10 @@ void Player::checkState()
else if (state == s_standing)
{
if (prevState == s_falling && fallCounter > maxFallHeight)
{ // Si cae de muy alto, el jugador muere
alive = false;
}
vy = 0.0f;
jumpCounter = 0;
fallCounter = 0;
@@ -653,3 +659,9 @@ void Player::setState(state_e value)
prevState = state;
state = value;
}
// Comprueba si el jugador esta vivo
bool Player::isAlive()
{
return alive;
}

View File

@@ -66,6 +66,8 @@ public:
std::vector<JA_Sound> fallSound; // Vecor con todos los sonidos de la caída
int jumpCounter; // Cuenta el tiempo de salto
int fallCounter; // Cuenta el tiempo de caida
bool alive; // Indica si el jugador esta vivo o no
int maxFallHeight; // Altura maxima permitida de caída.
SDL_Rect r;
// Comprueba las entradas y modifica variables
@@ -158,6 +160,9 @@ public:
// Establece el valor de la variable
void setInvincible(bool value);
// Comprueba si el jugador esta vivo
bool isAlive();
};
#endif

View File

@@ -11,6 +11,9 @@ x (A) Modificar el salto para que coincida con el del JSW, no ha de colisionar l
(A) Crear tiles que arrastren, tipo cinta transportadora
(A) Tiles animados
(A) Tile que maten (o enemigos?)
(A) Cuando mueres, pantalla negra entre vida y vida
x (A) Morir al caer de alto
x (A) Crear ascensores (NO SE VA A HACER POR DISEÑO)
x (A) Crear rampas
x (A) Enemigos de diferente tamaño {cm:2022-08-30}