Los parametros del juego ya se pueden cargar desde un fichero de texto. Falta empezar a sacar parametros hard-coded a ese fichero
This commit is contained in:
6
data/config/param.txt
Normal file
6
data/config/param.txt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
gameWidth 320
|
||||||
|
gameHeight 240
|
||||||
|
numSquaresWidth 80
|
||||||
|
numSquaresHeight 60
|
||||||
|
fadeRandomSquaresDelay 1
|
||||||
|
fadeRandomSquaresMult 8
|
||||||
@@ -112,12 +112,12 @@ struct op_window_t
|
|||||||
// Estructura con opciones para el video
|
// Estructura con opciones para el video
|
||||||
struct op_video_t
|
struct op_video_t
|
||||||
{
|
{
|
||||||
|
int gameWidth; // Ancho de la resolucion nativa del juego
|
||||||
|
int gameHeight; // Alto de la resolucion nativa del juego
|
||||||
op_window_t window; // Opciones para la ventana del programa
|
op_window_t window; // Opciones para la ventana del programa
|
||||||
Uint32 mode; // Contiene el valor del modo de pantalla completa
|
Uint32 mode; // Contiene el valor del modo de pantalla completa
|
||||||
Uint32 filter; // Filtro usado para el escalado de la imagen
|
Uint32 filter; // Filtro usado para el escalado de la imagen
|
||||||
bool vSync; // Indica si se quiere usar vsync o no
|
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 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 keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa
|
||||||
op_border_t border; // Opciones para el borde la pantalla de juego
|
op_border_t border; // Opciones para el borde la pantalla de juego
|
||||||
@@ -158,10 +158,15 @@ struct options_t
|
|||||||
|
|
||||||
struct param_t
|
struct param_t
|
||||||
{
|
{
|
||||||
int gameWidth; // Ancho del juego
|
int gameWidth; // Ancho de la resolucion nativa del juego
|
||||||
int gameHeight; // Alto del juego
|
int gameHeight; // Alto de la resolucion nativa del juego
|
||||||
|
|
||||||
SDL_Rect scoreboard; // Posición y tamaño del marcador
|
SDL_Rect scoreboard; // Posición y tamaño del marcador
|
||||||
|
|
||||||
|
int numSquaresWidth;
|
||||||
|
int numSquaresHeight;
|
||||||
|
int fadeRandomSquaresDelay;
|
||||||
|
int fadeRandomSquaresMult;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calcula el cuadrado de la distancia entre dos puntos
|
// Calcula el cuadrado de la distancia entre dos puntos
|
||||||
|
|||||||
@@ -14,16 +14,10 @@
|
|||||||
// 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;
|
||||||
|
|
||||||
// Inicializa las opciones del programa
|
|
||||||
initOptions();
|
|
||||||
|
|
||||||
// Comprueba los parametros del programa
|
// Comprueba los parametros del programa
|
||||||
checkProgramArguments(argc, argv);
|
checkProgramArguments(argc, argv);
|
||||||
|
|
||||||
@@ -35,6 +29,9 @@ Director::Director(int argc, char *argv[])
|
|||||||
createSystemFolder("jailgames/coffee_crisis_arcade_edition_debug");
|
createSystemFolder("jailgames/coffee_crisis_arcade_edition_debug");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Inicializa las opciones del programa
|
||||||
|
initOptions();
|
||||||
|
|
||||||
// Crea el objeto que controla los ficheros de recursos
|
// Crea el objeto que controla los ficheros de recursos
|
||||||
asset = new Asset(executablePath);
|
asset = new Asset(executablePath);
|
||||||
asset->setVerbose(options->console);
|
asset->setVerbose(options->console);
|
||||||
@@ -45,6 +42,9 @@ Director::Director(int argc, char *argv[])
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Carga los parametros para configurar el juego
|
||||||
|
loadParams();
|
||||||
|
|
||||||
// Carga el fichero de configuración
|
// Carga el fichero de configuración
|
||||||
loadConfigFile();
|
loadConfigFile();
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ bool Director::initSDL()
|
|||||||
incW = options->video.border.width * 2;
|
incW = options->video.border.width * 2;
|
||||||
incH = options->video.border.height * 2;
|
incH = options->video.border.height * 2;
|
||||||
}
|
}
|
||||||
window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, (options->video.gameWidth + incW) * options->video.window.size, (options->video.gameHeight + incH) * options->video.window.size, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, (param->gameWidth + incW) * options->video.window.size, (param->gameHeight + incH) * options->video.window.size, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||||
if (window == nullptr)
|
if (window == nullptr)
|
||||||
{
|
{
|
||||||
if (options->console)
|
if (options->console)
|
||||||
@@ -211,7 +211,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->video.gameWidth, options->video.gameHeight);
|
SDL_RenderSetLogicalSize(renderer, param->gameWidth, param->gameHeight);
|
||||||
|
|
||||||
// Establece el modo de mezcla
|
// Establece el modo de mezcla
|
||||||
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
|
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
|
||||||
@@ -238,6 +238,7 @@ bool Director::setFileList()
|
|||||||
// Ficheros de configuración
|
// Ficheros de configuración
|
||||||
asset->add(systemFolder + "/config.txt", t_data, false, true);
|
asset->add(systemFolder + "/config.txt", t_data, false, true);
|
||||||
asset->add(systemFolder + "/score.bin", t_data, false, true);
|
asset->add(systemFolder + "/score.bin", t_data, false, true);
|
||||||
|
asset->add(prefix + "/data/config/param.txt", t_data);
|
||||||
asset->add(prefix + "/data/config/demo.bin", t_data);
|
asset->add(prefix + "/data/config/demo.bin", t_data);
|
||||||
asset->add(prefix + "/data/config/gamecontrollerdb.txt", t_data);
|
asset->add(prefix + "/data/config/gamecontrollerdb.txt", t_data);
|
||||||
|
|
||||||
@@ -363,10 +364,12 @@ void Director::loadParams()
|
|||||||
{
|
{
|
||||||
param = new param_t;
|
param = new param_t;
|
||||||
|
|
||||||
param->gameWidth = 320;
|
loadParam(param, asset->get("param.txt"));
|
||||||
param->gameHeight = 240;
|
|
||||||
|
|
||||||
param->scoreboard = {0, 240-32, 320, 32};
|
options->video.window.width = options->video.window.size * param->gameWidth;
|
||||||
|
options->video.window.height = options->video.window.size * param->gameHeight;
|
||||||
|
options->video.gameWidth = param->gameWidth;
|
||||||
|
options->video.gameHeight = param->gameHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa las opciones del programa
|
// Inicializa las opciones del programa
|
||||||
@@ -390,12 +393,10 @@ void Director::initOptions()
|
|||||||
options->input.push_back(inp);
|
options->input.push_back(inp);
|
||||||
|
|
||||||
// Opciones de video
|
// Opciones de video
|
||||||
options->video.gameWidth = param->gameWidth;
|
|
||||||
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 * param->gameWidth;
|
||||||
options->video.window.height = options->video.window.size * options->video.gameHeight;
|
//options->video.window.height = options->video.window.size * param->gameHeight;
|
||||||
options->video.filter = FILTER_NEAREST;
|
options->video.filter = FILTER_NEAREST;
|
||||||
options->video.vSync = true;
|
options->video.vSync = true;
|
||||||
options->video.integerScale = true;
|
options->video.integerScale = true;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "logo.h"
|
#include "logo.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "title.h"
|
#include "title.h"
|
||||||
|
#include "load_param.h"
|
||||||
|
|
||||||
#ifndef DIRECTOR_H
|
#ifndef DIRECTOR_H
|
||||||
#define DIRECTOR_H
|
#define DIRECTOR_H
|
||||||
@@ -84,9 +85,6 @@ private:
|
|||||||
// Crea la carpeta del sistema donde guardar datos
|
// Crea la carpeta del sistema donde guardar datos
|
||||||
void createSystemFolder(std::string folder);
|
void createSystemFolder(std::string folder);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void setSection(section_t section);
|
|
||||||
|
|
||||||
// Ejecuta la seccion de juego con el logo
|
// Ejecuta la seccion de juego con el logo
|
||||||
void runLogo();
|
void runLogo();
|
||||||
|
|
||||||
|
|||||||
@@ -34,8 +34,10 @@ void Fade::init()
|
|||||||
r = 0;
|
r = 0;
|
||||||
g = 0;
|
g = 0;
|
||||||
b = 0;
|
b = 0;
|
||||||
numSquaresWidth = 80;
|
numSquaresWidth = param->numSquaresWidth;
|
||||||
numSquaresHeight = 60;
|
numSquaresHeight = param->numSquaresHeight;
|
||||||
|
fadeRandomSquaresDelay = param->fadeRandomSquaresDelay;
|
||||||
|
fadeRandomSquaresMult = param->fadeRandomSquaresMult;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta una transición en pantalla
|
// Pinta una transición en pantalla
|
||||||
@@ -118,9 +120,7 @@ void Fade::update()
|
|||||||
|
|
||||||
case FADE_RANDOM_SQUARE:
|
case FADE_RANDOM_SQUARE:
|
||||||
{
|
{
|
||||||
const int delay = 1;
|
if (counter % fadeRandomSquaresDelay == 0)
|
||||||
const int mult = 8;
|
|
||||||
if (counter % delay == 0)
|
|
||||||
{
|
{
|
||||||
// Dibujamos sobre el backbuffer
|
// Dibujamos sobre el backbuffer
|
||||||
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
|
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
|
||||||
@@ -128,17 +128,17 @@ void Fade::update()
|
|||||||
|
|
||||||
// Dibuja el cuadrado correspondiente
|
// Dibuja el cuadrado correspondiente
|
||||||
SDL_SetRenderDrawColor(renderer, r, g, b, 255);
|
SDL_SetRenderDrawColor(renderer, r, g, b, 255);
|
||||||
const int index = std::min(counter / delay, (numSquaresWidth * numSquaresHeight) - 1);
|
const int index = std::min(counter / fadeRandomSquaresDelay, (numSquaresWidth * numSquaresHeight) - 1);
|
||||||
for (int i = 0; i < mult; ++i)
|
for (int i = 0; i < fadeRandomSquaresMult; ++i)
|
||||||
{
|
{
|
||||||
SDL_RenderFillRect(renderer, &square[index * mult + i]);
|
SDL_RenderFillRect(renderer, &square[index * fadeRandomSquaresMult + i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Volvemos a usar el renderizador de forma normal
|
// Volvemos a usar el renderizador de forma normal
|
||||||
SDL_SetRenderTarget(renderer, temp);
|
SDL_SetRenderTarget(renderer, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter * mult / delay >= numSquaresWidth * numSquaresHeight)
|
if (counter * fadeRandomSquaresMult / fadeRandomSquaresDelay >= numSquaresWidth * numSquaresHeight)
|
||||||
{
|
{
|
||||||
finished = true;
|
finished = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ private:
|
|||||||
int numSquaresHeight; // Cantidad total de cuadraditos en vertical para el FADE_RANDOM_SQUARE
|
int numSquaresHeight; // Cantidad total de cuadraditos en vertical para el FADE_RANDOM_SQUARE
|
||||||
param_t *param; // Puntero con todos los parametros del programa
|
param_t *param; // Puntero con todos los parametros del programa
|
||||||
std::vector<SDL_Rect> square; // Vector con los indices de los cuadrados para el FADE_RANDOM_SQUARE
|
std::vector<SDL_Rect> square; // Vector con los indices de los cuadrados para el FADE_RANDOM_SQUARE
|
||||||
|
int fadeRandomSquaresDelay;
|
||||||
|
int fadeRandomSquaresMult;
|
||||||
|
|
||||||
// Inicializa las variables
|
// Inicializa las variables
|
||||||
void init();
|
void init();
|
||||||
|
|||||||
106
source/load_param.cpp
Normal file
106
source/load_param.cpp
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
#include "load_param.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
// Asigna variables a partir de dos cadenas
|
||||||
|
bool setOptions(param_t *param, std::string var, std::string value);
|
||||||
|
|
||||||
|
// Establece valores por defecto a las variables
|
||||||
|
void initParam(param_t *param)
|
||||||
|
{
|
||||||
|
// Tamaño original del juego
|
||||||
|
param->gameWidth = 320;
|
||||||
|
param->gameHeight = 240;
|
||||||
|
|
||||||
|
// Tamaño para el marcador
|
||||||
|
param->scoreboard = {0, 240 - 32, 320, 32};
|
||||||
|
|
||||||
|
// Valores para el FADE_RANDOM_SQUARE
|
||||||
|
param->numSquaresWidth = 80;
|
||||||
|
param->numSquaresHeight = 60;
|
||||||
|
param->fadeRandomSquaresDelay = 1;
|
||||||
|
param->fadeRandomSquaresMult = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece valores para los parametros a partir de un fichero de texto
|
||||||
|
bool loadParam(param_t *param, std::string filePath)
|
||||||
|
{
|
||||||
|
// Pone valores por defecto a las variables
|
||||||
|
initParam(param);
|
||||||
|
|
||||||
|
// Indicador de éxito en la carga
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
|
// Variables para manejar el fichero
|
||||||
|
std::string line;
|
||||||
|
std::ifstream file(filePath);
|
||||||
|
|
||||||
|
// Si el fichero se puede abrir
|
||||||
|
if (file.good())
|
||||||
|
{
|
||||||
|
while (std::getline(file, line))
|
||||||
|
{
|
||||||
|
// Comprueba que la linea no sea un comentario
|
||||||
|
if (line.substr(0, 1) != "#")
|
||||||
|
{
|
||||||
|
// Encuentra la posición del caracter '='
|
||||||
|
int pos = line.find(" ");
|
||||||
|
// Procesa las dos subcadenas
|
||||||
|
if (!setOptions(param, line.substr(0, pos), line.substr(pos + 1, line.length())))
|
||||||
|
{
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cierra el fichero
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Asigna variables a partir de dos cadenas
|
||||||
|
bool setOptions(param_t *param, std::string var, std::string value)
|
||||||
|
{
|
||||||
|
// Indicador de éxito en la asignación
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
|
// Opciones de video
|
||||||
|
if (var == "gameWidth")
|
||||||
|
{
|
||||||
|
param->gameWidth = std::stoi(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "gameHeight")
|
||||||
|
{
|
||||||
|
param->gameHeight = std::stoi(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "numSquaresWidth")
|
||||||
|
{
|
||||||
|
param->numSquaresWidth = std::stoi(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "numSquaresHeight")
|
||||||
|
{
|
||||||
|
param->numSquaresHeight = std::stoi(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "fadeRandomSquaresDelay")
|
||||||
|
{
|
||||||
|
param->fadeRandomSquaresDelay = std::stoi(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "fadeRandomSquaresMult")
|
||||||
|
{
|
||||||
|
param->fadeRandomSquaresMult = std::stoi(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
13
source/load_param.h
Normal file
13
source/load_param.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include "common/utils.h"
|
||||||
|
#include "const.h"
|
||||||
|
|
||||||
|
#ifndef LOAD_PARAM
|
||||||
|
#define LOAD_PARAM
|
||||||
|
|
||||||
|
// Establece valores para los parametros a partir de un fichero de texto
|
||||||
|
bool loadParam(param_t *param, std::string filePath);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user