Afegides mes descripcions a les classes

Eliminat el punter a renderer de les classes-estat que faltava
This commit is contained in:
2024-08-12 08:55:41 +02:00
parent 477891cac7
commit 9d5aee2562
15 changed files with 113 additions and 57 deletions

View File

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

View File

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

View File

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

View File

@@ -2,10 +2,9 @@
#include <iostream>
// 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();

View File

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

View File

@@ -2,16 +2,16 @@
#include <iostream>
// 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);

View File

@@ -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<Texture *> itemTextures; // Vector con las texturas de los items
std::vector<Sprite *> 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();

View File

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

View File

@@ -12,12 +12,16 @@
#include "lang.h"
#include <vector>
/*
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();

View File

@@ -2,15 +2,15 @@
#include <iostream>
// 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();

View File

@@ -10,11 +10,19 @@
#include "const.h"
#include <vector>
/*
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();

View File

@@ -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<hiScoreEntry_t> *table);

View File

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

View File

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

View File

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