Añadido puntero a la estructura param en las clases necesarias

This commit is contained in:
2024-06-18 08:58:28 +02:00
parent c98f0fc3d9
commit 022e44cfeb
22 changed files with 133 additions and 98 deletions

View File

@@ -1,12 +1,13 @@
#include "background.h" #include "background.h"
// Constructor // Constructor
Background::Background(SDL_Renderer *renderer, Screen *screen, Asset *asset) Background::Background(SDL_Renderer *renderer, Screen *screen, Asset *asset, param_t *param)
{ {
// Copia los punteros // Copia los punteros
this->renderer = renderer; this->renderer = renderer;
this->screen = screen; this->screen = screen;
this->asset = asset; this->asset = asset;
this->param = param;
// Inicializa variables // Inicializa variables
gradientNumber = 0; gradientNumber = 0;

View File

@@ -29,6 +29,7 @@ private:
SDL_Rect dstRect; // Posición donde dibujar la parte del objeto fondo que se dibujará en pantalla SDL_Rect dstRect; // Posición donde dibujar la parte del objeto fondo que se dibujará en pantalla
SDL_Texture *canvas; // Textura para componer el fondo SDL_Texture *canvas; // Textura para componer el fondo
int base; // Linea de fondo coincidente con el area inferior de la zona de juego int base; // Linea de fondo coincidente con el area inferior de la zona de juego
param_t *param; // Puntero con todos los parametros del programa
Texture *buildingsTexture; // Textura con los edificios de fondo Texture *buildingsTexture; // Textura con los edificios de fondo
Texture *cloudsTexture; // Textura con las nubes de fondo Texture *cloudsTexture; // Textura con las nubes de fondo
@@ -49,7 +50,7 @@ private:
public: public:
// Constructor // Constructor
Background(SDL_Renderer *renderer, Screen *screen, Asset *asset); Background(SDL_Renderer *renderer, Screen *screen, Asset *asset, param_t *param);
// Destructor // Destructor
~Background(); ~Background();

View File

@@ -156,6 +156,14 @@ struct options_t
op_audio_t audio; // Opciones para el audio op_audio_t audio; // Opciones para el audio
}; };
struct param_t
{
int gameWidth; // Ancho del juego
int gameHeight; // Alto del juego
SDL_Rect scoreboard; // Posición y tamaño del marcador
};
// Calcula el cuadrado de la distancia entre dos puntos // Calcula el cuadrado de la distancia entre dos puntos
double distanceSquared(int x1, int y1, int x2, int y2); double distanceSquared(int x1, int y1, int x2, int y2);

View File

@@ -11,18 +11,18 @@
#define HALF_BLOCK BLOCK / 2 #define HALF_BLOCK BLOCK / 2
// Resolución nativa del juego // Resolución nativa del juego
#define GAMECANVAS_WIDTH 320 #define WIDTH 320
#define GAMECANVAS_HEIGHT 240 #define HEIGHT 240
// Marcador // Marcador
const int SCOREBOARD_WIDTH = GAMECANVAS_WIDTH; const int SCOREBOARD_WIDTH = WIDTH;
const int SCOREBOARD_HEIGHT = 32; const int SCOREBOARD_HEIGHT = 32;
const int SCOREBOARD_X = 0; const int SCOREBOARD_X = 0;
const int SCOREBOARD_Y = GAMECANVAS_HEIGHT - SCOREBOARD_HEIGHT; const int SCOREBOARD_Y = HEIGHT - SCOREBOARD_HEIGHT;
// Zona de juego // Zona de juego
const SDL_Rect windowArea = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT}; const SDL_Rect windowArea = {0, 0, WIDTH, HEIGHT};
const SDL_Rect playArea = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT - SCOREBOARD_HEIGHT}; const SDL_Rect playArea = {0, 0, WIDTH, HEIGHT - SCOREBOARD_HEIGHT};
const int PLAY_AREA_TOP = 0; const int PLAY_AREA_TOP = 0;
const int PLAY_AREA_BOTTOM = playArea.h; const int PLAY_AREA_BOTTOM = playArea.h;
const int PLAY_AREA_LEFT = 0; const int PLAY_AREA_LEFT = 0;
@@ -37,12 +37,12 @@ const int PLAY_AREA_FIRST_QUARTER_Y = PLAY_AREA_HEIGHT / 4;
const int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3; const int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3;
// Anclajes de pantalla // Anclajes de pantalla
const int GAMECANVAS_CENTER_X = GAMECANVAS_WIDTH / 2; const int GAMECANVAS_CENTER_X = WIDTH / 2;
const int GAMECANVAS_FIRST_QUARTER_X = GAMECANVAS_WIDTH / 4; const int GAMECANVAS_FIRST_QUARTER_X = WIDTH / 4;
const int GAMECANVAS_THIRD_QUARTER_X = (GAMECANVAS_WIDTH / 4) * 3; const int GAMECANVAS_THIRD_QUARTER_X = (WIDTH / 4) * 3;
const int GAMECANVAS_CENTER_Y = GAMECANVAS_HEIGHT / 2; const int GAMECANVAS_CENTER_Y = HEIGHT / 2;
const int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4; const int GAMECANVAS_FIRST_QUARTER_Y = HEIGHT / 4;
const int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3; const int GAMECANVAS_THIRD_QUARTER_Y = (HEIGHT / 4) * 3;
// Secciones del programa // Secciones del programa
#define SECTION_PROG_LOGO 0 #define SECTION_PROG_LOGO 0

