From 8ad496b51080af90439a23a3b930311e252b441e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Thu, 15 Sep 2022 17:01:56 +0200 Subject: [PATCH] Ya muere al caer de alto --- source/game.cpp | 10 ++++++++++ source/game.h | 3 +++ source/player.cpp | 12 ++++++++++++ source/player.h | 5 +++++ todo.txt | 3 +++ 5 files changed, 33 insertions(+) diff --git a/source/game.cpp b/source/game.cpp index d88d8fe..5188e74 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -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() { diff --git a/source/game.h b/source/game.h index 5ff8519..e960090 100644 --- a/source/game.h +++ b/source/game.h @@ -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(); diff --git a/source/player.cpp b/source/player.cpp index 27791f0..23e0dde 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -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; @@ -652,4 +658,10 @@ void Player::setState(state_e value) { prevState = state; state = value; +} + +// Comprueba si el jugador esta vivo +bool Player::isAlive() +{ + return alive; } \ No newline at end of file diff --git a/source/player.h b/source/player.h index 0a3903b..29f5ea3 100644 --- a/source/player.h +++ b/source/player.h @@ -66,6 +66,8 @@ public: std::vector 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 diff --git a/todo.txt b/todo.txt index 61a3a1b..ef03395 100644 --- a/todo.txt +++ b/todo.txt @@ -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}