Eliminada gran cantidad de código sobrante

This commit is contained in:
2024-05-31 17:27:46 +02:00
parent 514372c9f0
commit d13e4daf25
9 changed files with 122 additions and 614 deletions

1
.gitignore vendored
View File

@@ -9,6 +9,7 @@ thumbs.db
*.tar.gz *.tar.gz
*.zip *.zip
*.app *.app
*.dll
*config.bin *config.bin
*score.bin *score.bin
coffee_crisis* coffee_crisis*

View File

@@ -165,11 +165,11 @@ void Notify::showText(std::string text1, std::string text2, int icon)
} }
else if (options->notifications.posH == pos_middle) else if (options->notifications.posH == pos_middle)
{ {
despH = ((options->screen.windowWidth * options->windowSize) / 2 - (width / 2)); despH = ((options->video.windowWidth * options->video.windowSize) / 2 - (width / 2));
} }
else else
{ {
despH = (options->screen.windowWidth * options->windowSize) - width - padding; despH = (options->video.windowWidth * options->video.windowSize) - width - padding;
} }
// Posición vertical // Posición vertical
@@ -180,7 +180,7 @@ void Notify::showText(std::string text1, std::string text2, int icon)
} }
else else
{ {
despV = (options->screen.windowHeight * options->windowSize) - height - padding; despV = (options->video.windowHeight * options->video.windowSize) - height - padding;
} }
const int travelDist = height + padding; const int travelDist = height + padding;

View File

