forked from jaildesigner-jailgames/jaildoctors_dilemma
Trabajando en la pantalla de game over
This commit is contained in:
@@ -9,7 +9,7 @@ Director::Director(int argc, char *argv[])
|
|||||||
section.name = SECTION_PROG_LOGO;
|
section.name = SECTION_PROG_LOGO;
|
||||||
section.subsection = SUBSECTION_LOGO_TO_INTRO;
|
section.subsection = SUBSECTION_LOGO_TO_INTRO;
|
||||||
|
|
||||||
//section.name = SECTION_PROG_GAME;
|
section.name = SECTION_PROG_GAME;
|
||||||
|
|
||||||
// Crea e inicializa las opciones del programa
|
// Crea e inicializa las opciones del programa
|
||||||
iniOptions();
|
iniOptions();
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
|||||||
// Inicializa el resto de variables
|
// Inicializa el resto de variables
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
ticksSpeed = 15;
|
ticksSpeed = 15;
|
||||||
board.lives = 9;
|
board.lives = 0;
|
||||||
board.items = 0;
|
board.items = 0;
|
||||||
board.rooms = 1;
|
board.rooms = 1;
|
||||||
board.music = true;
|
board.music = true;
|
||||||
@@ -370,7 +370,7 @@ void Game::checkIfPlayerIsAlive()
|
|||||||
// Comprueba si ha terminado la partida
|
// Comprueba si ha terminado la partida
|
||||||
void Game::checkGameOver()
|
void Game::checkGameOver()
|
||||||
{
|
{
|
||||||
if (board.lives < 0)
|
if (board.lives < 0 && blackScreenCounter > 17)
|
||||||
{
|
{
|
||||||
section.name = SECTION_PROG_GAME_OVER;
|
section.name = SECTION_PROG_GAME_OVER;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, A
|
|||||||
|
|
||||||
// Reserva memoria para los punteros a objetos
|
// Reserva memoria para los punteros a objetos
|
||||||
eventHandler = new SDL_Event();
|
eventHandler = new SDL_Event();
|
||||||
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
|
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
counter = 0;
|
counter = 0;
|
||||||
@@ -20,6 +20,17 @@ GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, A
|
|||||||
section.subsection = 0;
|
section.subsection = 0;
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
ticksSpeed = 15;
|
ticksSpeed = 15;
|
||||||
|
endSection = 300;
|
||||||
|
iniFade = 210;
|
||||||
|
fadeLenght = 30;
|
||||||
|
|
||||||
|
// Inicializa el vector de colores
|
||||||
|
const std::vector<std::string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
|
||||||
|
for (auto cl : colorList)
|
||||||
|
{
|
||||||
|
colors.push_back(stringToColor(options->palette, cl));
|
||||||
|
}
|
||||||
|
color = colors.at(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -42,9 +53,12 @@ void GameOver::update()
|
|||||||
// Comprueba el manejador de eventos
|
// Comprueba el manejador de eventos
|
||||||
checkEventHandler();
|
checkEventHandler();
|
||||||
|
|
||||||
|
// Actualiza el color usado para renderizar los textos e imagenes
|
||||||
|
updateColor();
|
||||||
|
|
||||||
counter++;
|
counter++;
|
||||||
|
|
||||||
if (counter == 400)
|
if (counter == endSection)
|
||||||
{
|
{
|
||||||
section.name = SECTION_PROG_TITLE;
|
section.name = SECTION_PROG_TITLE;
|
||||||
}
|
}
|
||||||
@@ -60,7 +74,10 @@ void GameOver::render()
|
|||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
screen->clean();
|
screen->clean();
|
||||||
|
|
||||||
text->writeCentered(GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y, "G A M E O V E R");
|
// Escribe el texto de GAME OVER
|
||||||
|
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y, "G A M E O V E R", 1, color);
|
||||||
|
|
||||||
|
text->write(0, 0, std::to_string(counter));
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->blit();
|
screen->blit();
|
||||||
@@ -124,8 +141,8 @@ void GameOver::checkEventHandler()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
//section.name = SECTION_PROG_TITLE;
|
// section.name = SECTION_PROG_TITLE;
|
||||||
//section.subsection = 0;
|
// section.subsection = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,3 +160,11 @@ section_t GameOver::run()
|
|||||||
|
|
||||||
return section;
|
return section;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actualiza el color usado para renderizar los textos e imagenes
|
||||||
|
void GameOver::updateColor()
|
||||||
|
{
|
||||||
|
const float step = std::min(std::max(counter, iniFade) - iniFade, fadeLenght) / (float)fadeLenght;
|
||||||
|
const int index = (colors.size() - 1) * step;
|
||||||
|
color = colors.at(index);
|
||||||
|
}
|
||||||
@@ -19,19 +19,24 @@ class GameOver
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||||
Resource *resource; // Objeto con los recursos
|
Resource *resource; // Objeto con los recursos
|
||||||
Asset *asset; // Objeto con los ficheros de recursos
|
Asset *asset; // Objeto con los ficheros de recursos
|
||||||
options_t *options; // Puntero a las opciones del juego
|
options_t *options; // Puntero a las opciones del juego
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
SDL_Event *eventHandler; // Manejador de eventos
|
||||||
Text *text; // Objeto para escribir texto en pantalla
|
Text *text; // Objeto para escribir texto en pantalla
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int counter; // Contador
|
int counter; // Contador
|
||||||
section_t section; // Estado del bucle principal para saber si continua o se sale
|
section_t section; // Estado del bucle principal para saber si continua o se sale
|
||||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||||
|
std::vector<color_t> colors; // Vector con los colores para el fade
|
||||||
|
color_t color; // Color usado para el texto y los sprites
|
||||||
|
int endSection; // Contador: cuando acaba la sección
|
||||||
|
int iniFade; // Contador: cuando emiepza el fade
|
||||||
|
int fadeLenght; // Contador: duración del fade
|
||||||
|
|
||||||
// Actualiza el objeto
|
// Actualiza el objeto
|
||||||
void update();
|
void update();
|
||||||
@@ -42,6 +47,9 @@ private:
|
|||||||
// Comprueba el manejador de eventos
|
// Comprueba el manejador de eventos
|
||||||
void checkEventHandler();
|
void checkEventHandler();
|
||||||
|
|
||||||
|
// Actualiza el color usado para renderizar los textos e imagenes
|
||||||
|
void updateColor();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options);
|
GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options);
|
||||||
|
|||||||
Reference in New Issue
Block a user