diff --git a/source/game.cpp b/source/game.cpp index f2df795..4aad1d1 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -16,7 +16,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, D this->debug = debug; // **** - this->debug->setEnabled(true); + //this->debug->setEnabled(true); currentRoom = "11.room"; spawnPoint = {2 * 8, 5 * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL}; @@ -111,6 +111,11 @@ void Game::checkEventHandler() board.music ? JA_ResumeMusic() : JA_PauseMusic(); break; + case SDL_SCANCODE_P: + player->pause(); + room->pause(); + break; + case SDL_SCANCODE_B: screen->switchBorder(); reLoadTextures(); @@ -345,13 +350,13 @@ void Game::checkIfPlayerIsAlive() } // Comprueba si ha terminado la partida - void Game::checkEndGame() +void Game::checkEndGame() +{ + if (board.lives < 0) { - if (board.lives < 0) - { - section.name = SECTION_PROG_TITLE; - } + section.name = SECTION_PROG_TITLE; } +} // Mata al jugador void Game::killPlayer() @@ -370,6 +375,8 @@ void Game::killPlayer() // Sonido JA_PlaySound(deathSound); + SDL_Delay(500); + // Crea la nueva habitación y el nuevo jugador room = new Room(asset->get(currentRoom), renderer, screen, asset, itemTracker, &board.items, debug); player = new Player(spawnPoint, asset->get("player.png"), asset->get("player.ani"), renderer, asset, input, room, debug); diff --git a/source/player.cpp b/source/player.cpp index 3b71e80..3a3af50 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -23,6 +23,7 @@ Player::Player(player_t ini, std::string tileset, std::string animation, SDL_Ren invincible = false; alive = true; maxFallHeight = BLOCK * 4; + paused = false; jumpIni = ini.jumpIni; state = ini.state; @@ -134,6 +135,11 @@ void Player::render() // Actualiza las variables del objeto void Player::update() { + if (paused) + { // Si está en modo pausa no se actualiza nada + return; + } + checkInput(); // Comprueba las entradas y modifica variables move(); // Recalcula la posición del jugador animate(); // Establece la animación del jugador @@ -669,4 +675,16 @@ void Player::setState(state_e value) bool Player::isAlive() { return alive; +} + +// Pone el jugador en modo pausa +void Player::pause() +{ + paused = true; +} + +// Quita el modo pausa del jugador +void Player::resume() +{ + paused = false; } \ No newline at end of file diff --git a/source/player.h b/source/player.h index 4644e8c..5ccd660 100644 --- a/source/player.h +++ b/source/player.h @@ -59,6 +59,7 @@ public: bool onBorder; // Indica si el jugador esta en uno de los cuatro bordes de la pantalla int border; // Indica en cual de los cuatro bordes se encuentra bool invincible; // Si es invencible, no puede morir + bool paused; // Indica si el jugador esta en modo pausa SDL_Rect lastPosition; // Contiene la ultima posición del jugador, por si hay que deshacer algun movimiento int jumpIni; // Valor del eje Y en el que se inicia el salto float maxVY; // Velocidad máxima que puede alcanzar al desplazarse en vertical @@ -163,6 +164,12 @@ public: // Comprueba si el jugador esta vivo bool isAlive(); + + // Pone el jugador en modo pausa + void pause(); + + // Quita el modo pausa del jugador + void resume(); }; #endif diff --git a/source/room.cpp b/source/room.cpp index 1eebbcd..9acd7df 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -11,6 +11,7 @@ Room::Room(std::string file_path, SDL_Renderer *renderer, Screen *screen, Asset mapWidth = 32; mapHeight = 16; tilesetWidth = 20; + paused = false; // Copia los punteros a objetos this->renderer = renderer; @@ -25,9 +26,9 @@ Room::Room(std::string file_path, SDL_Renderer *renderer, Screen *screen, Asset texture = new LTexture(renderer, asset->get(tileset)); itemSound = JA_LoadSound(asset->get("item.wav").c_str()); - //debug->clearLog(); - //debug->addToLog(tileset); - // Calcula las superficies + // debug->clearLog(); + // debug->addToLog(tileset); + // Calcula las superficies setBottomSurfaces(); setTopSurfaces(); setLeftSurfaces(); @@ -569,13 +570,18 @@ void Room::renderItems() // Actualiza las variables y objetos de la habitación void Room::update() { + if (paused) + {//Si está en modo pausa no se actualiza nada + return; + } + for (auto enemy : enemies) - { + {// Actualiza los enemigos enemy->update(); } for (auto item : items) - { + {// Actualiza los items item->update(); } } @@ -781,7 +787,7 @@ void Room::setBottomSurfaces() i++; } - //debug->addToLog("B: " + std::to_string(line.x1) + "," + std::to_string(line.y) + "," + std::to_string(line.x2) + "," + std::to_string(line.y)); + // debug->addToLog("B: " + std::to_string(line.x1) + "," + std::to_string(line.y) + "," + std::to_string(line.x2) + "," + std::to_string(line.y)); } } @@ -790,7 +796,7 @@ void Room::setTopSurfaces() { std::vector tile; - //debug->addToLog(std::to_string(tilemap.size())); + // debug->addToLog(std::to_string(tilemap.size())); // Busca todos los tiles de tipo muro o pasable que no tengan encima un muro // Hay que recorrer la habitación por filas (excepto los de la primera fila) @@ -832,7 +838,7 @@ void Room::setTopSurfaces() i++; } - //debug->addToLog("T: " + std::to_string(line.x1) + "," + std::to_string(line.y) + "," + std::to_string(line.x2) + "," + std::to_string(line.y)); + // debug->addToLog("T: " + std::to_string(line.x1) + "," + std::to_string(line.y) + "," + std::to_string(line.x2) + "," + std::to_string(line.y)); } } @@ -1122,4 +1128,16 @@ bool Room::checkRightSlopes(SDL_Point *p) } return false; +} + +// Pone el mapa en modo pausa +void Room::pause() +{ + paused = true; +} + +// Quita el modo pausa del mapa +void Room::resume() +{ + paused = false; } \ No newline at end of file diff --git a/source/room.h b/source/room.h index 6ab8130..fa03b66 100644 --- a/source/room.h +++ b/source/room.h @@ -63,6 +63,7 @@ private: JA_Sound itemSound; // Sonido producido al coger un objeto int *itemsPicked; // Puntero a la cantidad de items recogidos que lleva el juego Debug *debug; // Objeto para gestionar la información de debug + bool paused; // Indica si el mapa esta en modo pausa std::vector bottomSurfaces; // Lista con las superficies inferiores de la habitación std::vector topSurfaces; // Lista con las superficies superiores de la habitación std::vector leftSurfaces; // Lista con las superficies laterales de la parte izquierda de la habitación @@ -186,6 +187,12 @@ public: // Comprueba las colisiones bool checkRightSlopes(SDL_Point *p); + + // Pone el mapa en modo pausa + void pause(); + + // Quita el modo pausa del mapa + void resume(); }; #endif diff --git a/todo.txt b/todo.txt index 6b2b2c5..c49d108 100644 --- a/todo.txt +++ b/todo.txt @@ -40,6 +40,8 @@ x (A) La pantalla de titulo no tiene menu, solo un PRESS ENTER TO PLAY (A) Añadir color y efectos a los creditos (A) Arreglar la pantalal de carga para que cargue bit a bit (A) La musica del titulo ha de seguir sonando en los creditos y el ¿logo? +(A) Menu de pausa/salir +(A) Poner el mapa/jugador en pausa ## TEMAS