@@ -14,31 +14,23 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
// Crea los objetos // Crea los objetos
notify = new Notify(renderer, asset->get("notify.png"), asset->get("smb2.png"), asset->get("smb2.txt"), asset->get("notify.wav"), options); notify = new Notify(renderer, asset->get("notify.png"), asset->get("smb2.png"), asset->get("smb2.txt"), asset->get("notify.wav"), options);
gameCanvasWidth = options->gameWidth; gameCanvasWidth = options->video.gameWidth;
gameCanvasHeight = options->gameHeight; gameCanvasHeight = options->video.gameHeight;
borderWidth = options->borderWidth * 2; borderWidth = options->video.borderWidth * 2;
borderHeight = options->borderHeight * 2; borderHeight = options->video.borderHeight * 2;
notificationLogicalWidth = gameCanvasWidth; notificationLogicalWidth = gameCanvasWidth;
notificationLogicalHeight = gameCanvasHeight; notificationLogicalHeight = gameCanvasHeight;
iniFade(); iniFade();
iniSpectrumFade();
// Define el color del borde para el modo de pantalla completa // Define el color del borde para el modo de pantalla completa
borderColor = {0x00, 0x00, 0x00}; borderColor = {0x00, 0x00, 0x00};
// Crea la textura donde se dibujan los graficos del juego // Crea la textura donde se dibujan los graficos del juego
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight); gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
if (gameCanvas == nullptr)
{
if (options->console)
{
std::cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
// Establece el modo de video // Establece el modo de video
setVideoMode(options->videoMode); setVideoMode(options->video.mode);
// Inicializa variables // Inicializa variables
notifyActive = false; notifyActive = false;
@@ -99,7 +91,7 @@ void Screen::setVideoMode(int videoMode)
// Esconde la ventana // Esconde la ventana
//SDL_HideWindow(window); //SDL_HideWindow(window);
if (options->borderEnabled) if (options->video.borderEnabled)
{ {
windowWidth = gameCanvasWidth + borderWidth; windowWidth = gameCanvasWidth + borderWidth;
windowHeight = gameCanvasHeight + borderHeight; windowHeight = gameCanvasHeight + borderHeight;
@@ -114,7 +106,7 @@ void Screen::setVideoMode(int videoMode)
} }
// Modifica el tamaño de la ventana // Modifica el tamaño de la ventana
SDL_SetWindowSize(window, windowWidth * options->windowSize, windowHeight * options->windowSize); SDL_SetWindowSize(window, windowWidth * options->video.windowSize, windowHeight * options->video.windowSize);
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
// Muestra la ventana // Muestra la ventana
@@ -131,7 +123,7 @@ void Screen::setVideoMode(int videoMode)
SDL_GetWindowSize(window, &windowWidth, &windowHeight); SDL_GetWindowSize(window, &windowWidth, &windowHeight);
// Aplica el escalado al rectangulo donde se pinta la textura del juego // Aplica el escalado al rectangulo donde se pinta la textura del juego
if (options->integerScale) if (options->video.integerScale)
{ {
// Calcula el tamaño de la escala máxima // Calcula el tamaño de la escala máxima
int scale = 0; int scale = 0;
@@ -145,7 +137,7 @@ void Screen::setVideoMode(int videoMode)
dest.x = (windowWidth - dest.w) / 2; dest.x = (windowWidth - dest.w) / 2;
dest.y = (windowHeight - dest.h) / 2; dest.y = (windowHeight - dest.h) / 2;
} }
else if (options->keepAspect) else if (options->video.keepAspect)
{ {
float ratio = (float)gameCanvasWidth / (float)gameCanvasHeight; float ratio = (float)gameCanvasWidth / (float)gameCanvasHeight;
if ((windowWidth - gameCanvasWidth) >= (windowHeight - gameCanvasHeight)) if ((windowWidth - gameCanvasWidth) >= (windowHeight - gameCanvasHeight))
@@ -175,9 +167,9 @@ void Screen::setVideoMode(int videoMode)
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight); SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
// Actualiza las opciones // Actualiza las opciones
options->videoMode = videoMode; options->video.mode = videoMode;
options->screen.windowWidth = windowWidth; options->video.windowWidth = windowWidth;
options->screen.windowHeight = windowHeight; options->video.windowHeight = windowHeight;
// Establece el tamaño de las notificaciones // Establece el tamaño de las notificaciones
setNotificationSize(); setNotificationSize();
@@ -186,30 +178,30 @@ void Screen::setVideoMode(int videoMode)
// Camibia entre pantalla completa y ventana // Camibia entre pantalla completa y ventana
void Screen::switchVideoMode() void Screen::switchVideoMode()
{ {
options->videoMode = (options->videoMode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0; options->video.mode = (options->video.mode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
setVideoMode(options->videoMode); setVideoMode(options->video.mode);
} }
// Cambia el tamaño de la ventana // Cambia el tamaño de la ventana
void Screen::setWindowSize(int size) void Screen::setWindowSize(int size)
{ {
options->windowSize = size; options->video.windowSize = size;
setVideoMode(0); setVideoMode(0);
} }
// Reduce el tamaño de la ventana // Reduce el tamaño de la ventana
void Screen::decWindowSize() void Screen::decWindowSize()
{ {
--options->windowSize; --options->video.windowSize;
options->windowSize = std::max(options->windowSize, 1); options->video.windowSize = std::max(options->video.windowSize, 1);
setVideoMode(0); setVideoMode(0);
} }
// Aumenta el tamaño de la ventana // Aumenta el tamaño de la ventana
void Screen::incWindowSize() void Screen::incWindowSize()
{ {
++options->windowSize; ++options->video.windowSize;
options->windowSize = std::min(options->windowSize, 4); options->video.windowSize = std::min(options->video.windowSize, 4);
setVideoMode(0); setVideoMode(0);
} }
@@ -228,25 +220,25 @@ void Screen::setBlendMode(SDL_BlendMode blendMode)
// Establece el tamaño del borde // Establece el tamaño del borde
void Screen::setBorderWidth(int s) void Screen::setBorderWidth(int s)
{ {
options->borderWidth = s; options->video.borderWidth = s;
} }
// Establece el tamaño del borde // Establece el tamaño del borde
void Screen::setBorderHeight(int s) void Screen::setBorderHeight(int s)
{ {
options->borderHeight = s; options->video.borderHeight = s;
} }
// Establece si se ha de ver el borde en el modo ventana // Establece si se ha de ver el borde en el modo ventana
void Screen::setBorderEnabled(bool value) void Screen::setBorderEnabled(bool value)
{ {
options->borderEnabled = value; options->video.borderEnabled = value;
} }
// Cambia entre borde visible y no visible // Cambia entre borde visible y no visible
void Screen::switchBorder() void Screen::switchBorder()
{ {
options->borderEnabled = !options->borderEnabled; options->video.borderEnabled = !options->video.borderEnabled;
setVideoMode(0); setVideoMode(0);
} }
@@ -323,66 +315,16 @@ void Screen::renderFade()
SDL_RenderFillRect(renderer, &rect); SDL_RenderFillRect(renderer, &rect);
} }
// Inicializa las variables para el fade spectrum
void Screen::iniSpectrumFade()
{
spectrumFade = false;
spectrumFadeCounter = 0;
spectrumFadeLenght = 50;
spectrumColor.clear();
// Inicializa el vector de colores
const std::vector<std::string> vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"};
for (auto v : vColors)
{
spectrumColor.push_back(stringToColor(options->palette, v));
}
}
// Actualiza el spectrum fade
void Screen::updateSpectrumFade()
{
if (!spectrumFade)
{
return;
}
spectrumFadeCounter++;
if (spectrumFadeCounter > spectrumFadeLenght)
{
iniSpectrumFade();
SDL_SetTextureColorMod(gameCanvas, 255, 255, 255);
}
}
// Dibuja el spectrum fade
void Screen::renderSpectrumFade()
{
if (!spectrumFade)
{
return;
}
const float step = (float)spectrumFadeCounter / (float)spectrumFadeLenght;
const int max = spectrumColor.size() - 1;
const int index = max + (0 - max) * step;
const color_t c = spectrumColor[index];
SDL_SetTextureColorMod(gameCanvas, c.r, c.g, c.b);
}
// Actualiza los efectos // Actualiza los efectos
void Screen::updateFX() void Screen::updateFX()
{ {
updateFade(); updateFade();
updateSpectrumFade();
} }
// Dibuja los efectos // Dibuja los efectos
void Screen::renderFX() void Screen::renderFX()
{ {
renderFade(); renderFade();
renderSpectrumFade();
} }
// Actualiza el notificador // Actualiza el notificador
@@ -414,9 +356,9 @@ void Screen::renderNotifications()
// Establece el tamaño de las notificaciones // Establece el tamaño de las notificaciones
void Screen::setNotificationSize() void Screen::setNotificationSize()
{ {
if (options->videoMode == 0) if (options->video.mode == 0)
{ {
if (options->windowSize == 3) if (options->video.windowSize == 3)
{ {
notificationLogicalWidth = (windowWidth * 3) / 2; notificationLogicalWidth = (windowWidth * 3) / 2;
notificationLogicalHeight = (windowHeight * 3) / 2; notificationLogicalHeight = (windowHeight * 3) / 2;
@@ -428,7 +370,7 @@ void Screen::setNotificationSize()
} }
} }
if (options->videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP) if (options->video.mode == SDL_WINDOW_FULLSCREEN_DESKTOP)
{ {
notificationLogicalWidth = windowWidth / 3; notificationLogicalWidth = windowWidth / 3;
notificationLogicalHeight = windowHeight / 3; notificationLogicalHeight = windowHeight / 3;

View File

@@ -55,15 +55,6 @@ private:
// Dibuja el fade // Dibuja el fade
void renderFade(); void renderFade();
// Inicializa las variables para el fade spectrum
void iniSpectrumFade();
// Actualiza el spectrum fade
void updateSpectrumFade();
// Dibuja el spectrum fade
void renderSpectrumFade();
// Dibuja las notificaciones // Dibuja las notificaciones
void renderNotifications(); void renderNotifications();

View File

@@ -143,413 +143,6 @@ bool checkCollision(SDL_Point &p, SDL_Rect &r)
return true; return true;
} }
// Detector de colisiones entre una linea horizontal y un rectangulo
bool checkCollision(h_line_t &l, SDL_Rect &r)
{
// Comprueba si la linea esta por encima del rectangulo
if (l.y < r.y)
{
return false;
}
// Comprueba si la linea esta por debajo del rectangulo
if (l.y >= r.y + r.h)
{
return false;
}
// Comprueba si el inicio de la linea esta a la derecha del rectangulo
if (l.x1 >= r.x + r.w)
{
return false;
}
// Comprueba si el final de la linea esta a la izquierda del rectangulo
if (l.x2 < r.x)
{
return false;
}
// Si ha llegado hasta aquí, hay colisión
return true;
}
// Detector de colisiones entre una linea vertical y un rectangulo
bool checkCollision(v_line_t &l, SDL_Rect &r)
{
// Comprueba si la linea esta por la izquierda del rectangulo
if (l.x < r.x)
{
return false;
}
// Comprueba si la linea esta por la derecha del rectangulo
if (l.x >= r.x + r.w)
{
return false;
}
// Comprueba si el inicio de la linea esta debajo del rectangulo
if (l.y1 >= r.y + r.h)
{
return false;
}
// Comprueba si el final de la linea esta encima del rectangulo
if (l.y2 < r.y)
{
return false;
}
// Si ha llegado hasta aquí, hay colisión
return true;
}
// Detector de colisiones entre una linea horizontal y un punto
bool checkCollision(h_line_t &l, SDL_Point &p)
{
// Comprueba si el punto esta sobre la linea
if (p.y > l.y)
{
return false;
}
// Comprueba si el punto esta bajo la linea
if (p.y < l.y)
{
return false;
}
// Comprueba si el punto esta a la izquierda de la linea
if (p.x < l.x1)
{
return false;
}
// Comprueba si el punto esta a la derecha de la linea
if (p.x > l.x2)
{
return false;
}
// Si ha llegado aquí, hay colisión
return true;
}
// Detector de colisiones entre dos lineas
SDL_Point checkCollision(line_t &l1, line_t &l2)
{
const float x1 = l1.x1;
const float y1 = l1.y1;
const float x2 = l1.x2;
const float y2 = l1.y2;
const float x3 = l2.x1;
const float y3 = l2.y1;
const float x4 = l2.x2;
const float y4 = l2.y2;
// calculate the direction of the lines
float uA = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / ((y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1));
float uB = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3)) / ((y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1));
// if uA and uB are between 0-1, lines are colliding
if (uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1)
{
// Calcula la intersección
const float x = x1 + (uA * (x2 - x1));
const float y = y1 + (uA * (y2 - y1));
return {(int)round(x), (int)round(y)};
}
return {-1, -1};
}
// Detector de colisiones entre dos lineas
SDL_Point checkCollision(d_line_t &l1, v_line_t &l2)
{
const float x1 = l1.x1;
const float y1 = l1.y1;
const float x2 = l1.x2;
const float y2 = l1.y2;
const float x3 = l2.x;
const float y3 = l2.y1;
const float x4 = l2.x;
const float y4 = l2.y2;
// calculate the direction of the lines
float uA = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / ((y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1));
float uB = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3)) / ((y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1));
// if uA and uB are between 0-1, lines are colliding
if (uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1)
{
// Calcula la intersección
const float x = x1 + (uA * (x2 - x1));
const float y = y1 + (uA * (y2 - y1));
return {(int)x, (int)y};
}
return {-1, -1};
}
// Detector de colisiones entre una linea diagonal y una vertical
/*bool checkCollision(d_line_t &l1, v_line_t &l2)
{
// Normaliza la linea diagonal
normalizeLine(l1);
// Comprueba si la linea vertical esta a la izquierda de la linea diagonal
if (l2.x < l1.x1)
{
return false;
}
// Comprueba si la linea vertical esta a la derecha de la linea diagonal
if (l2.x > l1.x2)
{
return false;
}
// Inacabada
return true;
}*/
// Normaliza una linea diagonal
void normalizeLine(d_line_t &l)
{
// Las lineas diagonales van de izquierda a derecha
// x2 mayor que x1
if (l.x2 < l.x1)
{
const int x = l.x1;
const int y = l.y1;
l.x1 = l.x2;
l.y1 = l.y2;
l.x2 = x;
l.y2 = y;
}
}
// Detector de colisiones entre un punto y una linea diagonal
bool checkCollision(SDL_Point &p, d_line_t &l)
{
// Comprueba si el punto está en alineado con la linea
if (abs(p.x - l.x1) != abs(p.y - l.y1))
{
return false;
}
// Comprueba si está a la derecha de la linea
if (p.x > l.x1 && p.x > l.x2)
{
return false;
}
// Comprueba si está a la izquierda de la linea
if (p.x < l.x1 && p.x < l.x2)
{
return false;
}
// Comprueba si está por encima de la linea
if (p.y > l.y1 && p.y > l.y2)
{
return false;
}
// Comprueba si está por debajo de la linea
if (p.y < l.y1 && p.y < l.y2)
{
return false;
}
// En caso contrario, el punto está en la linea
return true;
/*const int m = (l.y2 - l.y1) / (l.x2 - l.x1);
const int c = 0;
// Comprueba si p cumple la ecuación de la linea
if (p.y == ((m * p.x) + c))
return true;
return false;*/
}
// Devuelve un color_t a partir de un string
color_t stringToColor(palette_e pal, std::string str)
{
if (pal == p_zxspectrum)
{
if (str == "black")
{
return {0x00, 0x00, 0x00};
}
else if (str == "bright_black")
{
return {0x00, 0x00, 0x00};
}
else if (str == "blue")
{
return {0x00, 0x00, 0xd8};
}
else if (str == "bright_blue")
{
return {0x00, 0x00, 0xFF};
}
else if (str == "red")
{
return {0xd8, 0x00, 0x00};
}
else if (str == "bright_red")
{
return {0xFF, 0x00, 0x00};
}
else if (str == "magenta")
{
return {0xd8, 0x00, 0xd8};
}
else if (str == "bright_magenta")
{
return {0xFF, 0x00, 0xFF};
}
else if (str == "green")
{
return {0x00, 0xd8, 0x00};
}
else if (str == "bright_green")
{
return {0x00, 0xFF, 0x00};
}
else if (str == "cyan")
{
return {0x00, 0xd8, 0xd8};
}
else if (str == "bright_cyan")
{
return {0x00, 0xFF, 0xFF};
}
else if (str == "yellow")
{
return {0xd8, 0xd8, 0x00};
}
else if (str == "bright_yellow")
{
return {0xFF, 0xFF, 0x00};
}
else if (str == "white")
{
return {0xd8, 0xd8, 0xd8};
}
else if (str == "bright_white")
{
return {0xFF, 0xFF, 0xFF};
}
}
else if (pal == p_zxarne)
{ // zxarne
if (str == "black")
{
return {0x00, 0x00, 0x00};
}
else if (str == "bright_black")
{
return {0x3C, 0x35, 0x1F};
}
else if (str == "blue")
{
return {0x31, 0x33, 0x90};
}
else if (str == "bright_blue")
{
return {0x15, 0x59, 0xDB};
}
else if (str == "red")
{
return {0xA7, 0x32, 0x11};
}
else if (str == "bright_red")
{
return {0xD8, 0x55, 0x25};
}
else if (str == "magenta")
{
return {0xA1, 0x55, 0x89};
}
else if (str == "bright_magenta")
{
return {0xCD, 0x7A, 0x50};
}
else if (str == "green")
{
return {0x62, 0x9A, 0x31};
}
else if (str == "bright_green")
{
return {0x9C, 0xD3, 0x3C};
}
else if (str == "cyan")
{
return {0x28, 0xA4, 0xCB};
}
else if (str == "bright_cyan")
{
return {0x65, 0xDC, 0xD6};
}
else if (str == "yellow")
{
return {0xE8, 0xBC, 0x50};
}
else if (str == "bright_yellow")
{
return {0xF1, 0xE7, 0x82};
}
else if (str == "white")
{
return {0xBF, 0xBF, 0xBD};
}
else if (str == "bright_white")
{
return {0xF2, 0xF1, 0xED};
}
}
return {0x00, 0x00, 0x00};
}
// Convierte una cadena en un valor booleano // Convierte una cadena en un valor booleano
bool stringToBool(std::string str) bool stringToBool(std::string str)
{ {

View File

@@ -57,13 +57,6 @@ struct color_t
Uint8 b; Uint8 b;
}; };
// Tipos de paleta
enum palette_e
{
p_zxspectrum,
p_zxarne
};
// Posiciones de las notificaciones // Posiciones de las notificaciones
enum not_pos_e enum not_pos_e
{ {
@@ -100,11 +93,22 @@ struct input_t
Uint8 deviceType; // Tipo de dispositivo (teclado o mando) Uint8 deviceType; // Tipo de dispositivo (teclado o mando)
}; };
// Estructura con opciones de la pantalla // Estructura con opciones para el video
struct op_screen_t struct op_video_t
{ {
int windowWidth; // Ancho de la ventana int windowWidth; // Ancho de la ventana
int windowHeight; // Alto de la ventana int windowHeight; // Alto de la ventana
int windowSize; // Contiene el valor por el que se multiplica el tamaño de la ventana
Uint32 mode; // Contiene el valor del modo de pantalla completa
Uint32 filter; // Filtro usado para el escalado de la imagen
bool vSync; // Indica si se quiere usar vsync o no
int gameWidth; // Ancho de la resolucion nativa del juego
int gameHeight; // Alto de la resolucion nativa del juego
bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa
bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa
bool borderEnabled; // Indica si ha de mostrar el borde en el modo de ventana
int borderWidth; // Cantidad de pixels que se añade en el borde de la ventana
int borderHeight; // Cantidad de pixels que se añade en el borde de la ventana
}; };
// Estructura para las opciones de las notificaciones // Estructura para las opciones de las notificaciones
@@ -116,6 +120,13 @@ struct op_notification_t
color_t color; // Color de las notificaciones color_t color; // Color de las notificaciones
}; };
// Estructura para las opciones de audio
struct op_audio_t
{
bool musicEnabled;
bool soundEnabled;
};
// Estructura con todas las opciones de configuración del programa // Estructura con todas las opciones de configuración del programa
struct options_t struct options_t
{ {
@@ -123,23 +134,10 @@ struct options_t
Uint8 playerSelected; // Jugador seleccionado para el modo 1P Uint8 playerSelected; // Jugador seleccionado para el modo 1P
std::vector<input_t> input; // Modo de control (teclado o mando) std::vector<input_t> input; // Modo de control (teclado o mando)
Uint8 language; // Idioma usado en el juego Uint8 language; // Idioma usado en el juego
Uint32 videoMode; // Contiene el valor del modo de pantalla completa
int windowSize; // Contiene el valor por el que se multiplica el tamaño de la ventana
Uint32 filter; // Filtro usado para el escalado de la imagen
bool vSync; // Indica si se quiere usar vsync o no
int gameWidth; // Ancho de la resolucion nativa del juego
int gameHeight; // Alto de la resolucion nativa del juego
bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa
bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa
bool borderEnabled; // Indica si ha de mostrar el borde en el modo de ventana
int borderWidth; // Cantidad de pixels que se añade en el borde de la ventana
int borderHeight; // Cantidad de pixels que se añade en el borde de la ventana
palette_e palette; // Paleta de colores a usar en el juego
bool console; // Indica si ha de mostrar información por la consola de texto bool console; // Indica si ha de mostrar información por la consola de texto
op_video_t video; // Opciones relativas a la clase screen
op_screen_t screen; // Opciones relativas a la clase screen
op_notification_t notifications; // Opciones relativas a las notificaciones; op_notification_t notifications; // Opciones relativas a las notificaciones;
op_audio_t audio; // Opciones para el audio
}; };
// Calcula el cuadrado de la distancia entre dos puntos // Calcula el cuadrado de la distancia entre dos puntos
@@ -157,30 +155,6 @@ bool checkCollision(SDL_Rect &a, SDL_Rect &b);
// Detector de colisiones entre un punto y un rectangulo // Detector de colisiones entre un punto y un rectangulo
bool checkCollision(SDL_Point &p, SDL_Rect &r); bool checkCollision(SDL_Point &p, SDL_Rect &r);
// Detector de colisiones entre una linea horizontal y un rectangulo
bool checkCollision(h_line_t &l, SDL_Rect &r);
// Detector de colisiones entre una linea vertical y un rectangulo
bool checkCollision(v_line_t &l, SDL_Rect &r);
// Detector de colisiones entre una linea horizontal y un punto
bool checkCollision(h_line_t &l, SDL_Point &p);
// Detector de colisiones entre dos lineas
SDL_Point checkCollision(line_t &l1, line_t &l2);
// Detector de colisiones entre dos lineas
SDL_Point checkCollision(d_line_t &l1, v_line_t &l2);
// Detector de colisiones entre un punto y una linea diagonal
bool checkCollision(SDL_Point &p, d_line_t &l);
// Normaliza una linea diagonal
void normalizeLine(d_line_t &l);
// Devuelve un color_t a partir de un string
color_t stringToColor(palette_e pal, std::string str);
// Convierte una cadena en un valor booleano // Convierte una cadena en un valor booleano
bool stringToBool(std::string str); bool stringToBool(std::string str);

