Añadido el esqueleto para dos secciones nuevas: ending y game_over

This commit is contained in:
2022-11-02 22:50:25 +01:00
parent bb992b7d90
commit a510742984
7 changed files with 443 additions and 1 deletions

View File

@@ -54,7 +54,9 @@ const int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
#define SECTION_PROG_CREDITS 3 #define SECTION_PROG_CREDITS 3
#define SECTION_PROG_GAME 4 #define SECTION_PROG_GAME 4
#define SECTION_PROG_DEMO 5 #define SECTION_PROG_DEMO 5
#define SECTION_PROG_QUIT 6 #define SECTION_PROG_GAME_OVER 6
#define SECTION_PROG_ENDING 7
#define SECTION_PROG_QUIT 8
// Subsecciones // Subsecciones
#define SUBSECTION_LOGO_TO_INTRO 0 #define SUBSECTION_LOGO_TO_INTRO 0

View File

@@ -298,6 +298,24 @@ void Director::loadResources(section_t section)
resource->loadOffsets(offsetsList); resource->loadOffsets(offsetsList);
} }
else if (section.name == SECTION_PROG_ENDING)
{
std::vector<std::string> textureList;
textureList.push_back("jailgames.png");
textureList.push_back("since_1998.png");
resource->loadTextures(textureList);
}
else if (section.name == SECTION_PROG_GAME_OVER)
{
std::vector<std::string> textureList;
textureList.push_back("jailgames.png");
textureList.push_back("since_1998.png");
resource->loadTextures(textureList);
}
else if (section.name == SECTION_PROG_GAME || section.name == SECTION_PROG_DEMO) else if (section.name == SECTION_PROG_GAME || section.name == SECTION_PROG_DEMO)
{ {
// Texturas // Texturas
@@ -1166,6 +1184,34 @@ void Director::runDemo()
resource->free(); resource->free();
} }
// Ejecuta la seccion del final del juego
void Director::runEnding()
{
if (options->console)
{
std::cout << "\n* SECTION: ENDING" << std::endl;
}
loadResources(section);
ending = new Ending(renderer, screen, resource, asset, options);
setSection(ending->run());
delete ending;
resource->free();
}
// Ejecuta la seccion del final de la partida
void Director::runGameOver()
{
if (options->console)
{
std::cout << "\n* SECTION: GAME OVER" << std::endl;
}
loadResources(section);
gameOver = new GameOver(renderer, screen, resource, asset, options);
setSection(gameOver->run());
delete gameOver;
resource->free();
}
// Ejecuta la seccion de juego donde se juega // Ejecuta la seccion de juego donde se juega
void Director::runGame() void Director::runGame()
{ {

View File

@@ -16,6 +16,8 @@
#include "intro.h" #include "intro.h"
#include "logo.h" #include "logo.h"
#include "title.h" #include "title.h"
#include "game_over.h"
#include "ending.h"
#ifndef DIRECTOR_H #ifndef DIRECTOR_H
#define DIRECTOR_H #define DIRECTOR_H
@@ -36,6 +38,8 @@ private:
Intro *intro; // Objeto para gestionar la introducción del juego Intro *intro; // Objeto para gestionar la introducción del juego
Credits *credits; // Objeto para gestionar los creditos del juego Credits *credits; // Objeto para gestionar los creditos del juego
Demo *demo; // Objeto para gestionar el modo demo, en el que se ven pantallas del juego Demo *demo; // Objeto para gestionar el modo demo, en el que se ven pantallas del juego
Ending *ending; // Objeto para gestionar el final del juego
GameOver *gameOver; // Objeto para gestionar el final de la partida
Debug *debug; // Objeto para getsionar la información de debug Debug *debug; // Objeto para getsionar la información de debug
struct options_t *options; // Variable con todas las opciones del programa struct options_t *options; // Variable con todas las opciones del programa
@@ -98,6 +102,12 @@ private:
// Ejecuta la seccion de la demo, donde se ven pantallas del juego // Ejecuta la seccion de la demo, donde se ven pantallas del juego
void runDemo(); void runDemo();
// Ejecuta la seccion del final del juego
void runEnding();
// Ejecuta la seccion del final de la partida
void runGameOver();
// Ejecuta la seccion de juego donde se juega // Ejecuta la seccion de juego donde se juega
void runGame(); void runGame();

133
source/ending.cpp Normal file
View File

@@ -0,0 +1,133 @@
#include "ending.h"
// Constructor
Ending::Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options)
{
// Copia los punteros
this->renderer = renderer;
this->screen = screen;
this->resource = resource;
this->asset = asset;
this->options = options;
// Reserva memoria para los punteros a objetos
eventHandler = new SDL_Event();
// Inicializa variables
counter = 0;
section.name = SECTION_PROG_ENDING;
section.subsection = 0;
ticks = 0;
ticksSpeed = 15;
}
// Destructor
Ending::~Ending()
{
// Libera la memoria de los objetos
delete eventHandler;
}
// Actualiza el objeto
void Ending::update()
{
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
if (SDL_GetTicks() - ticks > ticksSpeed)
{
// Actualiza el contador de ticks
ticks = SDL_GetTicks();
// Comprueba el manejador de eventos
checkEventHandler();
}
}
// Dibuja el final en pantalla
void Ending::render()
{
// Prepara para empezar a dibujar en la textura de juego
screen->start();
// Limpia la pantalla
screen->clean();
// Vuelca el contenido del renderizador en pantalla
screen->blit();
}
// Comprueba el manejador de eventos
void Ending::checkEventHandler()
{
// Comprueba los eventos que hay en la cola
while (SDL_PollEvent(eventHandler) != 0)
{
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
{
section.name = SECTION_PROG_QUIT;
break;
}
// Comprueba las teclas que se han pulsado
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
{
switch (eventHandler->key.keysym.scancode)
{
case SDL_SCANCODE_ESCAPE:
section.name = SECTION_PROG_QUIT;
break;
case SDL_SCANCODE_B:
screen->switchBorder();
resource->reLoadTextures();
break;
case SDL_SCANCODE_F:
screen->switchVideoMode();
resource->reLoadTextures();
break;
case SDL_SCANCODE_F1:
screen->setWindowSize(1);
resource->reLoadTextures();
break;
case SDL_SCANCODE_F2:
screen->setWindowSize(2);
resource->reLoadTextures();
break;
case SDL_SCANCODE_F3:
screen->setWindowSize(3);
resource->reLoadTextures();
break;
case SDL_SCANCODE_F4:
screen->setWindowSize(4);
resource->reLoadTextures();
break;
case SDL_SCANCODE_F5:
// switchPalette();
break;
default:
// section.name = SECTION_PROG_TITLE;
// section.subsection = 0;
break;
}
}
}
}
// Bucle principal
section_t Ending::run()
{
while (section.name == SECTION_PROG_ENDING)
{
update();
render();
}
return section;
}

59
source/ending.h Normal file
View File

@@ -0,0 +1,59 @@
#pragma once
#include <SDL2/SDL.h>
#include "common/animatedsprite.h"
#include "common/asset.h"
#include "common/jail_audio.h"
#include "common/resource.h"
#include "common/screen.h"
#include "common/sprite.h"
#include "common/text.h"
#include "common/texture.h"
#include "common/utils.h"
#include "const.h"
#include <vector>
#ifndef ENDING_H
#define ENDING_H
class Ending
{
private:
// Objetos y punteros
SDL_Renderer *renderer; // El renderizador de la ventana
Screen *screen; // Objeto encargado de dibujar en pantalla
Resource *resource; // Objeto con los recursos
Asset *asset; // Objeto con los ficheros de recursos
options_t *options; // Puntero a las opciones del juego
SDL_Event *eventHandler; // Manejador de eventos
Text *text; // Objeto para escribir texto en pantalla
SDL_Texture *textTexture; // Textura para dibujar el texto
SDL_Texture *coverTexture; // Textura para cubrir el texto
AnimatedSprite *sprite; // Sprite para el brillo del corazón
// Variables
int counter; // Contador
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 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
// Actualiza el objeto
void update();
// Dibuja el final en pantalla
void render();
// Comprueba el manejador de eventos
void checkEventHandler();
public:
// Constructor
Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options);
// Destructor
~Ending();
// Bucle principal
section_t run();
};
#endif

