From 9d5aee25620f571fa90458d2c019ab0156b4cbba Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 12 Aug 2024 08:55:41 +0200 Subject: [PATCH] Afegides mes descripcions a les classes Eliminat el punter a renderer de les classes-estat que faltava --- source/director.cpp | 20 ++++++++++---------- source/game.cpp | 10 +++++----- source/game.h | 28 +++++++++++++++++++++++++++- source/hiscore_table.cpp | 4 ++-- source/hiscore_table.h | 13 +++++++++++-- source/instructions.cpp | 6 +++--- source/instructions.h | 16 ++++++++++++++-- source/intro.cpp | 6 ++---- source/intro.h | 8 ++++++-- source/logo.cpp | 4 ++-- source/logo.h | 12 ++++++++++-- source/manage_hiscore_table.h | 9 ++++----- source/tiledbg.h | 8 ++++---- source/title.cpp | 4 ++-- source/title.h | 22 +++++++++++----------- 15 files changed, 113 insertions(+), 57 deletions(-) diff --git a/source/director.cpp b/source/director.cpp index 810835f..e289bda 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -708,7 +708,7 @@ bool Director::saveConfigFile() { file << "notification.posV=pos_top\n"; } - + else { file << "notification.posV=pos_bottom\n"; @@ -718,12 +718,12 @@ bool Director::saveConfigFile() { file << "notification.posH=pos_left\n"; } - + else if (options->notification.posH == pos_middle) { file << "notification.posH=pos_middle\n"; } - + else { file << "notification.posH=pos_right\n"; @@ -836,7 +836,7 @@ void Director::deleteMusics() // Ejecuta la seccion de juego con el logo void Director::runLogo() { - logo = new Logo(renderer, screen, asset, input, param, section); + logo = new Logo(screen, asset, input, param, section); logo->run(); delete logo; } @@ -844,7 +844,7 @@ void Director::runLogo() // Ejecuta la seccion de juego de la introducción void Director::runIntro() { - intro = new Intro(renderer, screen, asset, input, lang, param, section, getMusic(musics, "intro.ogg")); + intro = new Intro(screen, asset, input, lang, param, section, getMusic(musics, "intro.ogg")); intro->run(); delete intro; } @@ -852,7 +852,7 @@ void Director::runIntro() // Ejecuta la seccion de juego con el titulo y los menus void Director::runTitle() { - title = new Title(screen, input, asset, options, lang, param, section, getMusic(musics, "title.ogg")); + title = new Title(screen, asset, input, options, lang, param, section, getMusic(musics, "title.ogg")); title->run(); delete title; } @@ -861,7 +861,7 @@ void Director::runTitle() void Director::runGame() { const int playerID = section->subsection == SUBSECTION_GAME_PLAY_1P ? 1 : 2; - game = new Game(playerID, 0, renderer, screen, asset, lang, input, false, param, options, section, getMusic(musics, "playing.ogg")); + game = new Game(playerID, 0, screen, asset, lang, input, false, param, options, section, getMusic(musics, "playing.ogg")); game->run(); delete game; } @@ -869,7 +869,7 @@ void Director::runGame() // Ejecuta la parte donde se muestra la tabla de puntuaciones void Director::runHiScoreTable() { - hiScoreTable = new HiScoreTable(renderer, screen, asset, input, lang, param, options, section); + hiScoreTable = new HiScoreTable(screen, asset, input, lang, param, options, section); hiScoreTable->run(); delete hiScoreTable; } @@ -877,7 +877,7 @@ void Director::runHiScoreTable() // Ejecuta la parte donde se muestran las instrucciones void Director::runInstructions() { - instructions = new Instructions(renderer, screen, asset, input, lang, param, section); + instructions = new Instructions(screen, asset, input, lang, param, section); instructions->run(); delete instructions; } @@ -886,7 +886,7 @@ void Director::runInstructions() void Director::runDemoGame() { const int playerID = (rand() % 2) + 1; - demoGame = new Game(playerID, 0, renderer, screen, asset, lang, input, true, param, options, section, nullptr); + demoGame = new Game(playerID, 0, screen, asset, lang, input, true, param, options, section, nullptr); demoGame->run(); delete demoGame; } diff --git a/source/game.cpp b/source/game.cpp index 206b761..c7cc439 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -3,10 +3,9 @@ #define DEATH_COUNTER 350 // Constructor -Game::Game(int playerID, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, param_t *param, options_t *options, section_t *section, JA_Music_t *music) +Game::Game(int playerID, int currentStage, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, param_t *param, options_t *options, section_t *section, JA_Music_t *music) { // Copia los punteros - this->renderer = renderer; this->screen = screen; this->asset = asset; this->lang = lang; @@ -15,6 +14,7 @@ Game::Game(int playerID, int currentStage, SDL_Renderer *renderer, Screen *scree this->options = options; this->section = section; this->music = music; + renderer = screen->getRenderer(); // Pasa variables this->demo.enabled = demo; @@ -967,9 +967,9 @@ void Game::renderPlayers() { player->render(); #ifdef DEBUG - //SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); - //const circle_t c = player->getCollider(); - //DrawCircle(renderer, c.x, c.y, c.r); + // SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); + // const circle_t c = player->getCollider(); + // DrawCircle(renderer, c.x, c.y, c.r); #endif } } diff --git a/source/game.h b/source/game.h index 0f35643..9fd60d4 100644 --- a/source/game.h +++ b/source/game.h @@ -46,6 +46,32 @@ // Valores para las variables asociadas a los objetos #define TIME_STOPPED_COUNTER 300 +/* + Esta clase gestiona un estado del programa. Se encarga de toda la parte en la + que se está jugando. + + Tiene: + - Cacheadas todas las texturas y animaciones que usaran los diferentes objetos. + Mediante el método loadMedia() almacena en vectores todos los recursos + - Tiene vectores con objetos: jugadores, enemigos, balas, explosiones, objetos y otros (sprites con los puntos al coger objetos) + - Se encarga de comprobar las colisiones entre los diferentes objetos, los marca como deshabilitados si es el caso y + luego revisa los vectores para eliminar los objetos deshabilitados + + Utiliza: + - Un objeto para dibujar el fondo animado + - Un objeto para dibujar el marcador + + La clase comprueba el nivel de amenaza que hay en pantalla contando el número de enemigos y su peligrosidad y actua en consecuencia: + - Generando items + - Generando nuevas oleadas enemigas + + Mientras haya un jugador activo siempre puede unirse un segundo jugador. Cada vez que un jugador muere + aparece una cuenta atras para permitirle continuar. Si la cuenta atras de ambos jugadores llega a cero, + el juego termina. Cuando ambos jugadores han finalizado, se permite introducir nombre para la tabla de records + adjuntando la máxima puntuación obtenida en la partida, solo en caso de que hayan conseguido superar la + puntuación mínima. +*/ + // Clase Game class Game { @@ -428,7 +454,7 @@ private: public: // Constructor - Game(int playerID, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, param_t *param, options_t *options, section_t *section, JA_Music_t *music); + Game(int playerID, int currentStage, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, param_t *param, options_t *options, section_t *section, JA_Music_t *music); // Destructor ~Game(); diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index 877ec82..a8ae201 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -2,10 +2,9 @@ #include // Constructor -HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, options_t *options, section_t *section) +HiScoreTable::HiScoreTable(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, options_t *options, section_t *section) { // Copia punteros - this->renderer = renderer; this->screen = screen; this->asset = asset; this->input = input; @@ -13,6 +12,7 @@ HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, this->section = section; this->options = options; this->param = param; + SDL_Renderer *renderer = screen->getRenderer(); // Objetos eventHandler = new SDL_Event(); diff --git a/source/hiscore_table.h b/source/hiscore_table.h index a335386..34ea922 100644 --- a/source/hiscore_table.h +++ b/source/hiscore_table.h @@ -13,12 +13,21 @@ #include "fade.h" #include "background.h" +/* + Esta clase gestiona un estado del programa. Se encarga de mostrar la tabla con las puntuaciones + más altas. Para ello utiliza un objeto que se encarga de pintar el fondo y una textura + sobre la que escribe las puntuacions. Esta textura se recorre modificando la ventana de vista + para dar el efecto de que la textura se mueve sobre la pantalla. + + Para mejorar la legibilidad de los textos, el objeto que dibuja el fondo es capaz de modificar + su atenuación. +*/ + // Clase HiScoreTable class HiScoreTable { private: // Objetos y punteros - SDL_Renderer *renderer; // El renderizador de la ventana Screen *screen; // Objeto encargado de dibujar en pantalla SDL_Event *eventHandler; // Manejador de eventos SDL_Texture *backbuffer; // Textura para usar como backbuffer @@ -69,7 +78,7 @@ private: public: // Constructor - HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, options_t *options, section_t *section); + HiScoreTable(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, options_t *options, section_t *section); // Destructor ~HiScoreTable(); diff --git a/source/instructions.cpp b/source/instructions.cpp index 0149ff3..950238d 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -2,16 +2,16 @@ #include // Constructor -Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section) +Instructions::Instructions(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section) { // Copia los punteros - this->renderer = renderer; this->screen = screen; this->asset = asset; this->input = input; this->lang = lang; this->param = param; this->section = section; + SDL_Renderer *renderer = screen->getRenderer(); // Crea objetos eventHandler = new SDL_Event(); @@ -181,7 +181,7 @@ void Instructions::fillTexture() text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, anchor2, lang->getText(16), 1, orangeColor, 1, shdwTxtColor); const int anchor3 = anchor2 + spacePostHeader; - //const int anchor4 = anchor3 + ((param->itemSize + text->getCharacterSize()) / 2); + // const int anchor4 = anchor3 + ((param->itemSize + text->getCharacterSize()) / 2); text->writeShadowed(anchorItem + despX, anchor3 + spaceBetweenItemLines * 0, lang->getText(17), shdwTxtColor); text->writeShadowed(anchorItem + despX, anchor3 + spaceBetweenItemLines * 1, lang->getText(18), shdwTxtColor); text->writeShadowed(anchorItem + despX, anchor3 + spaceBetweenItemLines * 2, lang->getText(19), shdwTxtColor); diff --git a/source/instructions.h b/source/instructions.h index a89ea67..ae9905b 100644 --- a/source/instructions.h +++ b/source/instructions.h @@ -13,12 +13,24 @@ #include "tiledbg.h" #include "fade.h" +/* + Esta clase gestiona un estado del programa. Se encarga de poner en pantalla + un texto explicativo para entender como se juega. + + Ademas muestra algunos items y explica para qué sirven. + + Utiliza dos texturas de apoyo, una con el texto ya escrito y otra donde se combina + tanto el texto de la primera textura como los sprites de los items. + + Finalmente, una ventana recorre la textura para dar el efecto de que todo se desplaza + por la pantalla sobre el mosaico de fondo (gestionado por el correspondiente objeto) +*/ + // Clase Instructions class Instructions { private: // Objetos y punteros - SDL_Renderer *renderer; // El renderizador de la ventana Screen *screen; // Objeto encargado de dibujar en pantalla std::vector itemTextures; // Vector con las texturas de los items std::vector sprites; // Vector con los sprites de los items @@ -72,7 +84,7 @@ private: public: // Constructor - Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section); + Instructions(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section); // Destructor ~Instructions(); diff --git a/source/intro.cpp b/source/intro.cpp index 434a92d..c94b052 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -1,10 +1,9 @@ #include "intro.h" // Constructor -Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section, JA_Music_t *music) +Intro::Intro(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section, JA_Music_t *music) { // Copia los punteros - this->renderer = renderer; this->screen = screen; this->lang = lang; this->asset = asset; @@ -12,6 +11,7 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, this->param = param; this->section = section; this->music = music; + SDL_Renderer *renderer = screen->getRenderer(); // Reserva memoria para los objetos eventHandler = new SDL_Event(); @@ -146,8 +146,6 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Intro::~Intro() { delete eventHandler; - - texture->unload(); delete texture; for (auto bitmap : bitmaps) diff --git a/source/intro.h b/source/intro.h index 6324eed..a86d9e0 100644 --- a/source/intro.h +++ b/source/intro.h @@ -12,12 +12,16 @@ #include "lang.h" #include +/* + Esta clase gestiona un estado del programa. Se encarga de mostrar la secuencia + de introducción +*/ + // Clase Intro class Intro { private: // Objetos y punteros - SDL_Renderer *renderer; // El renderizador de la ventana Screen *screen; // Objeto encargado de dibujar en pantalla Texture *texture; // Textura con los graficos SDL_Event *eventHandler; // Manejador de eventos @@ -56,7 +60,7 @@ private: public: // Constructor - Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section, JA_Music_t *music); + Intro(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section, JA_Music_t *music); // Destructor ~Intro(); diff --git a/source/logo.cpp b/source/logo.cpp index 945c6f6..6e1d469 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -2,15 +2,15 @@ #include // Constructor -Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, param_t *param, section_t *section) +Logo::Logo(Screen *screen, Asset *asset, Input *input, param_t *param, section_t *section) { // Copia la dirección de los objetos - this->renderer = renderer; this->screen = screen; this->asset = asset; this->input = input; this->param = param; this->section = section; + SDL_Renderer *renderer = screen->getRenderer(); // Reserva memoria para los punteros eventHandler = new SDL_Event(); diff --git a/source/logo.h b/source/logo.h index 0ee2614..2897146 100644 --- a/source/logo.h +++ b/source/logo.h @@ -10,11 +10,19 @@ #include "const.h" #include +/* + Esta clase gestiona un estado del programa. Se encarga de dibujar por pantalla el + logo de "JAILGAMES" utilizando un sencillo efecto consistente en generar un sprite por + cada linea del bitmap que forma la palabra "JAILGAMES". Posteriormente realiza una + modulación de color sobre la textura para simular un fade to black al estilo + ZX Spectrum +*/ + +// Clase Logo class Logo { private: // Objetos y punteros - SDL_Renderer *renderer; // El renderizador de la ventana Screen *screen; // Objeto encargado de dibujar en pantalla Asset *asset; // Objeto con los ficheros de recursos Input *input; // Objeto pata gestionar la entrada @@ -60,7 +68,7 @@ private: public: // Constructor - Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, param_t *param, section_t *section); + Logo(Screen *screen, Asset *asset, Input *input, param_t *param, section_t *section); // Destructor ~Logo(); diff --git a/source/manage_hiscore_table.h b/source/manage_hiscore_table.h index 6bc36cf..5d81bb2 100644 --- a/source/manage_hiscore_table.h +++ b/source/manage_hiscore_table.h @@ -4,12 +4,11 @@ #include "common/utils.h" /* -Esta clase sirve para añadir elementos hiScoreEntry_r a un vector (tabla), de manera -que la tabla siempre está ordenada. Además también tiene un método para dejar la tabla -con sus valores iniciales + Esta clase sirve para añadir elementos hiScoreEntry_r a un vector (tabla), de manera + que la tabla siempre está ordenada. Además también tiene un método para dejar la tabla + con sus valores iniciales */ - // Clase ManageHiScoreTable class ManageHiScoreTable { @@ -19,7 +18,7 @@ private: // Ordena la tabla void sort(); - + public: // Constructor ManageHiScoreTable(std::vector *table); diff --git a/source/tiledbg.h b/source/tiledbg.h index f43e61f..8b0d429 100644 --- a/source/tiledbg.h +++ b/source/tiledbg.h @@ -13,9 +13,9 @@ #define TILED_MODE_STATIC 3 /* -Esta clase dibuja un tileado de fondo. Para ello se sirve de una textura "canvas", que rellena con los tiles. -El rectangulo "window" recorre la textura de diferentes formas para generar el efecto de movimiento de la -textura en pantalla + Esta clase dibuja un tileado de fondo. Para ello se sirve de una textura "canvas", que rellena con los tiles. + El rectangulo "window" recorre la textura de diferentes formas para generar el efecto de movimiento de la + textura en pantalla */ // Clase Tiledbg @@ -31,7 +31,7 @@ private: // Variables SDL_Rect pos; // Posición y tamaña del mosaico int counter; // Contador - int mode; // Tipo de movimiento del mosaico + int mode; // Tipo de movimiento del mosaico float sin[360]; // Vector con los valores del seno precalculados int tileWidth; // Ancho del tile int tileHeight; // Alto del tile diff --git a/source/title.cpp b/source/title.cpp index 7518d55..950db69 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -1,7 +1,7 @@ #include "title.h" // Constructor -Title::Title(Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, param_t *param, section_t *section, JA_Music_t *music) +Title::Title(Screen *screen, Asset *asset, Input *input, options_t *options, Lang *lang, param_t *param, section_t *section, JA_Music_t *music) { // Copia las direcciones de los punteros y objetos this->screen = screen; @@ -245,7 +245,7 @@ void Title::checkInput() if (index) { if (section->subsection == SUBSECTION_TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP) - {// No se puede empezar a jugar durante la animación del titulo + { // No se puede empezar a jugar durante la animación del titulo fade->activate(); postFade = index; } diff --git a/source/title.h b/source/title.h index 0feedd1..c1cd7d0 100644 --- a/source/title.h +++ b/source/title.h @@ -28,18 +28,18 @@ #define ALLOW_TITLE_ANIMATION_SKIP false /* -Esta clase gestiona un estado del programa. Se encarga de la parte del titulo o menu -que sirve para empezar a jugar. Utiliza otras clases para: - - Mostrar el logo del juego - - Dibujar el tileado de fondo - - Redifinir los botones de los mandos de juego + Esta clase gestiona un estado del programa. Se encarga de la parte del titulo o menu + que sirve para empezar a jugar. Utiliza otras clases para: + - Mostrar el logo del juego + - Dibujar el tileado de fondo + - Redifinir los botones de los mandos de juego -Esta clase tiene dos estados: - - El titulo está animandose, con el fondo estático - - El titulo ya está en su sitio y el fondo se está animando + Esta clase tiene dos estados: + - El titulo está animandose, con el fondo estático + - El titulo ya está en su sitio y el fondo se está animando -Por razones de diseño, no se permite saltarse la animación del titulo, aunque es -configurable mediante un define + Por razones de diseño, no se permite saltarse la animación del titulo, aunque es + configurable mediante un define */ // Clase Title @@ -96,7 +96,7 @@ private: public: // Constructor - Title(Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, param_t *param, section_t *section, JA_Music_t *music); + Title(Screen *screen, Asset *asset, Input *input, options_t *options, Lang *lang, param_t *param, section_t *section, JA_Music_t *music); // Destructor ~Title();