View File

@@ -130,6 +130,7 @@ void Director::initInput()
void Director::initJailAudio() void Director::initJailAudio()
{ {
JA_Init(48000, AUDIO_S16, 2); JA_Init(48000, AUDIO_S16, 2);
JA_SetVolume(0);
} }
// Arranca SDL y crea la ventana // Arranca SDL y crea la ventana
@@ -154,7 +155,7 @@ bool Director::initSDL()
std::srand(static_cast<unsigned int>(SDL_GetTicks())); std::srand(static_cast<unsigned int>(SDL_GetTicks()));
// Establece el filtro de la textura // Establece el filtro de la textura
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(options->filter).c_str())) if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(options->video.filter).c_str()))
{ {
if (options->console) if (options->console)
{ {
@@ -165,12 +166,12 @@ bool Director::initSDL()
// Crea la ventana // Crea la ventana
int incW = 0; int incW = 0;
int incH = 0; int incH = 0;
if (options->borderEnabled) if (options->video.borderEnabled)
{ {
incW = options->borderWidth * 2; incW = options->video.borderWidth * 2;
incH = options->borderHeight * 2; incH = options->video.borderHeight * 2;
} }
window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, (options->gameWidth + incW) * options->windowSize, (options->gameHeight + incH) * options->windowSize, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI); window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, (options->video.gameWidth + incW) * options->video.windowSize, (options->video.gameHeight + incH) * options->video.windowSize, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
if (window == nullptr) if (window == nullptr)
{ {
if (options->console) if (options->console)
@@ -186,7 +187,7 @@ bool Director::initSDL()
//Uint32 flags = SDL_RENDERER_SOFTWARE; //Uint32 flags = SDL_RENDERER_SOFTWARE;
//Uint32 flags = SDL_RENDERER_ACCELERATED; //Uint32 flags = SDL_RENDERER_ACCELERATED;
Uint32 flags = 0; Uint32 flags = 0;
if (options->vSync) if (options->video.vSync)
{ {
flags = flags | SDL_RENDERER_PRESENTVSYNC; flags = flags | SDL_RENDERER_PRESENTVSYNC;
} }
@@ -206,7 +207,7 @@ bool Director::initSDL()
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF); SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
// Establece el tamaño del buffer de renderizado // Establece el tamaño del buffer de renderizado
SDL_RenderSetLogicalSize(renderer, options->gameWidth, options->gameHeight); SDL_RenderSetLogicalSize(renderer, options->video.gameWidth, options->video.gameHeight);
// Establece el modo de mezcla // Establece el modo de mezcla
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
@@ -377,17 +378,23 @@ void Director::initOptions()
options->input.push_back(inp); options->input.push_back(inp);
// Opciones de video // Opciones de video
options->gameWidth = GAMECANVAS_WIDTH; options->video.gameWidth = GAMECANVAS_WIDTH;
options->gameHeight = GAMECANVAS_HEIGHT; options->video.gameHeight = GAMECANVAS_HEIGHT;
options->videoMode = 0; options->video.mode = 0;
options->windowSize = 3; options->video.windowSize = 3;
options->filter = FILTER_NEAREST; options->video.windowWidth = options->video.windowSize * options->video.gameWidth;
options->vSync = true; options->video.windowHeight = options->video.windowSize * options->video.gameHeight;
options->integerScale = true; options->video.filter = FILTER_NEAREST;
options->keepAspect = true; options->video.vSync = true;
options->borderWidth = 0; options->video.integerScale = true;
options->borderHeight = 0; options->video.keepAspect = true;
options->borderEnabled = false; options->video.borderWidth = 0;
options->video.borderHeight = 0;
options->video.borderEnabled = false;
// Opciones de audio
options->audio.musicEnabled = false;
options->audio.soundEnabled = false;
// Opciones varios // Opciones varios
options->playerSelected = 0; options->playerSelected = 0;
@@ -521,17 +528,17 @@ bool Director::loadConfigFile()
} }
// Normaliza los valores // Normaliza los valores
const bool a = options->videoMode == 0; const bool a = options->video.mode == 0;
const bool b = options->videoMode == SDL_WINDOW_FULLSCREEN; const bool b = options->video.mode == SDL_WINDOW_FULLSCREEN;
const bool c = options->videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP; const bool c = options->video.mode == SDL_WINDOW_FULLSCREEN_DESKTOP;
if (!(a || b || c)) if (!(a || b || c))
{ {
options->videoMode = 0; options->video.mode = 0;
} }
if (options->windowSize < 1 || options->windowSize > 4) if (options->video.windowSize < 1 || options->video.windowSize > 4)
{ {
options->windowSize = 3; options->video.windowSize = 3;
} }
if (options->language < 0 || options->language > MAX_LANGUAGES) if (options->language < 0 || options->language > MAX_LANGUAGES)
@@ -567,24 +574,24 @@ bool Director::saveConfigFile()
// Opciones g´raficas // Opciones g´raficas
file << "## VISUAL OPTIONS\n"; file << "## VISUAL OPTIONS\n";
if (options->videoMode == 0) if (options->video.mode == 0)
{ {
file << "videoMode=0\n"; file << "videoMode=0\n";
} }
else if (options->videoMode == SDL_WINDOW_FULLSCREEN) else if (options->video.mode == SDL_WINDOW_FULLSCREEN)
{ {
file << "fullScreenMode=SDL_WINDOW_FULLSCREEN\n"; file << "fullScreenMode=SDL_WINDOW_FULLSCREEN\n";
} }
else if (options->videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP) else if (options->video.mode == SDL_WINDOW_FULLSCREEN_DESKTOP)
{ {
file << "fullScreenMode=SDL_WINDOW_FULLSCREEN_DESKTOP\n"; file << "fullScreenMode=SDL_WINDOW_FULLSCREEN_DESKTOP\n";
} }
file << "windowSize=" + std::to_string(options->windowSize) + "\n"; file << "windowSize=" + std::to_string(options->video.windowSize) + "\n";
if (options->filter == FILTER_NEAREST) if (options->video.filter == FILTER_NEAREST)
{ {
file << "filter=FILTER_NEAREST\n"; file << "filter=FILTER_NEAREST\n";
} }
@@ -593,12 +600,12 @@ bool Director::saveConfigFile()
file << "filter=FILTER_LINEAL\n"; file << "filter=FILTER_LINEAL\n";
} }
file << "vSync=" + boolToString(options->vSync) + "\n"; file << "vSync=" + boolToString(options->video.vSync) + "\n";
file << "integerScale=" + boolToString(options->integerScale) + "\n"; file << "integerScale=" + boolToString(options->video.integerScale) + "\n";
file << "keepAspect=" + boolToString(options->keepAspect) + "\n"; file << "keepAspect=" + boolToString(options->video.keepAspect) + "\n";
file << "borderEnabled=" + boolToString(options->borderEnabled) + "\n"; file << "borderEnabled=" + boolToString(options->video.borderEnabled) + "\n";
file << "borderWidth=" + std::to_string(options->borderWidth) + "\n"; file << "borderWidth=" + std::to_string(options->video.borderWidth) + "\n";
file << "borderHeight=" + std::to_string(options->borderHeight) + "\n"; file << "borderHeight=" + std::to_string(options->video.borderHeight) + "\n";
// Otras opciones del programa // Otras opciones del programa
file << "\n## OTHER OPTIONS\n"; file << "\n## OTHER OPTIONS\n";
@@ -707,24 +714,24 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
{ {
if (value == "SDL_WINDOW_FULLSCREEN_DESKTOP") if (value == "SDL_WINDOW_FULLSCREEN_DESKTOP")
{ {
options->videoMode = SDL_WINDOW_FULLSCREEN_DESKTOP; options->video.mode = SDL_WINDOW_FULLSCREEN_DESKTOP;
} }
else if (value == "SDL_WINDOW_FULLSCREEN") else if (value == "SDL_WINDOW_FULLSCREEN")
{ {
options->videoMode = SDL_WINDOW_FULLSCREEN; options->video.mode = SDL_WINDOW_FULLSCREEN;
} }
else else
{ {
options->videoMode = 0; options->video.mode = 0;
} }
} }
else if (var == "windowSize") else if (var == "windowSize")
{ {
options->windowSize = std::stoi(value); options->video.windowSize = std::stoi(value);
if ((options->windowSize < 1) || (options->windowSize > 4)) if ((options->video.windowSize < 1) || (options->video.windowSize > 4))
{ {
options->windowSize = 3; options->video.windowSize = 3;
} }
} }
@@ -732,42 +739,42 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
{ {
if (value == "FILTER_LINEAL") if (value == "FILTER_LINEAL")
{ {
options->filter = FILTER_LINEAL; options->video.filter = FILTER_LINEAL;
} }
else else
{ {
options->filter = FILTER_NEAREST; options->video.filter = FILTER_NEAREST;
} }
} }
else if (var == "vSync") else if (var == "vSync")
{ {
options->vSync = stringToBool(value); options->video.vSync = stringToBool(value);
} }
else if (var == "integerScale") else if (var == "integerScale")
{ {
options->integerScale = stringToBool(value); options->video.integerScale = stringToBool(value);
} }
else if (var == "keepAspect") else if (var == "keepAspect")
{ {
options->keepAspect = stringToBool(value); options->video.keepAspect = stringToBool(value);
} }
else if (var == "borderEnabled") else if (var == "borderEnabled")
{ {
options->borderEnabled = stringToBool(value); options->video.borderEnabled = stringToBool(value);
} }
else if (var == "borderWidth") else if (var == "borderWidth")
{ {
options->borderWidth = std::stoi(value); options->video.borderWidth = std::stoi(value);
} }
else if (var == "borderHeight") else if (var == "borderHeight")
{ {
options->borderHeight = std::stoi(value); options->video.borderHeight = std::stoi(value);
} }
// Opciones varias // Opciones varias