133
source/game_over.cpp Normal file
View File

@@ -0,0 +1,133 @@
#include "game_over.h"
// Constructor
GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options)
{
// Copia los punteros
this->renderer = renderer;
this->screen = screen;
this->resource = resource;
this->asset = asset;
this->options = options;
// Reserva memoria para los punteros a objetos
eventHandler = new SDL_Event();
// Inicializa variables
counter = 0;
section.name = SECTION_PROG_GAME_OVER;
section.subsection = 0;
ticks = 0;
ticksSpeed = 15;
}
// Destructor
GameOver::~GameOver()
{
// Libera la memoria de los objetos
delete eventHandler;
}
// Actualiza el objeto
void GameOver::update()
{
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
if (SDL_GetTicks() - ticks > ticksSpeed)
{
// Actualiza el contador de ticks
ticks = SDL_GetTicks();
// Comprueba el manejador de eventos
checkEventHandler();
}
}
// Dibuja el final en pantalla
void GameOver::render()
{
// Prepara para empezar a dibujar en la textura de juego
screen->start();
// Limpia la pantalla
screen->clean();
// Vuelca el contenido del renderizador en pantalla
screen->blit();
}
// Comprueba el manejador de eventos
void GameOver::checkEventHandler()
{
// Comprueba los eventos que hay en la cola
while (SDL_PollEvent(eventHandler) != 0)
{
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
{
section.name = SECTION_PROG_QUIT;
break;
}
// Comprueba las teclas que se han pulsado
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
{
switch (eventHandler->key.keysym.scancode)
{
case SDL_SCANCODE_ESCAPE:
section.name = SECTION_PROG_QUIT;
break;
case SDL_SCANCODE_B:
screen->switchBorder();
resource->reLoadTextures();
break;
case SDL_SCANCODE_F:
screen->switchVideoMode();
resource->reLoadTextures();
break;
case SDL_SCANCODE_F1:
screen->setWindowSize(1);
resource->reLoadTextures();
break;
case SDL_SCANCODE_F2:
screen->setWindowSize(2);
resource->reLoadTextures();
break;
case SDL_SCANCODE_F3:
screen->setWindowSize(3);
resource->reLoadTextures();
break;
case SDL_SCANCODE_F4:
screen->setWindowSize(4);
resource->reLoadTextures();
break;
case SDL_SCANCODE_F5:
// switchPalette();
break;
default:
// section.name = SECTION_PROG_TITLE;
// section.subsection = 0;
break;
}
}
}
}
// Bucle principal
section_t GameOver::run()
{
while (section.name == SECTION_PROG_GAME_OVER)
{
update();
render();
}
return section;
}