View File

@@ -14,6 +14,9 @@
// Constructor // Constructor
Director::Director(int argc, char *argv[]) Director::Director(int argc, char *argv[])
{ {
// Carga los parametros para configurar el juego
loadParams();
// Inicializa variables // Inicializa variables
section = new section_t(); section = new section_t();
section->name = SECTION_PROG_TITLE; section->name = SECTION_PROG_TITLE;
@@ -70,6 +73,7 @@ Director::~Director()
delete screen; delete screen;
delete lang; delete lang;
delete options; delete options;
delete param;
delete section; delete section;
SDL_DestroyRenderer(renderer); SDL_DestroyRenderer(renderer);
@@ -186,9 +190,6 @@ bool Director::initSDL()
else else
{ {
// Crea un renderizador para la ventana. El vsync se activa en funcion de las opciones // Crea un renderizador para la ventana. El vsync se activa en funcion de las opciones
// Crea un renderizador para la ventana. El vsync se activa en funcion de las opciones
// Uint32 flags = SDL_RENDERER_SOFTWARE;
// Uint32 flags = SDL_RENDERER_ACCELERATED;
Uint32 flags = 0; Uint32 flags = 0;
if (options->video.vSync) if (options->video.vSync)
{ {
@@ -357,6 +358,17 @@ bool Director::setFileList()
return asset->check(); return asset->check();
} }
// Carga los parametros para configurar el juego
void Director::loadParams()
{
param = new param_t;
param->gameWidth = 320;
param->gameHeight = 240;
param->scoreboard = {0, 240-32, 320, 32};
}
// Inicializa las opciones del programa // Inicializa las opciones del programa
void Director::initOptions() void Director::initOptions()
{ {
@@ -378,8 +390,8 @@ void Director::initOptions()
options->input.push_back(inp); options->input.push_back(inp);
// Opciones de video // Opciones de video
options->video.gameWidth = GAMECANVAS_WIDTH; options->video.gameWidth = param->gameWidth;
options->video.gameHeight = GAMECANVAS_HEIGHT; options->video.gameHeight = param->gameHeight;
options->video.mode = 0; options->video.mode = 0;
options->video.window.size = 3; options->video.window.size = 3;
options->video.window.width = options->video.window.size * options->video.gameWidth; options->video.window.width = options->video.window.size * options->video.gameWidth;
@@ -625,21 +637,21 @@ bool Director::saveConfigFile()
void Director::runLogo() void Director::runLogo()
{ {
logo = new Logo(renderer, screen, asset, input, section); logo = new Logo(renderer, screen, asset, input, param, section);
logo->run(); logo->run();
delete logo; delete logo;
} }
void Director::runIntro() void Director::runIntro()
{ {
intro = new Intro(renderer, screen, asset, input, lang, section); intro = new Intro(renderer, screen, asset, input, lang, param, section);
intro->run(); intro->run();
delete intro; delete intro;
} }
void Director::runTitle() void Director::runTitle()
{ {
title = new Title(renderer, screen, input, asset, options, lang, section); title = new Title(renderer, screen, input, asset, options, lang, param, section);
title->run(); title->run();
delete title; delete title;
} }
@@ -647,7 +659,7 @@ void Director::runTitle()
void Director::runGame() void Director::runGame()
{ {
const int numPlayers = section->subsection == SUBSECTION_GAME_PLAY_1P ? 1 : 2; const int numPlayers = section->subsection == SUBSECTION_GAME_PLAY_1P ? 1 : 2;
game = new Game(numPlayers, 0, renderer, screen, asset, lang, input, false, options, section); game = new Game(numPlayers, 0, renderer, screen, asset, lang, input, false, param, options, section);
game->run(); game->run();
delete game; delete game;
} }
@@ -768,7 +780,7 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
options->audio.sound.enabled = stringToBool(value); options->audio.sound.enabled = stringToBool(value);
} }
else if (var == "sound.volume") else if (var == "sound.volume")
{ {
options->audio.sound.volume = std::stoi(value); options->audio.sound.volume = std::stoi(value);
} }

View File

@@ -46,7 +46,8 @@ private:
section_t *section; // Sección y subsección actual del programa; section_t *section; // Sección y subsección actual del programa;
// Variables // Variables
struct options_t *options; // Variable con todas las opciones del programa options_t *options; // Variable con todas las opciones del programa
param_t *param; // Variable con todos los parametros del programa
std::string executablePath; // Path del ejecutable std::string executablePath; // Path del ejecutable
std::string systemFolder; // Carpeta del sistema donde guardar datos std::string systemFolder; // Carpeta del sistema donde guardar datos
@@ -59,6 +60,9 @@ private:
// Inicializa el objeto input // Inicializa el objeto input
void initInput(); void initInput();
// Carga los parametros para configurar el juego
void loadParams();
// Inicializa las opciones del programa // Inicializa las opciones del programa
void initOptions(); void initOptions();

View File

@@ -3,15 +3,11 @@
#include <iostream> #include <iostream>
// Constructor // Constructor
Fade::Fade(SDL_Renderer *renderer) Fade::Fade(SDL_Renderer *renderer, param_t *param)
{ {
mRenderer = renderer; mRenderer = renderer;
mBackbuffer = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); mBackbuffer = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->gameWidth, param->gameHeight);
if (mBackbuffer == nullptr)
{
std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
} }
// Destructor // Destructor
@@ -41,7 +37,7 @@ void Fade::render()
switch (mFadeType) switch (mFadeType)
{ {
case FADE_FULLSCREEN: case FADE_FULLSCREEN:
mRect1 = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT}; mRect1 = {0, 0, param->gameWidth, param->gameHeight};
for (int i = 0; i < 256; i += 4) for (int i = 0; i < 256; i += 4)
{ {
@@ -69,21 +65,21 @@ void Fade::render()
break; break;
case FADE_CENTER: case FADE_CENTER:
mRect1 = {0, 0, GAMECANVAS_WIDTH, 0}; mRect1 = {0, 0, param->gameWidth, 0};
mRect2 = {0, 0, GAMECANVAS_WIDTH, 0}; mRect2 = {0, 0, param->gameWidth, 0};
SDL_SetRenderDrawColor(mRenderer, mR, mG, mB, 64); SDL_SetRenderDrawColor(mRenderer, mR, mG, mB, 64);
for (int i = 0; i < mCounter; i++) for (int i = 0; i < mCounter; i++)
{ {
mRect1.h = mRect2.h = i * 4; mRect1.h = mRect2.h = i * 4;
mRect2.y = GAMECANVAS_HEIGHT - (i * 4); mRect2.y = param->gameHeight - (i * 4);
SDL_RenderFillRect(mRenderer, &mRect1); SDL_RenderFillRect(mRenderer, &mRect1);
SDL_RenderFillRect(mRenderer, &mRect2); SDL_RenderFillRect(mRenderer, &mRect2);
} }
if ((mCounter * 4) > GAMECANVAS_HEIGHT) if ((mCounter * 4) > param->gameHeight)
mFinished = true; mFinished = true;
break; break;
@@ -101,8 +97,8 @@ void Fade::render()
// Dibujamos sobre el backbuffer // Dibujamos sobre el backbuffer
SDL_SetRenderTarget(mRenderer, mBackbuffer); SDL_SetRenderTarget(mRenderer, mBackbuffer);
mRect1.x = rand() % (GAMECANVAS_WIDTH - mRect1.w); mRect1.x = rand() % (param->gameWidth - mRect1.w);
mRect1.y = rand() % (GAMECANVAS_HEIGHT - mRect1.h); mRect1.y = rand() % (param->gameHeight - mRect1.h);
SDL_RenderFillRect(mRenderer, &mRect1); SDL_RenderFillRect(mRenderer, &mRect1);
// Volvemos a usar el renderizador de forma normal // Volvemos a usar el renderizador de forma normal

View File

@@ -2,6 +2,7 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "common/texture.h" #include "common/texture.h"
#include "common/utils.h"
#ifndef FADE_H #ifndef FADE_H
#define FADE_H #define FADE_H
@@ -15,19 +16,23 @@
class Fade class Fade
{ {
private: private:
// Objetos y punteros
SDL_Renderer *mRenderer; // El renderizador de la ventana SDL_Renderer *mRenderer; // El renderizador de la ventana
SDL_Texture *mBackbuffer; // Textura para usar como backbuffer SDL_Texture *mBackbuffer; // Textura para usar como backbuffer
Uint8 mFadeType; // Tipo de fade a realizar
Uint16 mCounter; // Contador interno // Variables
bool mEnabled; // Indica si el fade está activo Uint8 mFadeType; // Tipo de fade a realizar
bool mFinished; // Indica si ha terminado la transición Uint16 mCounter; // Contador interno
Uint8 mR, mG, mB; // Colores para el fade bool mEnabled; // Indica si el fade está activo
SDL_Rect mRect1; // Rectangulo usado para crear los efectos de transición bool mFinished; // Indica si ha terminado la transición
SDL_Rect mRect2; // Rectangulo usado para crear los efectos de transición Uint8 mR, mG, mB; // Colores para el fade
SDL_Rect mRect1; // Rectangulo usado para crear los efectos de transición
SDL_Rect mRect2; // Rectangulo usado para crear los efectos de transición
param_t *param; // Puntero con todos los parametros del programa
public: public:
// Constructor // Constructor
Fade(SDL_Renderer *renderer); Fade(SDL_Renderer *renderer, param_t *param);
// Destructor // Destructor
~Fade(); ~Fade();

View File

@@ -1,7 +1,7 @@
#include "game.h" #include "game.h"
// Constructor // Constructor
Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, options_t *options, section_t *section) Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, param_t *param, options_t *options, section_t *section)
{ {
// Copia los punteros // Copia los punteros
this->renderer = renderer; this->renderer = renderer;
@@ -9,6 +9,7 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr
this->asset = asset; this->asset = asset;
this->lang = lang; this->lang = lang;
this->input = input; this->input = input;
this->param = param;
this->options = options; this->options = options;
this->section = section; this->section = section;
@@ -25,10 +26,10 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr
difficulty = options->difficulty; difficulty = options->difficulty;
// Crea los objetos // Crea los objetos
fade = new Fade(renderer); fade = new Fade(renderer, param);
eventHandler = new SDL_Event(); eventHandler = new SDL_Event();
scoreboard = new Scoreboard(renderer, screen, asset, lang, options); scoreboard = new Scoreboard(renderer, screen, asset, lang, options);
background = new Background(renderer, screen, asset); background = new Background(renderer, screen, asset, param);
// Carga los recursos // Carga los recursos
loadMedia(); loadMedia();

View File

@@ -211,7 +211,8 @@ private:
Uint8 difficulty; // Dificultad del juego Uint8 difficulty; // Dificultad del juego
float difficultyScoreMultiplier; // Multiplicador de puntos en función de la dificultad float difficultyScoreMultiplier; // Multiplicador de puntos en función de la dificultad
color_t difficultyColor; // Color asociado a la dificultad color_t difficultyColor; // Color asociado a la dificultad
struct options_t *options; // Variable con todas las variables de las opciones del programa options_t *options; // Variable con todas las opciones del programa
param_t *param; // Puntero con todos los parametros del programa
Uint8 onePlayerControl; // Variable para almacenar el valor de las opciones Uint8 onePlayerControl; // Variable para almacenar el valor de las opciones
enemyFormation_t enemyFormation[NUMBER_OF_ENEMY_FORMATIONS]; // Vector con todas las formaciones enemigas enemyFormation_t enemyFormation[NUMBER_OF_ENEMY_FORMATIONS]; // Vector con todas las formaciones enemigas
enemyPool_t enemyPool[10]; // Variable con los diferentes conjuntos de formaciones enemigas enemyPool_t enemyPool[10]; // Variable con los diferentes conjuntos de formaciones enemigas
@@ -487,7 +488,7 @@ private:
public: public:
// Constructor // Constructor
Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, options_t *options, section_t *section); Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, param_t *param, options_t *options, section_t *section);
// Destructor // Destructor
~Game(); ~Game();

View File

@@ -1,12 +1,13 @@
#include "game_logo.h" #include "game_logo.h"
// Constructor // Constructor
GameLogo::GameLogo(SDL_Renderer *renderer, Screen *screen, Asset *asset, int x, int y) GameLogo::GameLogo(SDL_Renderer *renderer, Screen *screen, Asset *asset, param_t *param, int x, int y)
{ {
// Copia los punteros // Copia los punteros
this->renderer = renderer; this->renderer = renderer;
this->screen = screen; this->screen = screen;
this->asset = asset; this->asset = asset;
this->param = param;
this->x = x; this->x = x;
this->y = y; this->y = y;
@@ -203,7 +204,7 @@ void GameLogo::reLoad()
int GameLogo::getInitialVerticalDesp() int GameLogo::getInitialVerticalDesp()
{ {
int despUp = y; int despUp = y;
int despDown = GAMECANVAS_HEIGHT - y; int despDown = param->gameHeight - y;
return std::max(despUp, despDown); return std::max(despUp, despDown);
} }

View File

@@ -29,10 +29,12 @@ private:
SmartSprite *coffeeBitmap; // Sprite con la palabra COFFEE para la pantalla de titulo SmartSprite *coffeeBitmap; // Sprite con la palabra COFFEE para la pantalla de titulo
SmartSprite *crisisBitmap; // Sprite con la palabra CRISIS para la pantalla de titulo SmartSprite *crisisBitmap; // Sprite con la palabra CRISIS para la pantalla de titulo
// Variables
int x; // Posición donde ddibujar a la clase
int y; // Posición donde ddibujar a la clase
JA_Sound_t *crashSound; // Sonido con el impacto del título JA_Sound_t *crashSound; // Sonido con el impacto del título
param_t *param; // Puntero con todos los parametros del programa
// Variables
int x; // Posición donde dibujar el logo
int y; // Posición donde dibujar el logo
enum status_e enum status_e
{ {
@@ -50,7 +52,7 @@ private:
int lenght; // Cantidad de desplazamientos a realizar int lenght; // Cantidad de desplazamientos a realizar
int remaining; // Cantidad de desplazamientos pendientes a realizar int remaining; // Cantidad de desplazamientos pendientes a realizar
int origin; // Valor inicial de la pantalla para dejarla igual tras el desplazamiento int origin; // Valor inicial de la pantalla para dejarla igual tras el desplazamiento
} shake; // Estructura para generar el efecto de agitación } shake; // Estructura para generar el efecto de agitación
// Inicializa las variables // Inicializa las variables
void init(); void init();
@@ -60,7 +62,7 @@ private:
public: public:
// Constructor // Constructor
GameLogo(SDL_Renderer *renderer, Screen *screen, Asset *asset, int x, int y); GameLogo(SDL_Renderer *renderer, Screen *screen, Asset *asset, param_t *param, int x, int y);
// Destructor // Destructor
~GameLogo(); ~GameLogo();

View File

@@ -4,7 +4,7 @@
const Uint8 SELF = 0; const Uint8 SELF = 0;
// Constructor // Constructor
HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, section_t *section) HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, options_t *options, section_t *section)
{ {
// Copia los punteros // Copia los punteros
this->renderer = renderer; this->renderer = renderer;
@@ -14,6 +14,7 @@ HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset,
this->lang = lang; this->lang = lang;
this->section = section; this->section = section;
this->options = options; this->options = options;
this->param = param;
// Reserva memoria para los punteros // Reserva memoria para los punteros
eventHandler = new SDL_Event(); eventHandler = new SDL_Event();
@@ -21,14 +22,7 @@ HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset,
text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer); text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
// Crea un backbuffer para el renderizador // Crea un backbuffer para el renderizador
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->gameWidth, param->gameHeight);
if (backbuffer == nullptr)
{
if (options->console)
{
std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
// Inicializa variables // Inicializa variables
section->name = SELF; section->name = SELF;
@@ -90,7 +84,7 @@ void HiScoreTable::update()
void HiScoreTable::render() void HiScoreTable::render()
{ {
// Pinta en pantalla // Pinta en pantalla
SDL_Rect window = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT}; SDL_Rect window = {0, 0, param->gameWidth, param->gameHeight};
const color_t orangeColor = {0xFF, 0x7A, 0x00}; const color_t orangeColor = {0xFF, 0x7A, 0x00};
// hay 27 letras - 7 de puntos quedan 20 caracteres 20 - nameLenght 0 numDots // hay 27 letras - 7 de puntos quedan 20 caracteres 20 - nameLenght 0 numDots
@@ -121,11 +115,10 @@ void HiScoreTable::render()
const std::string line = names[i] + dots + "0000000"; const std::string line = names[i] + dots + "0000000";
text->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, (i * spaceBetweenLines) + spaceBetweenHeader, line, 1, orangeColor, 1, shdwTxtColor); text->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, (i * spaceBetweenLines) + spaceBetweenHeader, line, 1, orangeColor, 1, shdwTxtColor);
} }
if ((mode == mhst_manual) && (counter % 50 > 14)) if ((mode == mhst_manual) && (counter % 50 > 14))
{ {
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, GAMECANVAS_HEIGHT - 12, lang->getText(22), 1, orangeColor, 1, shdwTxtColor); text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, param->gameHeight - 12, lang->getText(22), 1, orangeColor, 1, shdwTxtColor);
} }
// Cambia el destino de renderizado // Cambia el destino de renderizado
@@ -140,7 +133,7 @@ void HiScoreTable::render()
// Establece la ventana del backbuffer // Establece la ventana del backbuffer
if (mode == mhst_auto) if (mode == mhst_auto)
{ {
window.y = std::max(8, GAMECANVAS_HEIGHT - counter + 100); window.y = std::max(8, param->gameHeight - counter + 100);
} }
else else
{ {

View File

@@ -42,6 +42,7 @@ private:
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
bool manualQuit; // Indica si se quiere salir del modo manual bool manualQuit; // Indica si se quiere salir del modo manual
mode_hiScoreTable_e mode; // Modo en el que se van a ejecutar las instrucciones mode_hiScoreTable_e mode; // Modo en el que se van a ejecutar las instrucciones
param_t *param; // Puntero con todos los parametros del programa
// Actualiza las variables // Actualiza las variables
void update(); void update();
@@ -60,7 +61,7 @@ private:
public: public:
// Constructor // Constructor
HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, section_t *section); HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, options_t *options, section_t *section);
// Destructor // Destructor
~HiScoreTable(); ~HiScoreTable();

View File

@@ -4,7 +4,7 @@
const Uint8 SELF = 0; const Uint8 SELF = 0;
// Constructor // Constructor
Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section) Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section)
{ {
// Copia los punteros // Copia los punteros
this->renderer = renderer; this->renderer = renderer;
@@ -12,6 +12,7 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset,
this->asset = asset; this->asset = asset;
this->input = input; this->input = input;
this->lang = lang; this->lang = lang;
this->param = param;
this->section = section; this->section = section;
// Reserva memoria para los punteros // Reserva memoria para los punteros
@@ -39,7 +40,7 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset,
text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer); text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
// Crea un backbuffer para el renderizador // Crea un backbuffer para el renderizador
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->gameWidth, param->gameHeight);
if (backbuffer == nullptr) if (backbuffer == nullptr)
{ {
std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl; std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
@@ -110,7 +111,7 @@ void Instructions::update()
void Instructions::render() void Instructions::render()
{ {
// Pinta en pantalla // Pinta en pantalla
SDL_Rect window = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT}; SDL_Rect window = {0, 0, param->gameWidth, param->gameHeight};
SDL_Rect srcRect = {0, 0, 16, 16}; SDL_Rect srcRect = {0, 0, 16, 16};
const color_t orangeColor = {0xFF, 0x7A, 0x00}; const color_t orangeColor = {0xFF, 0x7A, 0x00};
@@ -142,7 +143,7 @@ void Instructions::render()
if ((mode == m_manual) && (counter % 50 > 14)) if ((mode == m_manual) && (counter % 50 > 14))
{ {
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, GAMECANVAS_HEIGHT - 12, lang->getText(22), 1, orangeColor, 1, shdwTxtColor); text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, param->gameHeight - 12, lang->getText(22), 1, orangeColor, 1, shdwTxtColor);
} }
// Disquito // Disquito
@@ -192,7 +193,7 @@ void Instructions::render()
// Establece la ventana del backbuffer // Establece la ventana del backbuffer
if (mode == m_auto) if (mode == m_auto)
{ {
window.y = std::max(8, GAMECANVAS_HEIGHT - counter + 100); window.y = std::max(8, param->gameHeight - counter + 100);
} }
else else
{ {

View File

@@ -36,6 +36,7 @@ private:
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
Text *text; // Objeto para escribir texto Text *text; // Objeto para escribir texto
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
param_t *param; // Puntero con todos los parametros del programa
// Variables // Variables
Uint16 counter; // Contador Uint16 counter; // Contador
@@ -59,7 +60,7 @@ private:
public: public:
// Constructor // Constructor
Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section); Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section);
// Destructor // Destructor
~Instructions(); ~Instructions();

View File

@@ -1,7 +1,7 @@
#include "intro.h" #include "intro.h"
// Constructor // Constructor
Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section) Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section)
{ {
// Copia los punteros // Copia los punteros
this->renderer = renderer; this->renderer = renderer;
@@ -9,6 +9,7 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input,
this->lang = lang; this->lang = lang;
this->asset = asset; this->asset = asset;
this->input = input; this->input = input;
this->param = param;
this->section = section; this->section = section;
// Reserva memoria para los objetos // Reserva memoria para los objetos
@@ -47,7 +48,7 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input,
bitmaps[0]->setAccelY(0.0f); bitmaps[0]->setAccelY(0.0f);
bitmaps[0]->setSpriteClip(0, 0, 128, 96); bitmaps[0]->setSpriteClip(0, 0, 128, 96);
bitmaps[1]->setPosX(GAMECANVAS_WIDTH); bitmaps[1]->setPosX(param->gameWidth);
bitmaps[1]->setPosY(GAMECANVAS_FIRST_QUARTER_Y - 24); bitmaps[1]->setPosY(GAMECANVAS_FIRST_QUARTER_Y - 24);
bitmaps[1]->setVelX(-1.0f); bitmaps[1]->setVelX(-1.0f);
bitmaps[1]->setVelY(0.0f); bitmaps[1]->setVelY(0.0f);
@@ -65,7 +66,7 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input,
bitmaps[2]->setEnabledCounter(250); bitmaps[2]->setEnabledCounter(250);
bitmaps[3]->setPosX(GAMECANVAS_CENTER_X - 64); bitmaps[3]->setPosX(GAMECANVAS_CENTER_X - 64);
bitmaps[3]->setPosY(GAMECANVAS_HEIGHT); bitmaps[3]->setPosY(param->gameHeight);
bitmaps[3]->setVelX(0.0f); bitmaps[3]->setVelX(0.0f);
bitmaps[3]->setVelY(-0.7f); bitmaps[3]->setVelY(-0.7f);
bitmaps[3]->setAccelX(0.0f); bitmaps[3]->setAccelX(0.0f);
@@ -80,7 +81,7 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input,
bitmaps[4]->setAccelY(0.3f); bitmaps[4]->setAccelY(0.3f);
bitmaps[4]->setSpriteClip(0, 192, 128, 96); bitmaps[4]->setSpriteClip(0, 192, 128, 96);
bitmaps[5]->setPosX(GAMECANVAS_WIDTH); bitmaps[5]->setPosX(param->gameWidth);
bitmaps[5]->setPosY(GAMECANVAS_FIRST_QUARTER_Y - 24); bitmaps[5]->setPosY(GAMECANVAS_FIRST_QUARTER_Y - 24);
bitmaps[5]->setVelX(-0.7f); bitmaps[5]->setVelX(-0.7f);
bitmaps[5]->setVelY(0.0f); bitmaps[5]->setVelY(0.0f);
@@ -94,7 +95,7 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input,
{ {
Writer *w = new Writer(text); Writer *w = new Writer(text);
w->setPosX(BLOCK * 0); w->setPosX(BLOCK * 0);
w->setPosY(GAMECANVAS_HEIGHT - (BLOCK * 6)); w->setPosY(param->gameHeight - (BLOCK * 6));
w->setKerning(-1); w->setKerning(-1);
w->setEnabled(false); w->setEnabled(false);
w->setEnabledCounter(180); w->setEnabledCounter(180);

View File

@@ -31,6 +31,7 @@ private:
std::vector<Writer *> texts; // Textos de la intro std::vector<Writer *> texts; // Textos de la intro
Text *text; // Textos de la intro Text *text; // Textos de la intro
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
param_t *param; // Puntero con todos los parametros del programa
// Variables // Variables
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
@@ -58,7 +59,7 @@ private:
public: public:
// Constructor // Constructor
Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section); Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section);
// Destructor // Destructor
~Intro(); ~Intro();

View File

@@ -2,20 +2,21 @@
#include <iostream> #include <iostream>
// Constructor // Constructor
Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, section_t *section) Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, param_t *param, section_t *section)
{ {
// Copia la dirección de los objetos // Copia la dirección de los objetos
this->renderer = renderer; this->renderer = renderer;
this->screen = screen; this->screen = screen;
this->asset = asset; this->asset = asset;
this->input = input; this->input = input;
this->param = param;
this->section = section; this->section = section;
// Reserva memoria para los punteros // Reserva memoria para los punteros
eventHandler = new SDL_Event(); eventHandler = new SDL_Event();
jailTexture = new Texture(renderer, asset->get("logo_jailgames.png")); jailTexture = new Texture(renderer, asset->get("logo_jailgames.png"));
sinceTexture = new Texture(renderer, asset->get("logo_since_1998.png")); sinceTexture = new Texture(renderer, asset->get("logo_since_1998.png"));
sinceSprite = new Sprite((GAMECANVAS_WIDTH - sinceTexture->getWidth()) / 2, 83 + jailTexture->getHeight() + 5, sinceTexture->getWidth(), sinceTexture->getHeight(), sinceTexture, renderer); sinceSprite = new Sprite((param->gameWidth - sinceTexture->getWidth()) / 2, 83 + jailTexture->getHeight() + 5, sinceTexture->getWidth(), sinceTexture->getHeight(), sinceTexture, renderer);
sinceSprite->setSpriteClip(0, 0, sinceTexture->getWidth(), sinceTexture->getHeight()); sinceSprite->setSpriteClip(0, 0, sinceTexture->getWidth(), sinceTexture->getHeight());
sinceTexture->setColor(0, 0, 0); sinceTexture->setColor(0, 0, 0);
@@ -37,7 +38,7 @@ Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, s
{ {
Sprite *temp = new Sprite(0, i, jailTexture->getWidth(), 1, jailTexture, renderer); Sprite *temp = new Sprite(0, i, jailTexture->getWidth(), 1, jailTexture, renderer);
temp->setSpriteClip(0, i, jailTexture->getWidth(), 1); temp->setSpriteClip(0, i, jailTexture->getWidth(), 1);
const int posX = (i % 2 == 0) ? GAMECANVAS_WIDTH + (i * 3) : -jailTexture->getWidth() - (i * 3); const int posX = (i % 2 == 0) ? param->gameWidth + (i * 3) : -jailTexture->getWidth() - (i * 3);
temp->setPosX(posX); temp->setPosX(posX);
temp->setPosY(dest.y + i); temp->setPosY(dest.y + i);
jailSprite.push_back(temp); jailSprite.push_back(temp);

View File

@@ -27,6 +27,7 @@ private:
std::vector<Sprite *> jailSprite; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES std::vector<Sprite *> jailSprite; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
Sprite *sinceSprite; // Sprite para manejar la sinceTexture Sprite *sinceSprite; // Sprite para manejar la sinceTexture
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
param_t *param; // Puntero con todos los parametros del programa
// Variables // Variables
std::vector<color_t> color; // Vector con los colores para el fade std::vector<color_t> color; // Vector con los colores para el fade
@@ -59,7 +60,7 @@ private:
public: public:
// Constructor // Constructor
Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, section_t *section); Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, param_t *param, section_t *section);
// Destructor // Destructor
~Logo(); ~Logo();

View File

@@ -1,7 +1,7 @@
#include "title.h" #include "title.h"
// Constructor // Constructor
Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t *section) Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, param_t *param, section_t *section)
{ {
// Copia las direcciones de los punteros y objetos // Copia las direcciones de los punteros y objetos
this->renderer = renderer; this->renderer = renderer;
@@ -10,11 +10,12 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset,
this->asset = asset; this->asset = asset;
this->options = options; this->options = options;
this->lang = lang; this->lang = lang;
this->param = param;
this->section = section; this->section = section;
// Reserva memoria y crea los objetos // Reserva memoria y crea los objetos
eventHandler = new SDL_Event(); eventHandler = new SDL_Event();
fade = new Fade(renderer); fade = new Fade(renderer, param);
text1 = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer); text1 = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
text2 = new Text(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer); text2 = new Text(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer);
@@ -22,7 +23,7 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset,
miniLogoTexture = new Texture(renderer, asset->get("logo_jailgames_mini.png")); miniLogoTexture = new Texture(renderer, asset->get("logo_jailgames_mini.png"));
miniLogoSprite = new Sprite(GAMECANVAS_CENTER_X - miniLogoTexture->getWidth() / 2, 0, miniLogoTexture->getWidth(), miniLogoTexture->getHeight(), miniLogoTexture, renderer); miniLogoSprite = new Sprite(GAMECANVAS_CENTER_X - miniLogoTexture->getWidth() / 2, 0, miniLogoTexture->getWidth(), miniLogoTexture->getHeight(), miniLogoTexture, renderer);
backgroundObj = new Background(renderer, screen, asset); backgroundObj = new Background(renderer, screen, asset, param);
backgroundObj->setSrcDest(windowArea); backgroundObj->setSrcDest(windowArea);
backgroundObj->setDstDest(windowArea); backgroundObj->setDstDest(windowArea);
backgroundObj->setCloudsSpeed(-0.5f); backgroundObj->setCloudsSpeed(-0.5f);
@@ -31,7 +32,7 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset,
tiledbg = new Tiledbg(renderer, screen, asset, {0, 0, param->gameWidth, param->gameHeight}); tiledbg = new Tiledbg(renderer, screen, asset, {0, 0, param->gameWidth, param->gameHeight});
gameLogo = new GameLogo(renderer, screen, asset, GAMECANVAS_CENTER_X, GAMECANVAS_FIRST_QUARTER_Y + 20); gameLogo = new GameLogo(renderer, screen, asset, param, GAMECANVAS_CENTER_X, GAMECANVAS_FIRST_QUARTER_Y + 20);
gameLogo->enable(); gameLogo->enable();
// Musicas // Musicas
@@ -355,7 +356,7 @@ void Title::run()
// Ejecuta la parte donde se muestran las instrucciones // Ejecuta la parte donde se muestran las instrucciones
void Title::runInstructions(mode_e mode) void Title::runInstructions(mode_e mode)
{ {
instructions = new Instructions(renderer, screen, asset, input, lang, section); instructions = new Instructions(renderer, screen, asset, input, lang, param, section);
instructions->run(mode); instructions->run(mode);
delete instructions; delete instructions;
} }
@@ -363,7 +364,7 @@ void Title::runInstructions(mode_e mode)
// Ejecuta la parte donde se muestra la tabla de puntuaciones // Ejecuta la parte donde se muestra la tabla de puntuaciones
void Title::runHiScoreTable(mode_hiScoreTable_e mode) void Title::runHiScoreTable(mode_hiScoreTable_e mode)
{ {
hiScoreTable = new HiScoreTable(renderer, screen, asset, input, lang, options, section); hiScoreTable = new HiScoreTable(renderer, screen, asset, input, lang, param, options, section);
hiScoreTable->run(mode); hiScoreTable->run(mode);
delete hiScoreTable; delete hiScoreTable;
} }
@@ -371,7 +372,7 @@ void Title::runHiScoreTable(mode_hiScoreTable_e mode)
// Ejecuta el juego en modo demo // Ejecuta el juego en modo demo
void Title::runDemoGame() void Title::runDemoGame()
{ {
demoGame = new Game(1, 0, renderer, screen, asset, lang, input, true, options, section); demoGame = new Game(1, 0, renderer, screen, asset, lang, input, true, param, options, section);
demoGame->run(); demoGame->run();
delete demoGame; delete demoGame;
} }

View File

@@ -58,15 +58,17 @@ private:
Text *text2; // Objeto de texto para poder escribir textos en pantalla Text *text2; // Objeto de texto para poder escribir textos en pantalla
Fade *fade; // Objeto para realizar fundidos en pantalla Fade *fade; // Objeto para realizar fundidos en pantalla
JA_Music_t *titleMusic; // Musica para el titulo
// Variable // Variable
JA_Music_t *titleMusic; // Musica para el titulo
int counter; // Temporizador para la pantalla de titulo int counter; // Temporizador para la pantalla de titulo
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
bool demo; // Indica si el modo demo estará activo bool demo; // Indica si el modo demo estará activo
section_t nextSection; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo section_t nextSection; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
Uint8 postFade; // Opción a realizar cuando termina el fundido Uint8 postFade; // Opción a realizar cuando termina el fundido
struct options_t *options; // Variable con todas las variables de las opciones del programa options_t *options; // Variable con todas las variables de las opciones del programa
param_t *param; // Puntero con todos los parametros del programa
options_t optionsPrevious; // Variable de respaldo para las opciones options_t optionsPrevious; // Variable de respaldo para las opciones
std::vector<input_t> availableInputDevices; // Vector con todos los metodos de control disponibles std::vector<input_t> availableInputDevices; // Vector con todos los metodos de control disponibles
std::vector<int> deviceIndex; // Indice para el jugador [i] del vector de dispositivos de entrada disponibles std::vector<int> deviceIndex; // Indice para el jugador [i] del vector de dispositivos de entrada disponibles
@@ -109,7 +111,7 @@ private:
public: public:
// Constructor // Constructor
Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t *section); Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, param_t *param, section_t *section);
// Destructor // Destructor
~Title(); ~Title();