View File

@@ -167,7 +167,7 @@ void Scoreboard::setPos(SDL_Rect rect)
{ {
this->rect = rect; this->rect = rect;
const int left = 45; const int left = rect.w / 6;
const int right = rect.w - left; const int right = rect.w - left;
const int center = rect.w / 2; const int center = rect.w / 2;
const int desp = 7; const int desp = 7;

View File

@@ -535,20 +535,20 @@ void Title::updateBG()
// Cambia el valor de la variable de modo de pantalla completa // Cambia el valor de la variable de modo de pantalla completa
void Title::switchFullScreenModeVar() void Title::switchFullScreenModeVar()
{ {
switch (options->videoMode) switch (options->video.mode)
{ {
case 0: case 0:
options->videoMode = SDL_WINDOW_FULLSCREEN; options->video.mode = SDL_WINDOW_FULLSCREEN;
break; break;
case SDL_WINDOW_FULLSCREEN: case SDL_WINDOW_FULLSCREEN:
options->videoMode = SDL_WINDOW_FULLSCREEN_DESKTOP; options->video.mode = SDL_WINDOW_FULLSCREEN_DESKTOP;
break; break;
case SDL_WINDOW_FULLSCREEN_DESKTOP: case SDL_WINDOW_FULLSCREEN_DESKTOP:
options->videoMode = 0; options->video.mode = 0;
break; break;
default: default:
options->videoMode = 0; options->video.mode = 0;
break; break;
} }
} }