Trabajando en el modo pausa

This commit is contained in:
2022-09-15 19:10:51 +02:00
parent 3b3b807c5a
commit 9ea184946d
6 changed files with 73 additions and 14 deletions

View File

@@ -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)
{
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);

View File

@@ -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
@@ -670,3 +676,15 @@ 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;
}

View File

@@ -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

View File

@@ -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,8 +26,8 @@ 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);
// debug->clearLog();
// debug->addToLog(tileset);
// Calcula las superficies
setBottomSurfaces();
setTopSurfaces();
@@ -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<int> 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));
}
}
@@ -1123,3 +1129,15 @@ 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;
}

View File

@@ -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<h_line_t> bottomSurfaces; // Lista con las superficies inferiores de la habitación
std::vector<h_line_t> topSurfaces; // Lista con las superficies superiores de la habitación
std::vector<v_line_t> 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

View File

@@ -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