forked from jaildesigner-jailgames/jaildoctors_dilemma
Pantalla a negro al morir
This commit is contained in:
@@ -16,7 +16,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, D
|
|||||||
this->debug = debug;
|
this->debug = debug;
|
||||||
|
|
||||||
// ****
|
// ****
|
||||||
//this->debug->setEnabled(true);
|
// this->debug->setEnabled(true);
|
||||||
|
|
||||||
currentRoom = "11.room";
|
currentRoom = "11.room";
|
||||||
spawnPoint = {2 * 8, 5 * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
spawnPoint = {2 * 8, 5 * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
||||||
@@ -48,6 +48,9 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, D
|
|||||||
board.rooms = 1;
|
board.rooms = 1;
|
||||||
board.color = room->getBorderColor();
|
board.color = room->getBorderColor();
|
||||||
roomTracker->addRoom(currentRoom);
|
roomTracker->addRoom(currentRoom);
|
||||||
|
paused = false;
|
||||||
|
blackScreen = false;
|
||||||
|
blackScreenCounter = 0;
|
||||||
|
|
||||||
player->setInvincible(debug->getEnabled());
|
player->setInvincible(debug->getEnabled());
|
||||||
board.music = !debug->getEnabled();
|
board.music = !debug->getEnabled();
|
||||||
@@ -112,8 +115,20 @@ void Game::checkEventHandler()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_SCANCODE_P:
|
case SDL_SCANCODE_P:
|
||||||
player->pause();
|
if (paused)
|
||||||
room->pause();
|
{
|
||||||
|
player->resume();
|
||||||
|
room->resume();
|
||||||
|
scoreboard->resume();
|
||||||
|
paused = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
player->pause();
|
||||||
|
room->pause();
|
||||||
|
scoreboard->pause();
|
||||||
|
paused = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_SCANCODE_B:
|
case SDL_SCANCODE_B:
|
||||||
@@ -200,6 +215,7 @@ void Game::update()
|
|||||||
checkEndGame();
|
checkEndGame();
|
||||||
scoreboard->update();
|
scoreboard->update();
|
||||||
updateDebugInfo();
|
updateDebugInfo();
|
||||||
|
updateBlackScreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,6 +232,7 @@ void Game::render()
|
|||||||
player->render();
|
player->render();
|
||||||
renderRoomName();
|
renderRoomName();
|
||||||
scoreboard->render();
|
scoreboard->render();
|
||||||
|
renderBlackScreen();
|
||||||
|
|
||||||
// Debug info
|
// Debug info
|
||||||
renderDebugInfo();
|
renderDebugInfo();
|
||||||
@@ -375,11 +392,14 @@ void Game::killPlayer()
|
|||||||
// Sonido
|
// Sonido
|
||||||
JA_PlaySound(deathSound);
|
JA_PlaySound(deathSound);
|
||||||
|
|
||||||
SDL_Delay(500);
|
blackScreen = true;
|
||||||
|
|
||||||
// Crea la nueva habitación y el nuevo jugador
|
// Crea la nueva habitación y el nuevo jugador
|
||||||
room = new Room(asset->get(currentRoom), renderer, screen, asset, itemTracker, &board.items, debug);
|
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);
|
player = new Player(spawnPoint, asset->get("player.png"), asset->get("player.ani"), renderer, asset, input, room, debug);
|
||||||
|
|
||||||
|
room->pause();
|
||||||
|
player->pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recarga todas las texturas
|
// Recarga todas las texturas
|
||||||
@@ -389,4 +409,32 @@ void Game::reLoadTextures()
|
|||||||
room->reLoadTexture();
|
room->reLoadTexture();
|
||||||
scoreboard->reLoadTexture();
|
scoreboard->reLoadTexture();
|
||||||
text->reLoadTexture();
|
text->reLoadTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza las variables relativas a la pantalla en negro
|
||||||
|
void Game::updateBlackScreen()
|
||||||
|
{
|
||||||
|
if (blackScreen)
|
||||||
|
{
|
||||||
|
blackScreenCounter++;
|
||||||
|
if (blackScreenCounter > 50)
|
||||||
|
{
|
||||||
|
blackScreen = false;
|
||||||
|
blackScreenCounter = 0;
|
||||||
|
|
||||||
|
player->resume();
|
||||||
|
room->resume();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja la pantalla negra
|
||||||
|
void Game::renderBlackScreen()
|
||||||
|
{
|
||||||
|
if (blackScreen)
|
||||||
|
{
|
||||||
|
screen->clean();
|
||||||
|
screen->setBorderColor(stringToColor("black"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -45,6 +45,9 @@ private:
|
|||||||
player_t spawnPoint; // Lugar de la habitación donde aparece el jugador
|
player_t spawnPoint; // Lugar de la habitación donde aparece el jugador
|
||||||
JA_Sound deathSound; // Sonido a reproducir cuando muere el jugador
|
JA_Sound deathSound; // Sonido a reproducir cuando muere el jugador
|
||||||
board_t board; // Estructura con los datos del marcador
|
board_t board; // Estructura con los datos del marcador
|
||||||
|
bool paused; // Indica si el juego se encuentra en pausa
|
||||||
|
bool blackScreen; // Indica si la pantalla está en negro. Se utiliza para la muerte del jugador
|
||||||
|
int blackScreenCounter; // Contador para temporizar la pantalla en negro
|
||||||
Test *test;
|
Test *test;
|
||||||
|
|
||||||
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
||||||
@@ -89,6 +92,12 @@ private:
|
|||||||
// Recarga todas las texturas
|
// Recarga todas las texturas
|
||||||
void reLoadTextures();
|
void reLoadTextures();
|
||||||
|
|
||||||
|
// Actualiza las variables relativas a la pantalla en negro
|
||||||
|
void updateBlackScreen();
|
||||||
|
|
||||||
|
// Dibuja la pantalla negra
|
||||||
|
void renderBlackScreen();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Debug *debug);
|
Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Debug *debug);
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public:
|
|||||||
bool onBorder; // Indica si el jugador esta en uno de los cuatro bordes de la pantalla
|
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
|
int border; // Indica en cual de los cuatro bordes se encuentra
|
||||||
bool invincible; // Si es invencible, no puede morir
|
bool invincible; // Si es invencible, no puede morir
|
||||||
bool paused; // Indica si el jugador esta en modo pausa
|
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
|
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
|
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
|
float maxVY; // Velocidad máxima que puede alcanzar al desplazarse en vertical
|
||||||
|
|||||||
@@ -20,13 +20,16 @@ ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Asset *asset, board_t *board)
|
|||||||
// Inicializa las variables
|
// Inicializa las variables
|
||||||
counter = 0;
|
counter = 0;
|
||||||
colorChangeSpeed = 4;
|
colorChangeSpeed = 4;
|
||||||
|
paused = false;
|
||||||
|
timePaused = 0;
|
||||||
|
totalTimePaused = 0;
|
||||||
|
|
||||||
// Inicializa los colores
|
// Inicializa los colores
|
||||||
color_t c = stringToColor("blue");
|
color_t c = stringToColor("blue");
|
||||||
color.push_back(c);
|
color.push_back(c);
|
||||||
|
|
||||||
//c = stringToColor("red");
|
// c = stringToColor("red");
|
||||||
//color.push_back(c);
|
// color.push_back(c);
|
||||||
|
|
||||||
c = stringToColor("magenta");
|
c = stringToColor("magenta");
|
||||||
color.push_back(c);
|
color.push_back(c);
|
||||||
@@ -46,8 +49,8 @@ ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Asset *asset, board_t *board)
|
|||||||
c = stringToColor("bright_blue");
|
c = stringToColor("bright_blue");
|
||||||
color.push_back(c);
|
color.push_back(c);
|
||||||
|
|
||||||
//c = stringToColor("bright_red");
|
// c = stringToColor("bright_red");
|
||||||
//color.push_back(c);
|
// color.push_back(c);
|
||||||
|
|
||||||
c = stringToColor("bright_magenta");
|
c = stringToColor("bright_magenta");
|
||||||
color.push_back(c);
|
color.push_back(c);
|
||||||
@@ -117,7 +120,7 @@ void ScoreBoard::render()
|
|||||||
this->text->writeColored(17 * BLOCK, line1, itemsTxt, stringToColor("white"));
|
this->text->writeColored(17 * BLOCK, line1, itemsTxt, stringToColor("white"));
|
||||||
this->text->writeColored(20 * BLOCK, line1, " Time ", board->color);
|
this->text->writeColored(20 * BLOCK, line1, " Time ", board->color);
|
||||||
this->text->writeColored(26 * BLOCK, line1, timeTxt, stringToColor("white"));
|
this->text->writeColored(26 * BLOCK, line1, timeTxt, stringToColor("white"));
|
||||||
|
|
||||||
const std::string roomsTxt = std::to_string(board->rooms / 100) + std::to_string((board->rooms % 100) / 10) + std::to_string(board->rooms % 10);
|
const std::string roomsTxt = std::to_string(board->rooms / 100) + std::to_string((board->rooms % 100) / 10) + std::to_string(board->rooms % 10);
|
||||||
this->text->writeColored(22 * BLOCK, line2, "Rooms", stringToColor("white"));
|
this->text->writeColored(22 * BLOCK, line2, "Rooms", stringToColor("white"));
|
||||||
this->text->writeColored(28 * BLOCK, line2, roomsTxt, stringToColor("white"));
|
this->text->writeColored(28 * BLOCK, line2, roomsTxt, stringToColor("white"));
|
||||||
@@ -128,13 +131,17 @@ void ScoreBoard::update()
|
|||||||
{
|
{
|
||||||
counter++;
|
counter++;
|
||||||
sprite->update();
|
sprite->update();
|
||||||
clock = getTime();
|
|
||||||
|
if (!paused)
|
||||||
|
{// Si está en pausa no se actualiza el reloj
|
||||||
|
clock = getTime();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el tiempo transcurrido de partida
|
// Obtiene el tiempo transcurrido de partida
|
||||||
ScoreBoard::clock_t ScoreBoard::getTime()
|
ScoreBoard::clock_t ScoreBoard::getTime()
|
||||||
{
|
{
|
||||||
const Uint32 timeElapsed = SDL_GetTicks() - board->iniClock;
|
const Uint32 timeElapsed = SDL_GetTicks() - board->iniClock - totalTimePaused;
|
||||||
|
|
||||||
clock_t time;
|
clock_t time;
|
||||||
time.hours = timeElapsed / 3600000;
|
time.hours = timeElapsed / 3600000;
|
||||||
@@ -151,4 +158,18 @@ void ScoreBoard::reLoadTexture()
|
|||||||
playerTexture->reLoad();
|
playerTexture->reLoad();
|
||||||
itemTexture->reLoad();
|
itemTexture->reLoad();
|
||||||
text->reLoadTexture();
|
text->reLoadTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pone el marcador en modo pausa
|
||||||
|
void ScoreBoard::pause()
|
||||||
|
{
|
||||||
|
paused = true;
|
||||||
|
timePaused = SDL_GetTicks();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Quita el modo pausa del marcador
|
||||||
|
void ScoreBoard::resume()
|
||||||
|
{
|
||||||
|
paused = false;
|
||||||
|
totalTimePaused += SDL_GetTicks() - timePaused;
|
||||||
}
|
}
|
||||||
@@ -13,10 +13,10 @@
|
|||||||
|
|
||||||
struct board_t
|
struct board_t
|
||||||
{
|
{
|
||||||
int items; // Lleva la cuenta de los objetos recogidos
|
int items; // Lleva la cuenta de los objetos recogidos
|
||||||
int lives; // Lleva la cuenta de ls vidas restantes del jugador
|
int lives; // Lleva la cuenta de ls vidas restantes del jugador
|
||||||
int rooms; // Lleva la cuenta de las habitaciones visitadas
|
int rooms; // Lleva la cuenta de las habitaciones visitadas
|
||||||
bool music; // Indica si ha de sonar la musica durante el juego
|
bool music; // Indica si ha de sonar la musica durante el juego
|
||||||
color_t color; // Color para escribir el texto del marcador
|
color_t color; // Color para escribir el texto del marcador
|
||||||
Uint32 iniClock;
|
Uint32 iniClock;
|
||||||
};
|
};
|
||||||
@@ -41,6 +41,9 @@ private:
|
|||||||
std::vector<color_t> color; // Vector con los colores del objeto
|
std::vector<color_t> color; // Vector con los colores del objeto
|
||||||
int counter; // Contador interno
|
int counter; // Contador interno
|
||||||
int colorChangeSpeed; // Cuanto mas alto, mas tarda en cambiar de color
|
int colorChangeSpeed; // Cuanto mas alto, mas tarda en cambiar de color
|
||||||
|
bool paused; // Indica si el marcador esta en modo pausa
|
||||||
|
Uint32 timePaused; // Milisegundos que ha estado el marcador en pausa
|
||||||
|
Uint32 totalTimePaused; // Tiempo acumulado en pausa
|
||||||
clock_t clock; // Contiene las horas, minutos y segundos transcurridos desde el inicio de la partida
|
clock_t clock; // Contiene las horas, minutos y segundos transcurridos desde el inicio de la partida
|
||||||
LTexture *itemTexture; // Textura con los graficos para las vidas
|
LTexture *itemTexture; // Textura con los graficos para las vidas
|
||||||
board_t *board; // Contiene las variables a mostrar en el marcador
|
board_t *board; // Contiene las variables a mostrar en el marcador
|
||||||
@@ -63,6 +66,12 @@ public:
|
|||||||
|
|
||||||
// Recarga la textura
|
// Recarga la textura
|
||||||
void reLoadTexture();
|
void reLoadTexture();
|
||||||
|
|
||||||
|
// Pone el marcador en modo pausa
|
||||||
|
void pause();
|
||||||
|
|
||||||
|
// Quita el modo pausa del marcador
|
||||||
|
void resume();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user