59
source/game_over.h Normal file
View File

@@ -0,0 +1,59 @@
#pragma once
#include <SDL2/SDL.h>
#include "common/animatedsprite.h"
#include "common/asset.h"
#include "common/jail_audio.h"
#include "common/resource.h"
#include "common/screen.h"
#include "common/sprite.h"
#include "common/text.h"
#include "common/texture.h"
#include "common/utils.h"
#include "const.h"
#include <vector>
#ifndef GAME_OVER_H
#define GAME_OVER_H
class GameOver
{
private:
// Objetos y punteros
SDL_Renderer *renderer; // El renderizador de la ventana
Screen *screen; // Objeto encargado de dibujar en pantalla
Resource *resource; // Objeto con los recursos
Asset *asset; // Objeto con los ficheros de recursos
options_t *options; // Puntero a las opciones del juego
SDL_Event *eventHandler; // Manejador de eventos
Text *text; // Objeto para escribir texto en pantalla
SDL_Texture *textTexture; // Textura para dibujar el texto
SDL_Texture *coverTexture; // Textura para cubrir el texto
AnimatedSprite *sprite; // Sprite para el brillo del corazón
// Variables
int counter; // Contador
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 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
// Actualiza el objeto
void update();
// Dibuja el final en pantalla
void render();
// Comprueba el manejador de eventos
void checkEventHandler();
public:
// Constructor
GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options);
// Destructor
~GameOver();
// Bucle principal
section_t run();
};
#endif