forked from jaildesigner-jailgames/jaildoctors_dilemma
Eliminados todos los std:: del código
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#include <iostream>
|
||||
|
||||
// Constructor
|
||||
Cheevos::Cheevos(Screen *screen, options_t *options, std::string file)
|
||||
Cheevos::Cheevos(Screen *screen, options_t *options, string file)
|
||||
{
|
||||
// Copia la dirección de los objetos
|
||||
this->options = options;
|
||||
@@ -169,7 +169,7 @@ void Cheevos::loadFromFile()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Warning: Unable to open file! SDL Error: " << SDL_GetError() << std::endl;
|
||||
cout << "Warning: Unable to open file! SDL Error: " << SDL_GetError() << endl;
|
||||
}
|
||||
|
||||
// Crea el fichero en modo escritura
|
||||
@@ -179,7 +179,7 @@ void Cheevos::loadFromFile()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "New file created!" << std::endl;
|
||||
cout << "New file created!" << endl;
|
||||
}
|
||||
|
||||
// Guarda la información
|
||||
@@ -195,7 +195,7 @@ void Cheevos::loadFromFile()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Error: Unable to create file! SDL Error: " << SDL_GetError() << std::endl;
|
||||
cout << "Error: Unable to create file! SDL Error: " << SDL_GetError() << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -205,7 +205,7 @@ void Cheevos::loadFromFile()
|
||||
// Carga los datos
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Reading file...!" << std::endl;
|
||||
cout << "Reading file...!" << endl;
|
||||
}
|
||||
for (int i = 0; i < (int)cheevos.size(); ++i)
|
||||
{
|
||||
@@ -237,13 +237,13 @@ void Cheevos::saveToFile()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Error: Unable to save file! " << SDL_GetError() << std::endl;
|
||||
cout << "Error: Unable to save file! " << SDL_GetError() << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Lista los logros
|
||||
std::vector<cheevos_t> Cheevos::list()
|
||||
vector<cheevos_t> Cheevos::list()
|
||||
{
|
||||
return cheevos;
|
||||
}
|
||||
|
||||
@@ -8,14 +8,16 @@
|
||||
#ifndef CHEEVOS_H
|
||||
#define CHEEVOS_H
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct cheevos_t
|
||||
{
|
||||
int id; // Identificador del logro
|
||||
std::string caption; // Texto con el nombre del logro
|
||||
std::string description; // Texto que describe el logro
|
||||
int icon; // Indice del icono a utilizar en la notificación
|
||||
bool completed; // Indica si se ha obtenido el logro
|
||||
bool valid; // Indica si se puede obtener el logro
|
||||
int id; // Identificador del logro
|
||||
string caption; // Texto con el nombre del logro
|
||||
string description; // Texto que describe el logro
|
||||
int icon; // Indice del icono a utilizar en la notificación
|
||||
bool completed; // Indica si se ha obtenido el logro
|
||||
bool valid; // Indica si se puede obtener el logro
|
||||
};
|
||||
|
||||
class Cheevos
|
||||
@@ -26,9 +28,9 @@ private:
|
||||
options_t *options; // Puntero a las opciones del juego
|
||||
|
||||
// Variables
|
||||
std::vector<cheevos_t> cheevos; // Listado de logros
|
||||
bool enabled; // Indica si los logros se pueden obtener
|
||||
std::string file; // Fichero done leer/almacenar el estado de los logros
|
||||
vector<cheevos_t> cheevos; // Listado de logros
|
||||
bool enabled; // Indica si los logros se pueden obtener
|
||||
string file; // Fichero done leer/almacenar el estado de los logros
|
||||
|
||||
// Inicializa los logros
|
||||
void init();
|
||||
@@ -44,7 +46,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Cheevos(Screen *screen, options_t *options, std::string file);
|
||||
Cheevos(Screen *screen, options_t *options, string file);
|
||||
|
||||
// Destructor
|
||||
~Cheevos();
|
||||
@@ -59,7 +61,7 @@ public:
|
||||
void enable(bool value);
|
||||
|
||||
// Lista los logros
|
||||
std::vector<cheevos_t> list();
|
||||
vector<cheevos_t> list();
|
||||
|
||||
// Devuelve el número total de logros desbloqueados
|
||||
int unlocked();
|
||||
|
||||
@@ -37,7 +37,7 @@ Credits::Credits(SDL_Renderer *renderer, Screen *screen, Resource *resource, Ass
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << endl;
|
||||
}
|
||||
}
|
||||
SDL_SetTextureBlendMode(textTexture, SDL_BLENDMODE_BLEND);
|
||||
@@ -48,7 +48,7 @@ Credits::Credits(SDL_Renderer *renderer, Screen *screen, Resource *resource, Ass
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << endl;
|
||||
}
|
||||
}
|
||||
SDL_SetTextureBlendMode(coverTexture, SDL_BLENDMODE_BLEND);
|
||||
@@ -126,7 +126,7 @@ void Credits::checkInput()
|
||||
// Inicializa los textos
|
||||
void Credits::iniTexts()
|
||||
{
|
||||
std::string keys = "";
|
||||
string keys = "";
|
||||
if (options->keys == ctrl_cursor)
|
||||
{
|
||||
keys = "CURSORS";
|
||||
@@ -331,7 +331,7 @@ void Credits::render()
|
||||
SDL_RenderCopy(renderer, textTexture, nullptr, nullptr);
|
||||
|
||||
// Dibuja la textura que cubre el texto
|
||||
const int offset = std::min(counter / 8, 192 / 2);
|
||||
const int offset = min(counter / 8, 192 / 2);
|
||||
SDL_Rect srcRect = {0, 0, 256, 192 - (offset * 2)};
|
||||
SDL_Rect dstRect = {0, offset * 2, 256, 192 - (offset * 2)};
|
||||
SDL_RenderCopy(renderer, coverTexture, &srcRect, &dstRect);
|
||||
|
||||
@@ -17,13 +17,15 @@
|
||||
#ifndef CREDITS_H
|
||||
#define CREDITS_H
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Credits
|
||||
{
|
||||
private:
|
||||
struct captions_t
|
||||
{
|
||||
std::string label; // Texto a escribir
|
||||
color_t color; // Color del texto
|
||||
string label; // Texto a escribir
|
||||
color_t color; // Color del texto
|
||||
};
|
||||
|
||||
// Objetos y punteros
|
||||
@@ -41,12 +43,12 @@ private:
|
||||
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
||||
|
||||
// Variables
|
||||
int counter; // Contador
|
||||
bool counterEnabled; // Indica si esta activo el contador
|
||||
int subCounter; // Contador secundario
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
std::vector<captions_t> texts; // Vector con los textos
|
||||
int counter; // Contador
|
||||
bool counterEnabled; // Indica si esta activo el contador
|
||||
int subCounter; // Contador secundario
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
vector<captions_t> texts; // Vector con los textos
|
||||
|
||||
// Actualiza las variables
|
||||
void update();
|
||||
|
||||
@@ -192,7 +192,7 @@ void Demo::reLoadTextures()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "** RELOAD REQUESTED" << std::endl;
|
||||
cout << "** RELOAD REQUESTED" << endl;
|
||||
}
|
||||
room->reLoadTexture();
|
||||
scoreboard->reLoadTexture();
|
||||
@@ -220,7 +220,7 @@ void Demo::switchPalette()
|
||||
}
|
||||
|
||||
// Cambia de habitación
|
||||
bool Demo::changeRoom(std::string file)
|
||||
bool Demo::changeRoom(string file)
|
||||
{
|
||||
// En las habitaciones los limites tienen la cadena del fichero o un 0 en caso de no limitar con nada
|
||||
if (file != "0")
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#ifndef DEMO_H
|
||||
#define DEMO_H
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Demo
|
||||
{
|
||||
private:
|
||||
@@ -39,14 +41,14 @@ private:
|
||||
section_t *section; // Seccion actual dentro del juego
|
||||
|
||||
// Variables
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
std::string currentRoom; // Fichero de la habitación actual
|
||||
board_t board; // Estructura con los datos del marcador
|
||||
int counter; // Contador para el modo demo
|
||||
int roomTime; // Tiempo que se muestra cada habitacion
|
||||
int roomIndex; // Indice para el vector de habitaciones
|
||||
std::vector<std::string> rooms; // Listado con los mapas de la demo
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
string currentRoom; // Fichero de la habitación actual
|
||||
board_t board; // Estructura con los datos del marcador
|
||||
int counter; // Contador para el modo demo
|
||||
int roomTime; // Tiempo que se muestra cada habitacion
|
||||
int roomIndex; // Indice para el vector de habitaciones
|
||||
vector<string> rooms; // Listado con los mapas de la demo
|
||||
|
||||
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
||||
void update();
|
||||
@@ -70,7 +72,7 @@ private:
|
||||
void switchPalette();
|
||||
|
||||
// Cambia de habitación
|
||||
bool changeRoom(std::string file);
|
||||
bool changeRoom(string file);
|
||||
|
||||
// Comprueba si se ha de cambiar de habitación
|
||||
void checkRoomChange();
|
||||
|
||||
@@ -100,11 +100,11 @@ void Director::initOnline()
|
||||
{ // Establece el servidor y el puerto
|
||||
jscore::init(options->online.server, options->online.port);
|
||||
|
||||
const std::string caption = options->online.jailerID + " IS LOGGED IN";
|
||||
const string caption = options->online.jailerID + " IS LOGGED IN";
|
||||
screen->showNotification(caption);
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << caption << std::endl;
|
||||
cout << caption << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -214,12 +214,12 @@ bool Director::loadConfig()
|
||||
bool success = true;
|
||||
|
||||
// Versión actual del fichero
|
||||
const std::string configVersion = options->configVersion;
|
||||
const string configVersion = options->configVersion;
|
||||
options->configVersion = "";
|
||||
|
||||
// Variables para manejar el fichero
|
||||
std::string line;
|
||||
std::ifstream file(asset->get("config.txt"));
|
||||
string line;
|
||||
ifstream file(asset->get("config.txt"));
|
||||
|
||||
// Si el fichero se puede abrir
|
||||
if (file.good())
|
||||
@@ -227,9 +227,9 @@ bool Director::loadConfig()
|
||||
// Procesa el fichero linea a linea
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Reading file config.txt\n";
|
||||
cout << "Reading file config.txt\n";
|
||||
}
|
||||
while (std::getline(file, line))
|
||||
while (getline(file, line))
|
||||
{
|
||||
// Comprueba que la linea no sea un comentario
|
||||
if (line.substr(0, 1) != "#")
|
||||
@@ -241,8 +241,8 @@ bool Director::loadConfig()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Warning: file config.txt\n";
|
||||
std::cout << "unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
||||
cout << "Warning: file config.txt\n";
|
||||
cout << "unknown parameter " << line.substr(0, pos).c_str() << endl;
|
||||
}
|
||||
success = false;
|
||||
}
|
||||
@@ -252,7 +252,7 @@ bool Director::loadConfig()
|
||||
// Cierra el fichero
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Closing file config.txt\n\n";
|
||||
cout << "Closing file config.txt\n\n";
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
@@ -307,20 +307,20 @@ bool Director::saveConfig()
|
||||
bool success = true;
|
||||
|
||||
// Crea y abre el fichero de texto
|
||||
std::ofstream file(asset->get("config.txt"));
|
||||
ofstream file(asset->get("config.txt"));
|
||||
|
||||
if (file.good())
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << asset->get("config.txt") << " open for writing" << std::endl;
|
||||
cout << asset->get("config.txt") << " open for writing" << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << asset->get("config.txt") << " can't be opened" << std::endl;
|
||||
cout << asset->get("config.txt") << " can't be opened" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ bool Director::saveConfig()
|
||||
file << "videoMode=SDL_WINDOW_FULLSCREEN_DESKTOP\n";
|
||||
}
|
||||
|
||||
file << "windowSize=" + std::to_string(options->windowSize) + "\n";
|
||||
file << "windowSize=" + to_string(options->windowSize) + "\n";
|
||||
|
||||
if (options->filter == FILTER_NEAREST)
|
||||
{
|
||||
@@ -374,14 +374,14 @@ bool Director::saveConfig()
|
||||
file << "integerScale=" + boolToString(options->integerScale) + "\n";
|
||||
file << "keepAspect=" + boolToString(options->keepAspect) + "\n";
|
||||
file << "borderEnabled=" + boolToString(options->borderEnabled) + "\n";
|
||||
file << "borderWidth=" + std::to_string(options->borderWidth) + "\n";
|
||||
file << "borderHeight=" + std::to_string(options->borderHeight) + "\n";
|
||||
file << "palette=" + std::to_string(options->palette) + "\n";
|
||||
file << "borderWidth=" + to_string(options->borderWidth) + "\n";
|
||||
file << "borderHeight=" + to_string(options->borderHeight) + "\n";
|
||||
file << "palette=" + to_string(options->palette) + "\n";
|
||||
|
||||
file << "\n## ONLINE OPTIONS\n";
|
||||
file << "enabled=" + boolToString(options->online.enabled) + "\n";
|
||||
file << "server=" + options->online.server + "\n";
|
||||
file << "port=" + std::to_string(options->online.port) + "\n";
|
||||
file << "port=" + to_string(options->online.port) + "\n";
|
||||
file << "jailerID=" + options->online.jailerID + "\n";
|
||||
|
||||
file << "\n## NOTIFICATION OPTIONS\n";
|
||||
@@ -418,18 +418,18 @@ bool Director::saveConfig()
|
||||
}
|
||||
|
||||
// Crea la carpeta del sistema donde guardar datos
|
||||
void Director::createSystemFolder(std::string folder)
|
||||
void Director::createSystemFolder(string folder)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
systemFolder = std::string(getenv("APPDATA")) + "/" + folder;
|
||||
systemFolder = string(getenv("APPDATA")) + "/" + folder;
|
||||
#elif __APPLE__
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
const char *homedir = pw->pw_dir;
|
||||
systemFolder = std::string(homedir) + "/Library/Application Support" + "/" + folder;
|
||||
systemFolder = string(homedir) + "/Library/Application Support" + "/" + folder;
|
||||
#elif __linux__
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
const char *homedir = pw->pw_dir;
|
||||
systemFolder = std::string(homedir) + "/." + folder;
|
||||
systemFolder = string(homedir) + "/." + folder;
|
||||
#endif
|
||||
|
||||
struct stat st = {0};
|
||||
@@ -471,12 +471,12 @@ void Director::loadResources(section_t *section)
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "** LOAD RESOURCES" << std::endl;
|
||||
cout << "** LOAD RESOURCES" << endl;
|
||||
}
|
||||
|
||||
if (section->name == SECTION_PROG_LOGO)
|
||||
{
|
||||
std::vector<std::string> textureList;
|
||||
vector<string> textureList;
|
||||
textureList.push_back("jailgames.png");
|
||||
textureList.push_back("since_1998.png");
|
||||
|
||||
@@ -485,7 +485,7 @@ void Director::loadResources(section_t *section)
|
||||
|
||||
else if (section->name == SECTION_PROG_INTRO)
|
||||
{
|
||||
std::vector<std::string> textureList;
|
||||
vector<string> textureList;
|
||||
textureList.push_back("loading_screen_bn.png");
|
||||
textureList.push_back("loading_screen_color.png");
|
||||
textureList.push_back("loading_screen_bn_zxarne.png");
|
||||
@@ -496,7 +496,7 @@ void Director::loadResources(section_t *section)
|
||||
|
||||
else if (section->name == SECTION_PROG_TITLE)
|
||||
{
|
||||
std::vector<std::string> textureList;
|
||||
vector<string> textureList;
|
||||
textureList.push_back("loading_screen_color.png");
|
||||
textureList.push_back("loading_screen_color_zxarne.png");
|
||||
textureList.push_back("smb2.png");
|
||||
@@ -506,7 +506,7 @@ void Director::loadResources(section_t *section)
|
||||
resource->loadTextures(textureList);
|
||||
|
||||
// Offsets
|
||||
std::vector<std::string> offsetsList;
|
||||
vector<string> offsetsList;
|
||||
offsetsList.push_back("smb2.txt");
|
||||
offsetsList.push_back("debug.txt");
|
||||
|
||||
@@ -516,20 +516,20 @@ void Director::loadResources(section_t *section)
|
||||
else if (section->name == SECTION_PROG_CREDITS)
|
||||
{
|
||||
// Texturas
|
||||
std::vector<std::string> textureList;
|
||||
vector<string> textureList;
|
||||
textureList.push_back("shine.png");
|
||||
textureList.push_back("smb2.png");
|
||||
|
||||
resource->loadTextures(textureList);
|
||||
|
||||
// Animaciones
|
||||
std::vector<std::string> animationList;
|
||||
vector<string> animationList;
|
||||
animationList.push_back("shine.ani");
|
||||
|
||||
resource->loadAnimations(animationList);
|
||||
|
||||
// Offsets
|
||||
std::vector<std::string> offsetsList;
|
||||
vector<string> offsetsList;
|
||||
offsetsList.push_back("smb2.txt");
|
||||
|
||||
resource->loadOffsets(offsetsList);
|
||||
@@ -538,7 +538,7 @@ void Director::loadResources(section_t *section)
|
||||
else if (section->name == SECTION_PROG_ENDING)
|
||||
{
|
||||
// Texturas
|
||||
std::vector<std::string> textureList;
|
||||
vector<string> textureList;
|
||||
textureList.push_back("ending1.png");
|
||||
textureList.push_back("ending1_zxarne.png");
|
||||
textureList.push_back("ending2.png");
|
||||
@@ -554,7 +554,7 @@ void Director::loadResources(section_t *section)
|
||||
resource->loadTextures(textureList);
|
||||
|
||||
// Offsets
|
||||
std::vector<std::string> offsetsList;
|
||||
vector<string> offsetsList;
|
||||
offsetsList.push_back("smb2.txt");
|
||||
|
||||
resource->loadOffsets(offsetsList);
|
||||
@@ -563,7 +563,7 @@ void Director::loadResources(section_t *section)
|
||||
else if (section->name == SECTION_PROG_ENDING2)
|
||||
{
|
||||
// Texturas
|
||||
std::vector<std::string> textureList;
|
||||
vector<string> textureList;
|
||||
|
||||
// Texto
|
||||
textureList.push_back("smb2.png");
|
||||
@@ -629,7 +629,7 @@ void Director::loadResources(section_t *section)
|
||||
resource->loadTextures(textureList);
|
||||
|
||||
// Animaciones
|
||||
std::vector<std::string> animationList;
|
||||
vector<string> animationList;
|
||||
|
||||
// Enemigos
|
||||
animationList.push_back("abad.ani");
|
||||
@@ -692,7 +692,7 @@ void Director::loadResources(section_t *section)
|
||||
resource->loadAnimations(animationList);
|
||||
|
||||
// Offsets
|
||||
std::vector<std::string> offsetsList;
|
||||
vector<string> offsetsList;
|
||||
offsetsList.push_back("smb2.txt");
|
||||
|
||||
resource->loadOffsets(offsetsList);
|
||||
@@ -701,7 +701,7 @@ void Director::loadResources(section_t *section)
|
||||
else if (section->name == SECTION_PROG_GAME_OVER)
|
||||
{
|
||||
// Texturas
|
||||
std::vector<std::string> textureList;
|
||||
vector<string> textureList;
|
||||
textureList.push_back("smb2.png");
|
||||
textureList.push_back("player_game_over.png");
|
||||
textureList.push_back("tv.png");
|
||||
@@ -709,14 +709,14 @@ void Director::loadResources(section_t *section)
|
||||
resource->loadTextures(textureList);
|
||||
|
||||
// Animaciones
|
||||
std::vector<std::string> animationList;
|
||||
vector<string> animationList;
|
||||
animationList.push_back("player_game_over.ani");
|
||||
animationList.push_back("tv.ani");
|
||||
|
||||
resource->loadAnimations(animationList);
|
||||
|
||||
// Offsets
|
||||
std::vector<std::string> offsetsList;
|
||||
vector<string> offsetsList;
|
||||
offsetsList.push_back("smb2.txt");
|
||||
|
||||
resource->loadOffsets(offsetsList);
|
||||
@@ -725,7 +725,7 @@ void Director::loadResources(section_t *section)
|
||||
else if (section->name == SECTION_PROG_GAME || section->name == SECTION_PROG_DEMO)
|
||||
{
|
||||
// Texturas
|
||||
std::vector<std::string> textureList;
|
||||
vector<string> textureList;
|
||||
|
||||
// Jugador
|
||||
if (options->cheat.altSkin)
|
||||
@@ -810,7 +810,7 @@ void Director::loadResources(section_t *section)
|
||||
resource->loadTextures(textureList);
|
||||
|
||||
// Animaciones
|
||||
std::vector<std::string> animationList;
|
||||
vector<string> animationList;
|
||||
|
||||
// Jugador
|
||||
if (options->cheat.altSkin)
|
||||
@@ -884,14 +884,14 @@ void Director::loadResources(section_t *section)
|
||||
resource->loadAnimations(animationList);
|
||||
|
||||
// Offsets
|
||||
std::vector<std::string> offsetsList;
|
||||
vector<string> offsetsList;
|
||||
offsetsList.push_back("smb2.txt");
|
||||
offsetsList.push_back("debug.txt");
|
||||
|
||||
resource->loadOffsets(offsetsList);
|
||||
|
||||
// TileMaps
|
||||
std::vector<std::string> tileMapList;
|
||||
vector<string> tileMapList;
|
||||
tileMapList.push_back("01.tmx");
|
||||
tileMapList.push_back("02.tmx");
|
||||
tileMapList.push_back("03.tmx");
|
||||
@@ -956,7 +956,7 @@ void Director::loadResources(section_t *section)
|
||||
resource->loadTileMaps(tileMapList);
|
||||
|
||||
// Habitaciones
|
||||
std::vector<std::string> roomList;
|
||||
vector<string> roomList;
|
||||
roomList.push_back("01.room");
|
||||
roomList.push_back("02.room");
|
||||
roomList.push_back("03.room");
|
||||
@@ -1023,12 +1023,12 @@ void Director::loadResources(section_t *section)
|
||||
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "** RESOURCES LOADED" << std::endl;
|
||||
cout << "** RESOURCES LOADED" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Asigna variables a partir de dos cadenas
|
||||
bool Director::setOptions(options_t *options, std::string var, std::string value)
|
||||
bool Director::setOptions(options_t *options, string var, string value)
|
||||
{
|
||||
// Indicador de éxito en la asignación
|
||||
bool success = true;
|
||||
@@ -1072,7 +1072,7 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
|
||||
|
||||
else if (var == "windowSize")
|
||||
{
|
||||
options->windowSize = std::stoi(value);
|
||||
options->windowSize = stoi(value);
|
||||
if ((options->windowSize < 1) || (options->windowSize > 4))
|
||||
{
|
||||
options->windowSize = 3;
|
||||
@@ -1113,17 +1113,17 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
|
||||
|
||||
else if (var == "borderWidth")
|
||||
{
|
||||
options->borderWidth = std::stoi(value);
|
||||
options->borderWidth = stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "borderHeight")
|
||||
{
|
||||
options->borderHeight = std::stoi(value);
|
||||
options->borderHeight = stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "palette")
|
||||
{
|
||||
const int pal = std::stoi(value);
|
||||
const int pal = stoi(value);
|
||||
|
||||
if (pal == 0)
|
||||
{
|
||||
@@ -1152,7 +1152,7 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
|
||||
{
|
||||
value = "0";
|
||||
}
|
||||
options->online.port = std::stoi(value);
|
||||
options->online.port = stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "jailerID")
|
||||
@@ -1222,7 +1222,6 @@ void Director::initInput()
|
||||
input->bindKey(input_right, SDL_SCANCODE_RIGHT);
|
||||
input->bindKey(input_up, SDL_SCANCODE_UP);
|
||||
input->bindKey(input_down, SDL_SCANCODE_DOWN);
|
||||
|
||||
}
|
||||
else if (options->keys == ctrl_opqa)
|
||||
{
|
||||
@@ -1290,21 +1289,21 @@ bool Director::initSDL()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "SDL could not initialize!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
cout << "SDL could not initialize!\nSDL Error: " << SDL_GetError() << endl;
|
||||
}
|
||||
success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Inicia el generador de numeros aleatorios
|
||||
std::srand(static_cast<unsigned int>(SDL_GetTicks()));
|
||||
srand(static_cast<unsigned int>(SDL_GetTicks()));
|
||||
|
||||
// Establece el filtro de la textura a nearest
|
||||
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(options->filter).c_str()))
|
||||
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, to_string(options->filter).c_str()))
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Warning: Nearest texture filtering not enabled!\n";
|
||||
cout << "Warning: Nearest texture filtering not enabled!\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1322,7 +1321,7 @@ bool Director::initSDL()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Window could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
cout << "Window could not be created!\nSDL Error: " << SDL_GetError() << endl;
|
||||
}
|
||||
success = false;
|
||||
}
|
||||
@@ -1342,7 +1341,7 @@ bool Director::initSDL()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Renderer could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
cout << "Renderer could not be created!\nSDL Error: " << SDL_GetError() << endl;
|
||||
}
|
||||
success = false;
|
||||
}
|
||||
@@ -1362,7 +1361,7 @@ bool Director::initSDL()
|
||||
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << std::endl;
|
||||
cout << endl;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
@@ -1371,9 +1370,9 @@ bool Director::initSDL()
|
||||
bool Director::setFileList()
|
||||
{
|
||||
#ifdef MACOS_BUNDLE
|
||||
const std::string prefix = "/../Resources";
|
||||
const string prefix = "/../Resources";
|
||||
#else
|
||||
const std::string prefix = "";
|
||||
const string prefix = "";
|
||||
#endif
|
||||
|
||||
// Texto
|
||||
@@ -1722,7 +1721,7 @@ void Director::runLogo()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "\n* SECTION: LOGO" << std::endl;
|
||||
cout << "\n* SECTION: LOGO" << endl;
|
||||
}
|
||||
loadResources(section);
|
||||
logo = new Logo(renderer, screen, resource, asset, input, options, section);
|
||||
@@ -1736,7 +1735,7 @@ void Director::runIntro()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "\n* SECTION: INTRO" << std::endl;
|
||||
cout << "\n* SECTION: INTRO" << endl;
|
||||
}
|
||||
loadResources(section);
|
||||
intro = new Intro(renderer, screen, resource, asset, input, options, section);
|
||||
@@ -1750,7 +1749,7 @@ void Director::runTitle()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "\n* SECTION: TITLE" << std::endl;
|
||||
cout << "\n* SECTION: TITLE" << endl;
|
||||
}
|
||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
||||
{
|
||||
@@ -1768,7 +1767,7 @@ void Director::runCredits()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "\n* SECTION: CREDITS" << std::endl;
|
||||
cout << "\n* SECTION: CREDITS" << endl;
|
||||
}
|
||||
loadResources(section);
|
||||
credits = new Credits(renderer, screen, resource, asset, input, options, section);
|
||||
@@ -1782,7 +1781,7 @@ void Director::runDemo()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "\n* SECTION: DEMO" << std::endl;
|
||||
cout << "\n* SECTION: DEMO" << endl;
|
||||
}
|
||||
loadResources(section);
|
||||
demo = new Demo(renderer, screen, resource, asset, input, options, section, debug);
|
||||
@@ -1796,7 +1795,7 @@ void Director::runEnterID()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "\n* SECTION: ENTER_ID" << std::endl;
|
||||
cout << "\n* SECTION: ENTER_ID" << endl;
|
||||
}
|
||||
// loadResources(section);
|
||||
enterID = new EnterID(renderer, screen, asset, options, section);
|
||||
@@ -1810,7 +1809,7 @@ void Director::runEnding()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "\n* SECTION: ENDING" << std::endl;
|
||||
cout << "\n* SECTION: ENDING" << endl;
|
||||
}
|
||||
loadResources(section);
|
||||
ending = new Ending(renderer, screen, resource, asset, input, options, section);
|
||||
@@ -1824,7 +1823,7 @@ void Director::runEnding2()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "\n* SECTION: ENDING2" << std::endl;
|
||||
cout << "\n* SECTION: ENDING2" << endl;
|
||||
}
|
||||
loadResources(section);
|
||||
ending2 = new Ending2(renderer, screen, resource, asset, input, options, section);
|
||||
@@ -1838,7 +1837,7 @@ void Director::runGameOver()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "\n* SECTION: GAME OVER" << std::endl;
|
||||
cout << "\n* SECTION: GAME OVER" << endl;
|
||||
}
|
||||
loadResources(section);
|
||||
gameOver = new GameOver(renderer, screen, resource, asset, input, options, section);
|
||||
@@ -1852,7 +1851,7 @@ void Director::runGame()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "\n* SECTION: GAME" << std::endl;
|
||||
cout << "\n* SECTION: GAME" << endl;
|
||||
}
|
||||
JA_StopMusic();
|
||||
loadResources(section);
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#ifndef DIRECTOR_H
|
||||
#define DIRECTOR_H
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Director
|
||||
{
|
||||
private:
|
||||
@@ -49,9 +51,9 @@ private:
|
||||
section_t *section; // Sección y subsección actual del programa;
|
||||
|
||||
// Variables
|
||||
JA_Music_t *music; // Musica del titulo
|
||||
std::string executablePath; // Path del ejecutable
|
||||
std::string systemFolder; // Carpeta del sistema donde guardar datos
|
||||
JA_Music_t *music; // Musica del titulo
|
||||
string executablePath; // Path del ejecutable
|
||||
string systemFolder; // Carpeta del sistema donde guardar datos
|
||||
|
||||
// Crea e inicializa las opciones del programa
|
||||
void initOptions();
|
||||
@@ -69,13 +71,13 @@ private:
|
||||
bool saveConfig();
|
||||
|
||||
// Crea la carpeta del sistema donde guardar datos
|
||||
void createSystemFolder(std::string folder);
|
||||
void createSystemFolder(string folder);
|
||||
|
||||
// Carga los recursos
|
||||
void loadResources(section_t *section);
|
||||
|
||||
// Asigna variables a partir de dos cadenas
|
||||
bool setOptions(options_t *options, std::string var, std::string value);
|
||||
bool setOptions(options_t *options, string var, string value);
|
||||
|
||||
// Inicializa jail_audio
|
||||
void initJailAudio();
|
||||
|
||||
@@ -45,7 +45,7 @@ Ending::Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Error: canvasTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
cout << "Error: canvasTexture could not be created!\nSDL Error: " << SDL_GetError() << endl;
|
||||
}
|
||||
}
|
||||
SDL_SetTextureBlendMode(coverTexture, SDL_BLENDMODE_BLEND);
|
||||
@@ -140,7 +140,7 @@ void Ending::render()
|
||||
// Dibuja la cortinilla de cambio de escena
|
||||
renderCoverTexture();
|
||||
|
||||
// text->write(0, 0, std::to_string(counter));
|
||||
// text->write(0, 0, to_string(counter));
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
screen->blit();
|
||||
@@ -201,7 +201,7 @@ void Ending::checkInput()
|
||||
void Ending::iniTexts()
|
||||
{
|
||||
// Vector con los textos
|
||||
std::vector<textAndPos_t> texts;
|
||||
vector<textAndPos_t> texts;
|
||||
|
||||
// Escena #0
|
||||
texts.push_back({"HE FINALLY MANAGED", 32});
|
||||
@@ -307,7 +307,7 @@ void Ending::iniTexts()
|
||||
void Ending::iniPics()
|
||||
{
|
||||
// Vector con las rutas y la posición
|
||||
std::vector<textAndPos_t> pics;
|
||||
vector<textAndPos_t> pics;
|
||||
|
||||
if (options->palette == p_zxspectrum)
|
||||
{
|
||||
@@ -605,7 +605,7 @@ void Ending::renderCoverTexture()
|
||||
{
|
||||
if (coverCounter > 0)
|
||||
{ // Dibuja la textura que cubre el texto
|
||||
const int offset = std::min(coverCounter, 100);
|
||||
const int offset = min(coverCounter, 100);
|
||||
SDL_Rect srcRect = {0, 200 - (coverCounter * 2), 256, offset * 2};
|
||||
SDL_Rect dstRect = {0, 0, 256, offset * 2};
|
||||
SDL_RenderCopy(renderer, coverTexture, &srcRect, &dstRect);
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#ifndef ENDING_H
|
||||
#define ENDING_H
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Ending
|
||||
{
|
||||
private:
|
||||
@@ -33,8 +35,8 @@ private:
|
||||
|
||||
struct textAndPos_t // Estructura con un texto y su posición en el eje Y
|
||||
{
|
||||
std::string caption; // Texto
|
||||
int pos; // Posición
|
||||
string caption; // Texto
|
||||
int pos; // Posición
|
||||
};
|
||||
|
||||
struct asdhk
|
||||
@@ -45,9 +47,9 @@ private:
|
||||
|
||||
struct scene_t // Estructura para crear cada una de las escenas del final
|
||||
{
|
||||
std::vector<asdhk> textIndex; // Indices del vector de textos a mostrar y su disparador
|
||||
int pictureIndex; // Indice del vector de imagenes a mostrar
|
||||
int counterEnd; // Valor del contador en el que finaliza la escena
|
||||
vector<asdhk> textIndex; // Indices del vector de textos a mostrar y su disparador
|
||||
int pictureIndex; // Indice del vector de imagenes a mostrar
|
||||
int counterEnd; // Valor del contador en el que finaliza la escena
|
||||
};
|
||||
|
||||
// Objetos y punteros
|
||||
@@ -63,16 +65,16 @@ private:
|
||||
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
||||
|
||||
// Variables
|
||||
int counter; // Contador
|
||||
int preCounter; // Contador previo
|
||||
int coverCounter; // Contador para la cortinilla
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
std::vector<endingTexture_t> spriteTexts; // Vector con los sprites de texto con su cortinilla
|
||||
std::vector<endingTexture_t> spritePics; // Vector con los sprites de texto con su cortinilla
|
||||
int scene; // Escena actual
|
||||
std::vector<scene_t> scenes; // Vector con los textos e imagenes de cada escena
|
||||
JA_Music_t *music; // Musica que suena durante el final
|
||||
int counter; // Contador
|
||||
int preCounter; // Contador previo
|
||||
int coverCounter; // Contador para la cortinilla
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
vector<endingTexture_t> spriteTexts; // Vector con los sprites de texto con su cortinilla
|
||||
vector<endingTexture_t> spritePics; // Vector con los sprites de texto con su cortinilla
|
||||
int scene; // Escena actual
|
||||
vector<scene_t> scenes; // Vector con los textos e imagenes de cada escena
|
||||
JA_Music_t *music; // Musica que suena durante el final
|
||||
|
||||
// Actualiza el objeto
|
||||
void update();
|
||||
|
||||
@@ -34,7 +34,7 @@ Ending2::Ending2(SDL_Renderer *renderer, Screen *screen, Resource *resource, Ass
|
||||
secondCol = GAMECANVAS_THIRD_QUARTER_X - (GAMECANVAS_WIDTH / 16);
|
||||
|
||||
// Inicializa el vector de colores
|
||||
const std::vector<std::string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
|
||||
const vector<string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
|
||||
for (auto cl : colorList)
|
||||
{
|
||||
colors.push_back(stringToColor(options->palette, cl));
|
||||
@@ -131,7 +131,7 @@ void Ending2::render()
|
||||
// Dibuja los sprites con el texto del final
|
||||
renderTexts();
|
||||
|
||||
const std::string txt = std::to_string(postCounter);
|
||||
const string txt = to_string(postCounter);
|
||||
// text->write(0, 192 - 8, txt);
|
||||
|
||||
// Dibuja la cuadricula
|
||||
@@ -363,8 +363,8 @@ void Ending2::loadSprites()
|
||||
for (auto sl : spriteList)
|
||||
{
|
||||
sprites.push_back(new AnimatedSprite(renderer, resource->getAnimation(sl + ".ani")));
|
||||
maxSpriteWidth = std::max(sprites.back()->getAnimationClip(0, 0).w, maxSpriteWidth);
|
||||
maxSpriteHeight = std::max(sprites.back()->getAnimationClip(0, 0).h, maxSpriteHeight);
|
||||
maxSpriteWidth = max(sprites.back()->getAnimationClip(0, 0).w, maxSpriteWidth);
|
||||
maxSpriteHeight = max(sprites.back()->getAnimationClip(0, 0).h, maxSpriteHeight);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -488,8 +488,8 @@ void Ending2::createSpriteTexts()
|
||||
for (int i = 0; i < (int)spriteList.size(); ++i)
|
||||
{
|
||||
// Calcula constantes
|
||||
std::string txt = spriteList[i];
|
||||
std::replace(txt.begin(), txt.end(), '_', ' ');
|
||||
string txt = spriteList[i];
|
||||
replace(txt.begin(), txt.end(), '_', ' ');
|
||||
txt = txt == "player" ? "JAILDOCTOR" : txt; // Reemplaza el texto
|
||||
const int w = text->lenght(txt, 1);
|
||||
const int h = text->getCharacterSize();
|
||||
@@ -520,7 +520,7 @@ void Ending2::createTexts()
|
||||
deleteTexts();
|
||||
|
||||
// Crea los primeros textos
|
||||
std::vector<std::string> list;
|
||||
vector<string> list;
|
||||
list.push_back("STARRING");
|
||||
|
||||
// Crea los sprites de texto a partir de la lista
|
||||
@@ -610,7 +610,7 @@ void Ending2::deleteTexts()
|
||||
void Ending2::updateFinalFade()
|
||||
{
|
||||
// La variable step va de 0 a 40 en el tramo de postCounter que va de 500 a 540. Al dividirlo por 40, va de 0.0f a 1.0f
|
||||
const float step = std::min(std::max(postCounter, 500) - 500, 40) / 40.0f;
|
||||
const float step = min(max(postCounter, 500) - 500, 40) / 40.0f;
|
||||
const int index = (colors.size() - 1) * step;
|
||||
|
||||
for (auto t : texts)
|
||||
|
||||
@@ -17,40 +17,42 @@
|
||||
#ifndef ENDING2_H
|
||||
#define ENDING2_H
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Ending2
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
Asset *asset; // Objeto con los ficheros de recursos
|
||||
Resource *resource; // Objeto con los recursos
|
||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||
SDL_Event *eventHandler; // Manejador de eventos
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Input *input; // Objeto pata gestionar la entrada
|
||||
Text *text; // Objeto para escribir texto en pantalla
|
||||
options_t *options; // Puntero a las opciones del juego
|
||||
std::vector<AnimatedSprite *> sprites; // Vector con todos los sprites a dibujar
|
||||
std::vector<MovingSprite *> spriteTexts; // Vector con los sprites de texto de los sprites
|
||||
std::vector<MovingSprite *> texts; // Vector con los sprites de texto
|
||||
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
||||
Asset *asset; // Objeto con los ficheros de recursos
|
||||
Resource *resource; // Objeto con los recursos
|
||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||
SDL_Event *eventHandler; // Manejador de eventos
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Input *input; // Objeto pata gestionar la entrada
|
||||
Text *text; // Objeto para escribir texto en pantalla
|
||||
options_t *options; // Puntero a las opciones del juego
|
||||
vector<AnimatedSprite *> sprites; // Vector con todos los sprites a dibujar
|
||||
vector<MovingSprite *> spriteTexts; // Vector con los sprites de texto de los sprites
|
||||
vector<MovingSprite *> texts; // Vector con los sprites de texto
|
||||
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
||||
|
||||
// Variables
|
||||
bool counterEnabled; // Indica si está el contador habilitado
|
||||
int preCounter; // Contador previo
|
||||
int postCounter; // Contador posterior
|
||||
bool postCounterEnabled; // Indica si está habilitado el contador
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
JA_Music_t *music; // Musica que suena durante el final
|
||||
std::vector<std::string> spriteList; // Lista con todos los sprites a dibujar
|
||||
std::vector<color_t> colors; // Vector con los colores para el fade
|
||||
int maxSpriteWidth; // El valor de ancho del sprite mas ancho
|
||||
int maxSpriteHeight; // El valor de alto del sprite mas alto
|
||||
int distSpriteText; // Distancia entre el sprite y el texto que lo acompaña
|
||||
int distSpriteSprite; // Distancia entre dos sprites de la misma columna
|
||||
float despSpeed; // Velocidad de desplazamiento de los sprites
|
||||
int firstCol; // Primera columna por donde desfilan los sprites
|
||||
int secondCol; // Segunda columna por donde desfilan los sprites
|
||||
bool counterEnabled; // Indica si está el contador habilitado
|
||||
int preCounter; // Contador previo
|
||||
int postCounter; // Contador posterior
|
||||
bool postCounterEnabled; // Indica si está habilitado el contador
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
JA_Music_t *music; // Musica que suena durante el final
|
||||
vector<string> spriteList; // Lista con todos los sprites a dibujar
|
||||
vector<color_t> colors; // Vector con los colores para el fade
|
||||
int maxSpriteWidth; // El valor de ancho del sprite mas ancho
|
||||
int maxSpriteHeight; // El valor de alto del sprite mas alto
|
||||
int distSpriteText; // Distancia entre el sprite y el texto que lo acompaña
|
||||
int distSpriteSprite; // Distancia entre dos sprites de la misma columna
|
||||
float despSpeed; // Velocidad de desplazamiento de los sprites
|
||||
int firstCol; // Primera columna por donde desfilan los sprites
|
||||
int secondCol; // Segunda columna por donde desfilan los sprites
|
||||
|
||||
// Actualiza el objeto
|
||||
void update();
|
||||
|
||||
@@ -40,7 +40,7 @@ Enemy::Enemy(enemy_t enemy)
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite->setCurrentFrame(std::min(enemy.frame, sprite->getNumFrames() - 1));
|
||||
sprite->setCurrentFrame(min(enemy.frame, sprite->getNumFrames() - 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,12 +9,14 @@
|
||||
#ifndef ENEMY_H
|
||||
#define ENEMY_H
|
||||
|
||||
using namespace std;
|
||||
|
||||
// Estructura para pasar los datos de un enemigo
|
||||
struct enemy_t
|
||||
{
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
animatedSprite_t *animation; // Puntero a las animaciones del enemigo
|
||||
std::string animationString; // Ruta al fichero con la animación
|
||||
string animationString; // Ruta al fichero con la animación
|
||||
int w; // Anchura del enemigo
|
||||
int h; // Altura del enemigo
|
||||
float x; // Posición inicial en el eje X
|
||||
@@ -28,7 +30,7 @@ struct enemy_t
|
||||
bool flip; // Indica si el enemigo hace flip al terminar su ruta
|
||||
bool mirror; // Indica si el enemigo está volteado verticalmente
|
||||
int frame; // Frame inicial para la animación del enemigo
|
||||
std::string color; // Color del enemigo
|
||||
string color; // Color del enemigo
|
||||
palette_e palette; // Paleta de colores
|
||||
};
|
||||
|
||||
@@ -39,16 +41,16 @@ private:
|
||||
AnimatedSprite *sprite; // Sprite del enemigo
|
||||
|
||||
// Variables
|
||||
color_t color; // Color del enemigo
|
||||
std::string colorString; // Color del enemigo en formato texto
|
||||
palette_e palette; // Paleta de colores
|
||||
int x1; // Limite izquierdo de la ruta en el eje X
|
||||
int x2; // Limite derecho de la ruta en el eje X
|
||||
int y1; // Limite superior de la ruta en el eje Y
|
||||
int y2; // Limite inferior de la ruta en el eje Y
|
||||
SDL_Rect collider; // Caja de colisión
|
||||
bool doFlip; // Indica si el enemigo hace flip al terminar su ruta
|
||||
bool mirror; // Indica si el enemigo se dibuja volteado verticalmente
|
||||
color_t color; // Color del enemigo
|
||||
string colorString; // Color del enemigo en formato texto
|
||||
palette_e palette; // Paleta de colores
|
||||
int x1; // Limite izquierdo de la ruta en el eje X
|
||||
int x2; // Limite derecho de la ruta en el eje X
|
||||
int y1; // Limite superior de la ruta en el eje Y
|
||||
int y2; // Limite inferior de la ruta en el eje Y
|
||||
SDL_Rect collider; // Caja de colisión
|
||||
bool doFlip; // Indica si el enemigo hace flip al terminar su ruta
|
||||
bool mirror; // Indica si el enemigo se dibuja volteado verticalmente
|
||||
|
||||
// Comprueba si ha llegado al limite del recorrido para darse media vuelta
|
||||
void checkPath();
|
||||
|
||||
@@ -25,7 +25,7 @@ EnterID::EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << endl;
|
||||
}
|
||||
}
|
||||
SDL_SetTextureBlendMode(textTexture, SDL_BLENDMODE_BLEND);
|
||||
@@ -90,7 +90,7 @@ void EnterID::checkEventHandler()
|
||||
{
|
||||
if (eventHandler->key.keysym.scancode == SDL_SCANCODE_RETURN)
|
||||
{
|
||||
options->online.jailerID = (std::string)name;
|
||||
options->online.jailerID = (string)name;
|
||||
endSection();
|
||||
break;
|
||||
}
|
||||
@@ -206,7 +206,7 @@ void EnterID::render()
|
||||
SDL_RenderCopy(renderer, textTexture, nullptr, nullptr);
|
||||
|
||||
// Escribe el jailerID
|
||||
const std::string jailerID = (std::string)name + cursor;
|
||||
const string jailerID = (string)name + cursor;
|
||||
const color_t color = stringToColor(options->palette, "white");
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, (16 * 8 + 1), jailerID, 1, color);
|
||||
|
||||
@@ -296,14 +296,14 @@ void EnterID::initOnline()
|
||||
jscore::init(options->online.server, options->online.port);
|
||||
|
||||
#ifdef DEBUG
|
||||
const std::string caption = "IS LOGGED IN (DEBUG)";
|
||||
const string caption = "IS LOGGED IN (DEBUG)";
|
||||
#else
|
||||
const std::string caption = "IS LOGGED IN";
|
||||
const string caption = "IS LOGGED IN";
|
||||
#endif
|
||||
screen->showNotification(options->online.jailerID, caption, 12);
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << caption << std::endl;
|
||||
cout << caption << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,15 +9,17 @@
|
||||
#include <vector>
|
||||
|
||||
#ifndef ENTER_ID_H
|
||||
#define ASK_ME_H
|
||||
#define ENTER_ID_H
|
||||
|
||||
using namespace std;
|
||||
|
||||
class EnterID
|
||||
{
|
||||
private:
|
||||
struct captions_t
|
||||
{
|
||||
std::string label; // Texto a escribir
|
||||
color_t color; // Color del texto
|
||||
string label; // Texto a escribir
|
||||
color_t color; // Color del texto
|
||||
};
|
||||
|
||||
// Punteros y objetos
|
||||
@@ -32,11 +34,11 @@ private:
|
||||
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
||||
|
||||
// Variables
|
||||
int counter; // Contador
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
std::vector<captions_t> texts; // Vector con los textos
|
||||
std::string cursor; // Contiene el caracter que se muestra como cursor
|
||||
int counter; // Contador
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
vector<captions_t> texts; // Vector con los textos
|
||||
string cursor; // Contiene el caracter que se muestra como cursor
|
||||
|
||||
char name[15];
|
||||
int pos;
|
||||
|
||||
@@ -35,8 +35,8 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
||||
itemTracker = new ItemTracker();
|
||||
roomTracker = new RoomTracker();
|
||||
room = new Room(resource->getRoom(currentRoom), renderer, screen, asset, options, itemTracker, &board.items, false, debug);
|
||||
const std::string playerPNG = options->cheat.altSkin ? "player2.png" : "player.png";
|
||||
const std::string playerANI = options->cheat.altSkin ? "player2.ani" : "player.ani";
|
||||
const string playerPNG = options->cheat.altSkin ? "player2.png" : "player.png";
|
||||
const string playerANI = options->cheat.altSkin ? "player2.ani" : "player.ani";
|
||||
const player_t player = {spawnPoint, playerPNG, playerANI, renderer, resource, asset, options, input, room, debug};
|
||||
this->player = new Player(player);
|
||||
eventHandler = new SDL_Event();
|
||||
@@ -51,7 +51,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Error: roomNameTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
cout << "Error: roomNameTexture could not be created!\nSDL Error: " << SDL_GetError() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,9 +322,9 @@ void Game::render()
|
||||
// Pasa la información de debug
|
||||
void Game::updateDebugInfo()
|
||||
{
|
||||
debug->add("X = " + std::to_string((int)player->x) + ", Y = " + std::to_string((int)player->y));
|
||||
debug->add("VX = " + std::to_string(player->vx).substr(0, 4) + ", VY = " + std::to_string(player->vy).substr(0, 4));
|
||||
debug->add("STATE = " + std::to_string(player->state));
|
||||
debug->add("X = " + to_string((int)player->x) + ", Y = " + to_string((int)player->y));
|
||||
debug->add("VX = " + to_string(player->vx).substr(0, 4) + ", VY = " + to_string(player->vy).substr(0, 4));
|
||||
debug->add("STATE = " + to_string(player->state));
|
||||
}
|
||||
|
||||
// Pone la información de debug en pantalla
|
||||
@@ -365,7 +365,7 @@ void Game::renderRoomName()
|
||||
}
|
||||
|
||||
// Cambia de habitación
|
||||
bool Game::changeRoom(std::string file)
|
||||
bool Game::changeRoom(string file)
|
||||
{
|
||||
// En las habitaciones los limites tienen la cadena del fichero o un 0 en caso de no limitar con nada
|
||||
if (file == "0")
|
||||
@@ -413,7 +413,7 @@ void Game::checkPlayerOnBorder()
|
||||
{
|
||||
if (player->getOnBorder())
|
||||
{
|
||||
const std::string roomName = room->getRoom(player->getBorder());
|
||||
const string roomName = room->getRoom(player->getBorder());
|
||||
if (changeRoom(roomName))
|
||||
{
|
||||
player->switchBorders();
|
||||
@@ -490,8 +490,8 @@ void Game::killPlayer()
|
||||
|
||||
// Crea la nueva habitación y el nuevo jugador
|
||||
room = new Room(resource->getRoom(currentRoom), renderer, screen, asset, options, itemTracker, &board.items, board.jailEnabled, debug);
|
||||
const std::string playerPNG = options->cheat.altSkin ? "player2.png" : "player.png";
|
||||
const std::string playerANI = options->cheat.altSkin ? "player2.ani" : "player.ani";
|
||||
const string playerPNG = options->cheat.altSkin ? "player2.png" : "player.png";
|
||||
const string playerANI = options->cheat.altSkin ? "player2.ani" : "player.ani";
|
||||
const player_t player = {spawnPoint, playerPNG, playerANI, renderer, resource, asset, options, input, room, debug};
|
||||
this->player = new Player(player);
|
||||
|
||||
@@ -505,7 +505,7 @@ void Game::reLoadTextures()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "** RELOAD REQUESTED" << std::endl;
|
||||
cout << "** RELOAD REQUESTED" << endl;
|
||||
}
|
||||
player->reLoadTexture();
|
||||
room->reLoadTexture();
|
||||
@@ -518,7 +518,7 @@ void Game::switchPalette()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "** PALETTE SWITCH REQUESTED" << std::endl;
|
||||
cout << "** PALETTE SWITCH REQUESTED" << endl;
|
||||
}
|
||||
|
||||
// Modifica la variable
|
||||
@@ -608,7 +608,7 @@ bool Game::checkEndGame()
|
||||
int Game::getTotalItems()
|
||||
{
|
||||
int items = 0;
|
||||
std::vector<res_room_t> *rooms = new std::vector<res_room_t>;
|
||||
vector<res_room_t> *rooms = new vector<res_room_t>;
|
||||
rooms = resource->getAllRooms();
|
||||
|
||||
for (auto room : *rooms)
|
||||
@@ -622,7 +622,7 @@ int Game::getTotalItems()
|
||||
// Va a la habitación designada
|
||||
void Game::goToRoom(int border)
|
||||
{
|
||||
const std::string roomName = room->getRoom(border);
|
||||
const string roomName = room->getRoom(border);
|
||||
if (changeRoom(roomName))
|
||||
{
|
||||
currentRoom = roomName;
|
||||
@@ -682,7 +682,7 @@ void Game::checkRestoringJail()
|
||||
// Inicializa el diccionario de las estadísticas
|
||||
void Game::initStats()
|
||||
{
|
||||
std::vector<res_room_t> *rooms = new std::vector<res_room_t>;
|
||||
vector<res_room_t> *rooms = new vector<res_room_t>;
|
||||
rooms = resource->getAllRooms();
|
||||
|
||||
for (auto room : *rooms)
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#ifndef GAME_H
|
||||
#define GAME_H
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Game
|
||||
{
|
||||
private:
|
||||
@@ -50,7 +52,7 @@ private:
|
||||
JA_Music_t *music; // Musica que suena durante el juego
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
std::string currentRoom; // Fichero de la habitación actual
|
||||
string currentRoom; // Fichero de la habitación actual
|
||||
playerSpawn_t spawnPoint; // Lugar de la habitación donde aparece el jugador
|
||||
JA_Sound_t *deathSound; // Sonido a reproducir cuando muere el jugador
|
||||
board_t board; // Estructura con los datos del marcador
|
||||
@@ -81,7 +83,7 @@ private:
|
||||
void renderRoomName();
|
||||
|
||||
// Cambia de habitación
|
||||
bool changeRoom(std::string file);
|
||||
bool changeRoom(string file);
|
||||
|
||||
// Comprueba el teclado
|
||||
void checkInput();
|
||||
|
||||
@@ -35,7 +35,7 @@ GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, A
|
||||
tvSprite->setPosY(30);
|
||||
|
||||
// Inicializa el vector de colores
|
||||
const std::vector<std::string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
|
||||
const vector<string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
|
||||
for (auto cl : colorList)
|
||||
{
|
||||
colors.push_back(stringToColor(options->palette, cl));
|
||||
@@ -104,8 +104,8 @@ void GameOver::render()
|
||||
renderSprites();
|
||||
|
||||
// Escribe el texto con las habitaciones y los items
|
||||
const std::string itemsTxt = std::to_string(options->stats.items / 100) + std::to_string((options->stats.items % 100) / 10) + std::to_string(options->stats.items % 10);
|
||||
const std::string roomsTxt = std::to_string(options->stats.rooms / 100) + std::to_string((options->stats.rooms % 100) / 10) + std::to_string(options->stats.rooms % 10);
|
||||
const string itemsTxt = to_string(options->stats.items / 100) + to_string((options->stats.items % 100) / 10) + to_string(options->stats.items % 10);
|
||||
const string roomsTxt = to_string(options->stats.rooms / 100) + to_string((options->stats.rooms % 100) / 10) + to_string(options->stats.rooms % 10);
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 80, "ITEMS: " + itemsTxt, 1, color);
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 90, "ROOMS: " + roomsTxt, 1, color);
|
||||
|
||||
@@ -185,13 +185,13 @@ void GameOver::updateColor()
|
||||
|
||||
if (counter < half)
|
||||
{
|
||||
const float step = std::min(counter, fadeLenght) / (float)fadeLenght;
|
||||
const float step = min(counter, fadeLenght) / (float)fadeLenght;
|
||||
const int index = (colors.size() - 1) - int((colors.size() - 1) * step);
|
||||
color = colors[index];
|
||||
}
|
||||
else
|
||||
{
|
||||
const float step = std::min(std::max(counter, iniFade) - iniFade, fadeLenght) / (float)fadeLenght;
|
||||
const float step = min(max(counter, iniFade) - iniFade, fadeLenght) / (float)fadeLenght;
|
||||
const int index = (colors.size() - 1) * step;
|
||||
color = colors[index];
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#ifndef GAME_OVER_H
|
||||
#define GAME_OVER_H
|
||||
|
||||
using namespace std;
|
||||
|
||||
class GameOver
|
||||
{
|
||||
private:
|
||||
@@ -33,16 +35,16 @@ private:
|
||||
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
||||
|
||||
// Variables
|
||||
int preCounter; // Contador previo
|
||||
int counter; // Contador
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
std::vector<color_t> colors; // Vector con los colores para el fade
|
||||
color_t color; // Color usado para el texto y los sprites
|
||||
int endSection; // Contador: cuando acaba la sección
|
||||
int iniFade; // Contador: cuando emiepza el fade
|
||||
int fadeLenght; // Contador: duración del fade
|
||||
JA_Music_t *music; // Musica que suena durante el juego
|
||||
int preCounter; // Contador previo
|
||||
int counter; // Contador
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
vector<color_t> colors; // Vector con los colores para el fade
|
||||
color_t color; // Color usado para el texto y los sprites
|
||||
int endSection; // Contador: cuando acaba la sección
|
||||
int iniFade; // Contador: cuando emiepza el fade
|
||||
int fadeLenght; // Contador: duración del fade
|
||||
JA_Music_t *music; // Musica que suena durante el juego
|
||||
|
||||
// Actualiza el objeto
|
||||
void update();
|
||||
|
||||
@@ -9,17 +9,19 @@
|
||||
#ifndef ITEM_H
|
||||
#define ITEM_H
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct item_t
|
||||
{
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Texture *texture; // Textura con los graficos del item
|
||||
std::string tileSetFile; // Ruta al fichero con los graficos del item
|
||||
int x; // Posicion del item en pantalla
|
||||
int y; // Posicion del item en pantalla
|
||||
int tile; // Numero de tile dentro de la textura
|
||||
int counter; // Contador inicial. Es el que lo hace cambiar de color
|
||||
color_t color1; // Uno de los dos colores que se utiliza para el item
|
||||
color_t color2; // Uno de los dos colores que se utiliza para el item
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Texture *texture; // Textura con los graficos del item
|
||||
string tileSetFile; // Ruta al fichero con los graficos del item
|
||||
int x; // Posicion del item en pantalla
|
||||
int y; // Posicion del item en pantalla
|
||||
int tile; // Numero de tile dentro de la textura
|
||||
int counter; // Contador inicial. Es el que lo hace cambiar de color
|
||||
color_t color1; // Uno de los dos colores que se utiliza para el item
|
||||
color_t color2; // Uno de los dos colores que se utiliza para el item
|
||||
};
|
||||
|
||||
class Item
|
||||
@@ -29,10 +31,10 @@ private:
|
||||
Sprite *sprite; // Sprite del objeto
|
||||
|
||||
// Variables
|
||||
std::vector<color_t> color; // Vector con los colores del objeto
|
||||
int counter; // Contador interno
|
||||
SDL_Rect collider; // Rectangulo de colisión
|
||||
int colorChangeSpeed; // Cuanto mas alto, mas tarda en cambiar de color
|
||||
vector<color_t> color; // Vector con los colores del objeto
|
||||
int counter; // Contador interno
|
||||
SDL_Rect collider; // Rectangulo de colisión
|
||||
int colorChangeSpeed; // Cuanto mas alto, mas tarda en cambiar de color
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
|
||||
@@ -7,7 +7,7 @@ ItemTracker::~ItemTracker()
|
||||
}
|
||||
|
||||
// Comprueba si el objeto ya ha sido cogido
|
||||
bool ItemTracker::hasBeenPicked(std::string name, SDL_Point pos)
|
||||
bool ItemTracker::hasBeenPicked(string name, SDL_Point pos)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
@@ -26,7 +26,7 @@ bool ItemTracker::hasBeenPicked(std::string name, SDL_Point pos)
|
||||
}
|
||||
|
||||
// Añade el objeto a la lista de objetos cogidos
|
||||
void ItemTracker::addItem(std::string name, SDL_Point pos)
|
||||
void ItemTracker::addItem(string name, SDL_Point pos)
|
||||
{
|
||||
// Comprueba si el objeto no ha sido recogido con anterioridad
|
||||
if (!hasBeenPicked(name, pos))
|
||||
@@ -50,7 +50,7 @@ void ItemTracker::addItem(std::string name, SDL_Point pos)
|
||||
}
|
||||
|
||||
// Busca una entrada en la lista por nombre
|
||||
int ItemTracker::findByName(std::string name)
|
||||
int ItemTracker::findByName(string name)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
@@ -71,7 +71,7 @@ int ItemTracker::findByPos(int index, SDL_Point pos)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (auto l:list[index].pos)
|
||||
for (auto l : list[index].pos)
|
||||
{
|
||||
if ((l.x == pos.x) && (l.y == pos.y))
|
||||
{
|
||||
|
||||
@@ -7,20 +7,22 @@
|
||||
#ifndef ITEM_TRACKER_H
|
||||
#define ITEM_TRACKER_H
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct item_tracker_t
|
||||
{
|
||||
std::string name; // Nombre de la habitación donde se encuentra el objeto
|
||||
std::vector<SDL_Point> pos; // Lista de objetos cogidos de la habitación
|
||||
string name; // Nombre de la habitación donde se encuentra el objeto
|
||||
vector<SDL_Point> pos; // Lista de objetos cogidos de la habitación
|
||||
};
|
||||
|
||||
class ItemTracker
|
||||
{
|
||||
private:
|
||||
// Variables
|
||||
std::vector<item_tracker_t> list; // Lista con todos los objetos recogidos
|
||||
vector<item_tracker_t> list; // Lista con todos los objetos recogidos
|
||||
|
||||
// Busca una entrada en la lista por nombre
|
||||
int findByName(std::string name);
|
||||
int findByName(string name);
|
||||
|
||||
// Busca una entrada en la lista por posición
|
||||
int findByPos(int index, SDL_Point pos);
|
||||
@@ -30,10 +32,10 @@ public:
|
||||
~ItemTracker();
|
||||
|
||||
// Comprueba si el objeto ya ha sido cogido
|
||||
bool hasBeenPicked(std::string name, SDL_Point pos);
|
||||
bool hasBeenPicked(string name, SDL_Point pos);
|
||||
|
||||
// Añade el objeto a la lista de objetos cogidos
|
||||
void addItem(std::string name, SDL_Point pos);
|
||||
void addItem(string name, SDL_Point pos);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -47,7 +47,7 @@ Logo::Logo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
||||
postLogo = 20;
|
||||
|
||||
// Inicializa el vector de colores
|
||||
const std::vector<std::string> vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"};
|
||||
const vector<string> vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"};
|
||||
for (auto v : vColors)
|
||||
{
|
||||
color.push_back(stringToColor(options->palette, v));
|
||||
|
||||
@@ -14,31 +14,33 @@
|
||||
#ifndef LOGO_H
|
||||
#define LOGO_H
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Logo
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||
Resource *resource; // Objeto con los recursos
|
||||
Asset *asset; // Objeto con los ficheros de recursos
|
||||
Input *input; // Objeto pata gestionar la entrada
|
||||
Texture *texture; // Textura con los graficos "JAILGAMES"
|
||||
Texture *texture2; // Textura con los graficos "Since 1998"
|
||||
SDL_Event *eventHandler; // Manejador de eventos
|
||||
std::vector<Sprite *> sprite; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
|
||||
Sprite *sprite2; // Sprite para manejar la textura2
|
||||
options_t *options; // Puntero a las opciones del juego
|
||||
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||
Resource *resource; // Objeto con los recursos
|
||||
Asset *asset; // Objeto con los ficheros de recursos
|
||||
Input *input; // Objeto pata gestionar la entrada
|
||||
Texture *texture; // Textura con los graficos "JAILGAMES"
|
||||
Texture *texture2; // Textura con los graficos "Since 1998"
|
||||
SDL_Event *eventHandler; // Manejador de eventos
|
||||
vector<Sprite *> sprite; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
|
||||
Sprite *sprite2; // Sprite para manejar la textura2
|
||||
options_t *options; // Puntero a las opciones del juego
|
||||
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
||||
|
||||
// Variables
|
||||
std::vector<color_t> color; // Vector con los colores para el fade
|
||||
int counter; // Contador
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
int initFade; // Tiempo del contador cuando inicia el fade a negro
|
||||
int endLogo; // Tiempo del contador para terminar el logo
|
||||
int postLogo; // Tiempo que dura el logo con el fade al maximo
|
||||
vector<color_t> color; // Vector con los colores para el fade
|
||||
int counter; // Contador
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
int initFade; // Tiempo del contador cuando inicia el fade a negro
|
||||
int endLogo; // Tiempo del contador para terminar el logo
|
||||
int postLogo; // Tiempo que dura el logo con el fade al maximo
|
||||
|
||||
// Actualiza las variables
|
||||
void update();
|
||||
|
||||
@@ -533,7 +533,7 @@ void Player::move()
|
||||
#endif
|
||||
|
||||
// Comprueba la colisión con las superficies normales y las automáticas
|
||||
const int pos = std::max(room->checkTopSurfaces(&proj), room->checkAutoSurfaces(&proj));
|
||||
const int pos = max(room->checkTopSurfaces(&proj), room->checkAutoSurfaces(&proj));
|
||||
if (pos > -1)
|
||||
{ // Si hay colisión lo mueve hasta donde no colisiona y pasa a estar sobre la superficie
|
||||
y = pos - h;
|
||||
@@ -548,7 +548,7 @@ void Player::move()
|
||||
{ // Las rampas no se miran si se está saltando
|
||||
v_line_t leftSide = {proj.x, proj.y, proj.y + proj.h - 1};
|
||||
v_line_t rightSide = {proj.x + proj.w - 1, proj.y, proj.y + proj.h - 1};
|
||||
const int p = std::max(room->checkRightSlopes(&rightSide), room->checkLeftSlopes(&leftSide));
|
||||
const int p = max(room->checkRightSlopes(&rightSide), room->checkLeftSlopes(&leftSide));
|
||||
if (p > -1)
|
||||
{ // No está saltando y hay colisión con una rampa
|
||||
// Calcula la nueva posición
|
||||
@@ -581,8 +581,8 @@ void Player::move()
|
||||
sprite->setPosY(y);
|
||||
|
||||
#ifdef DEBUG
|
||||
debug->add("RECT_X: " + std::to_string(rx.x) + "," + std::to_string(rx.y) + "," + std::to_string(rx.w) + "," + std::to_string(rx.h));
|
||||
debug->add("RECT_Y: " + std::to_string(ry.x) + "," + std::to_string(ry.y) + "," + std::to_string(ry.w) + "," + std::to_string(ry.h));
|
||||
debug->add("RECT_X: " + to_string(rx.x) + "," + to_string(rx.y) + "," + to_string(rx.w) + "," + to_string(rx.h));
|
||||
debug->add("RECT_Y: " + to_string(ry.x) + "," + to_string(ry.y) + "," + to_string(ry.w) + "," + to_string(ry.h));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -621,7 +621,7 @@ void Player::playJumpSound()
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
debug->add("JUMP: " + std::to_string(jumpCounter / 4));
|
||||
debug->add("JUMP: " + to_string(jumpCounter / 4));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -630,11 +630,11 @@ void Player::playFallSound()
|
||||
{
|
||||
if (fallCounter % 4 == 0)
|
||||
{
|
||||
JA_PlaySound(fallSound[std::min((fallCounter / 4), (int)fallSound.size() - 1)]);
|
||||
JA_PlaySound(fallSound[min((fallCounter / 4), (int)fallSound.size() - 1)]);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
debug->add("FALL: " + std::to_string(fallCounter / 4));
|
||||
debug->add("FALL: " + to_string(fallCounter / 4));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -666,12 +666,12 @@ bool Player::isOnFloor()
|
||||
|
||||
if (onSlopeL)
|
||||
{
|
||||
debug->add("ON_SLOPE_L: " + std::to_string(underFeet[0].x) + "," + std::to_string(underFeet[0].y));
|
||||
debug->add("ON_SLOPE_L: " + to_string(underFeet[0].x) + "," + to_string(underFeet[0].y));
|
||||
}
|
||||
|
||||
if (onSlopeR)
|
||||
{
|
||||
debug->add("ON_SLOPE_R: " + std::to_string(underFeet[1].x) + "," + std::to_string(underFeet[1].y));
|
||||
debug->add("ON_SLOPE_R: " + to_string(underFeet[1].x) + "," + to_string(underFeet[1].y));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#ifndef PLAYER_H
|
||||
#define PLAYER_H
|
||||
|
||||
using namespace std;
|
||||
|
||||
enum state_e
|
||||
{
|
||||
s_standing,
|
||||
@@ -36,8 +38,8 @@ struct playerSpawn_t
|
||||
struct player_t
|
||||
{
|
||||
playerSpawn_t spawn;
|
||||
std::string png;
|
||||
std::string animation;
|
||||
string png;
|
||||
string animation;
|
||||
SDL_Renderer *renderer;
|
||||
Resource *resource;
|
||||
Asset *asset;
|
||||
@@ -61,32 +63,32 @@ public:
|
||||
options_t *options; // Puntero a las opciones del juego
|
||||
|
||||
// Variables
|
||||
float x; // Posición del jugador en el eje X
|
||||
float y; // Posición del jugador en el eje Y
|
||||
float vx; // Velocidad/desplazamiento del jugador en el eje X
|
||||
float vy; // Velocidad/desplazamiento del jugador en el eje Y
|
||||
int w; // Ancho del jugador
|
||||
int h; // ALto del jugador
|
||||
color_t color; // Color del jugador
|
||||
SDL_Rect colliderBox; // Caja de colisión con los enemigos u objetos
|
||||
std::vector<SDL_Point> colliderPoints; // Puntos de colisión con el mapa
|
||||
std::vector<SDL_Point> underFeet; // Contiene los puntos que hay bajo cada pie del jugador
|
||||
std::vector<SDL_Point> feet; // Contiene los puntos que hay en el pie del jugador
|
||||
state_e state; // Estado en el que se encuentra el jugador. Util apara saber si está saltando o cayendo
|
||||
state_e prevState; // Estado previo en el que se encontraba el jugador
|
||||
bool onBorder; // Indica si el jugador esta en uno de los cuatro bordes de la pantalla
|
||||
int border; // Indica en cual de los cuatro bordes se encuentra
|
||||
bool autoMovement; // Indica si esta siendo arrastrado por una superficie automatica
|
||||
bool paused; // Indica si el jugador esta en modo pausa
|
||||
SDL_Rect lastPosition; // Contiene la ultima posición del jugador, por si hay que deshacer algun movimiento
|
||||
int jumpIni; // Valor del eje Y en el que se inicia el salto
|
||||
float maxVY; // Velocidad máxima que puede alcanzar al desplazarse en vertical
|
||||
std::vector<JA_Sound_t*> jumpSound; // Vecor con todos los sonidos del salto
|
||||
std::vector<JA_Sound_t*> fallSound; // Vecor con todos los sonidos de la caída
|
||||
int jumpCounter; // Cuenta el tiempo de salto
|
||||
int fallCounter; // Cuenta el tiempo de caida
|
||||
bool alive; // Indica si el jugador esta vivo o no
|
||||
int maxFallHeight; // Altura maxima permitida de caída.
|
||||
float x; // Posición del jugador en el eje X
|
||||
float y; // Posición del jugador en el eje Y
|
||||
float vx; // Velocidad/desplazamiento del jugador en el eje X
|
||||
float vy; // Velocidad/desplazamiento del jugador en el eje Y
|
||||
int w; // Ancho del jugador
|
||||
int h; // ALto del jugador
|
||||
color_t color; // Color del jugador
|
||||
SDL_Rect colliderBox; // Caja de colisión con los enemigos u objetos
|
||||
vector<SDL_Point> colliderPoints; // Puntos de colisión con el mapa
|
||||
vector<SDL_Point> underFeet; // Contiene los puntos que hay bajo cada pie del jugador
|
||||
vector<SDL_Point> feet; // Contiene los puntos que hay en el pie del jugador
|
||||
state_e state; // Estado en el que se encuentra el jugador. Util apara saber si está saltando o cayendo
|
||||
state_e prevState; // Estado previo en el que se encontraba el jugador
|
||||
bool onBorder; // Indica si el jugador esta en uno de los cuatro bordes de la pantalla
|
||||
int border; // Indica en cual de los cuatro bordes se encuentra
|
||||
bool autoMovement; // Indica si esta siendo arrastrado por una superficie automatica
|
||||
bool paused; // Indica si el jugador esta en modo pausa
|
||||
SDL_Rect lastPosition; // Contiene la ultima posición del jugador, por si hay que deshacer algun movimiento
|
||||
int jumpIni; // Valor del eje Y en el que se inicia el salto
|
||||
float maxVY; // Velocidad máxima que puede alcanzar al desplazarse en vertical
|
||||
vector<JA_Sound_t *> jumpSound; // Vecor con todos los sonidos del salto
|
||||
vector<JA_Sound_t *> fallSound; // Vecor con todos los sonidos de la caída
|
||||
int jumpCounter; // Cuenta el tiempo de salto
|
||||
int fallCounter; // Cuenta el tiempo de caida
|
||||
bool alive; // Indica si el jugador esta vivo o no
|
||||
int maxFallHeight; // Altura maxima permitida de caída.
|
||||
|
||||
#ifdef DEBUG
|
||||
SDL_Rect rx; // Rectangulo de desplazamiento para el modo debug
|
||||
|
||||
116
source/room.cpp
116
source/room.cpp
@@ -4,34 +4,34 @@
|
||||
#include <sstream>
|
||||
|
||||
// Carga las variables y texturas desde un fichero de mapa de tiles
|
||||
std::vector<int> loadRoomTileFile(std::string file_path, bool verbose)
|
||||
vector<int> loadRoomTileFile(string file_path, bool verbose)
|
||||
{
|
||||
std::vector<int> tileMapFile;
|
||||
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
std::string line;
|
||||
std::ifstream file(file_path);
|
||||
vector<int> tileMapFile;
|
||||
const string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
string line;
|
||||
ifstream file(file_path);
|
||||
|
||||
// El fichero se puede abrir
|
||||
if (file.good())
|
||||
{
|
||||
// Procesa el fichero linea a linea
|
||||
while (std::getline(file, line))
|
||||
while (getline(file, line))
|
||||
{ // Lee el fichero linea a linea
|
||||
if (line.find("data encoding") != std::string::npos)
|
||||
if (line.find("data encoding") != string::npos)
|
||||
{
|
||||
// Lee la primera linea
|
||||
std::getline(file, line);
|
||||
getline(file, line);
|
||||
while (line != "</data>")
|
||||
{ // Procesa lineas mientras haya
|
||||
std::stringstream ss(line);
|
||||
std::string tmp;
|
||||
stringstream ss(line);
|
||||
string tmp;
|
||||
while (getline(ss, tmp, ','))
|
||||
{
|
||||
tileMapFile.push_back(std::stoi(tmp) - 1);
|
||||
tileMapFile.push_back(stoi(tmp) - 1);
|
||||
}
|
||||
|
||||
// Lee la siguiente linea
|
||||
std::getline(file, line);
|
||||
getline(file, line);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ std::vector<int> loadRoomTileFile(std::string file_path, bool verbose)
|
||||
// Cierra el fichero
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "TileMap loaded: " << filename.c_str() << std::endl;
|
||||
cout << "TileMap loaded: " << filename.c_str() << endl;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
@@ -48,7 +48,7 @@ std::vector<int> loadRoomTileFile(std::string file_path, bool verbose)
|
||||
{ // El fichero no se puede abrir
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl;
|
||||
cout << "Warning: Unable to open " << filename.c_str() << " file" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,24 +56,24 @@ std::vector<int> loadRoomTileFile(std::string file_path, bool verbose)
|
||||
}
|
||||
|
||||
// Carga las variables desde un fichero de mapa
|
||||
room_t loadRoomFile(std::string file_path, bool verbose)
|
||||
room_t loadRoomFile(string file_path, bool verbose)
|
||||
{
|
||||
room_t room;
|
||||
room.itemColor1 = "yellow";
|
||||
room.itemColor2 = "magenta";
|
||||
room.autoSurfaceDirection = 1;
|
||||
|
||||
const std::string fileName = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
const string fileName = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
room.number = fileName.substr(0, fileName.find_last_of("."));
|
||||
|
||||
std::string line;
|
||||
std::ifstream file(file_path);
|
||||
string line;
|
||||
ifstream file(file_path);
|
||||
|
||||
// El fichero se puede abrir
|
||||
if (file.good())
|
||||
{
|
||||
// Procesa el fichero linea a linea
|
||||
while (std::getline(file, line))
|
||||
while (getline(file, line))
|
||||
{
|
||||
// Si la linea contiene el texto [enemy] se realiza el proceso de carga de un enemigo
|
||||
if (line == "[enemy]")
|
||||
@@ -86,7 +86,7 @@ room_t loadRoomFile(std::string file_path, bool verbose)
|
||||
|
||||
do
|
||||
{
|
||||
std::getline(file, line);
|
||||
getline(file, line);
|
||||
|
||||
// Encuentra la posición del caracter '='
|
||||
int pos = line.find("=");
|
||||
@@ -96,7 +96,7 @@ room_t loadRoomFile(std::string file_path, bool verbose)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "Warning: file " << fileName.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||
cout << "Warning: file " << fileName.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << endl;
|
||||
}
|
||||
}
|
||||
} while (line != "[/enemy]");
|
||||
@@ -115,7 +115,7 @@ room_t loadRoomFile(std::string file_path, bool verbose)
|
||||
|
||||
do
|
||||
{
|
||||
std::getline(file, line);
|
||||
getline(file, line);
|
||||
|
||||
// Encuentra la posición del caracter '='
|
||||
int pos = line.find("=");
|
||||
@@ -125,7 +125,7 @@ room_t loadRoomFile(std::string file_path, bool verbose)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "Warning: file " << fileName.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||
cout << "Warning: file " << fileName.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ room_t loadRoomFile(std::string file_path, bool verbose)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "Warning: file " << fileName.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||
cout << "Warning: file " << fileName.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -154,7 +154,7 @@ room_t loadRoomFile(std::string file_path, bool verbose)
|
||||
// Cierra el fichero
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "Room loaded: " << fileName.c_str() << std::endl;
|
||||
cout << "Room loaded: " << fileName.c_str() << endl;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
@@ -162,7 +162,7 @@ room_t loadRoomFile(std::string file_path, bool verbose)
|
||||
else
|
||||
{
|
||||
{
|
||||
std::cout << "Warning: Unable to open " << fileName.c_str() << " file" << std::endl;
|
||||
cout << "Warning: Unable to open " << fileName.c_str() << " file" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ room_t loadRoomFile(std::string file_path, bool verbose)
|
||||
}
|
||||
|
||||
// Asigna variables a partir de dos cadenas
|
||||
bool setVars(room_t *room, std::string var, std::string value)
|
||||
bool setVars(room_t *room, string var, string value)
|
||||
{
|
||||
// Indicador de éxito en la asignación
|
||||
bool success = true;
|
||||
@@ -255,7 +255,7 @@ bool setVars(room_t *room, std::string var, std::string value)
|
||||
}
|
||||
|
||||
// Asigna variables a una estructura enemy_t
|
||||
bool setEnemy(enemy_t *enemy, std::string var, std::string value)
|
||||
bool setEnemy(enemy_t *enemy, string var, string value)
|
||||
{
|
||||
// Indicador de éxito en la asignación
|
||||
bool success = true;
|
||||
@@ -267,52 +267,52 @@ bool setEnemy(enemy_t *enemy, std::string var, std::string value)
|
||||
|
||||
else if (var == "width")
|
||||
{
|
||||
enemy->w = std::stof(value);
|
||||
enemy->w = stof(value);
|
||||
}
|
||||
|
||||
else if (var == "height")
|
||||
{
|
||||
enemy->h = std::stof(value);
|
||||
enemy->h = stof(value);
|
||||
}
|
||||
|
||||
else if (var == "x")
|
||||
{
|
||||
enemy->x = std::stof(value) * BLOCK;
|
||||
enemy->x = stof(value) * BLOCK;
|
||||
}
|
||||
|
||||
else if (var == "y")
|
||||
{
|
||||
enemy->y = std::stof(value) * BLOCK;
|
||||
enemy->y = stof(value) * BLOCK;
|
||||
}
|
||||
|
||||
else if (var == "vx")
|
||||
{
|
||||
enemy->vx = std::stof(value);
|
||||
enemy->vx = stof(value);
|
||||
}
|
||||
|
||||
else if (var == "vy")
|
||||
{
|
||||
enemy->vy = std::stof(value);
|
||||
enemy->vy = stof(value);
|
||||
}
|
||||
|
||||
else if (var == "x1")
|
||||
{
|
||||
enemy->x1 = std::stoi(value) * BLOCK;
|
||||
enemy->x1 = stoi(value) * BLOCK;
|
||||
}
|
||||
|
||||
else if (var == "x2")
|
||||
{
|
||||
enemy->x2 = std::stoi(value) * BLOCK;
|
||||
enemy->x2 = stoi(value) * BLOCK;
|
||||
}
|
||||
|
||||
else if (var == "y1")
|
||||
{
|
||||
enemy->y1 = std::stoi(value) * BLOCK;
|
||||
enemy->y1 = stoi(value) * BLOCK;
|
||||
}
|
||||
|
||||
else if (var == "y2")
|
||||
{
|
||||
enemy->y2 = std::stoi(value) * BLOCK;
|
||||
enemy->y2 = stoi(value) * BLOCK;
|
||||
}
|
||||
|
||||
else if (var == "flip")
|
||||
@@ -332,7 +332,7 @@ bool setEnemy(enemy_t *enemy, std::string var, std::string value)
|
||||
|
||||
else if (var == "frame")
|
||||
{
|
||||
enemy->frame = std::stoi(value);
|
||||
enemy->frame = stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "[/enemy]" || var == "tileSetFile" || var.substr(0, 1) == "#")
|
||||
@@ -348,7 +348,7 @@ bool setEnemy(enemy_t *enemy, std::string var, std::string value)
|
||||
}
|
||||
|
||||
// Asigna variables a una estructura item_t
|
||||
bool setItem(item_t *item, std::string var, std::string value)
|
||||
bool setItem(item_t *item, string var, string value)
|
||||
{
|
||||
// Indicador de éxito en la asignación
|
||||
bool success = true;
|
||||
@@ -360,22 +360,22 @@ bool setItem(item_t *item, std::string var, std::string value)
|
||||
|
||||
else if (var == "counter")
|
||||
{
|
||||
item->counter = std::stoi(value);
|
||||
item->counter = stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "x")
|
||||
{
|
||||
item->x = std::stof(value) * BLOCK;
|
||||
item->x = stof(value) * BLOCK;
|
||||
}
|
||||
|
||||
else if (var == "y")
|
||||
{
|
||||
item->y = std::stof(value) * BLOCK;
|
||||
item->y = stof(value) * BLOCK;
|
||||
}
|
||||
|
||||
else if (var == "tile")
|
||||
{
|
||||
item->tile = std::stof(value);
|
||||
item->tile = stof(value);
|
||||
}
|
||||
|
||||
else if (var == "[/item]")
|
||||
@@ -478,7 +478,7 @@ Room::Room(room_t *room, SDL_Renderer *renderer, Screen *screen, Asset *asset, o
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Error: mapTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
cout << "Error: mapTexture could not be created!\nSDL Error: " << SDL_GetError() << endl;
|
||||
}
|
||||
}
|
||||
SDL_SetTextureBlendMode(mapTexture, SDL_BLENDMODE_BLEND);
|
||||
@@ -514,7 +514,7 @@ Room::~Room()
|
||||
}
|
||||
|
||||
// Devuelve el nombre de la habitación
|
||||
std::string Room::getName()
|
||||
string Room::getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
@@ -723,7 +723,7 @@ void Room::update()
|
||||
}
|
||||
|
||||
// Devuelve la cadena del fichero de la habitación contigua segun el borde
|
||||
std::string Room::getRoom(int border)
|
||||
string Room::getRoom(int border)
|
||||
{
|
||||
switch (border)
|
||||
{
|
||||
@@ -897,13 +897,13 @@ int Room::getSlopeHeight(SDL_Point p, tile_e slope)
|
||||
// Calcula la base del tile
|
||||
int base = ((p.y / tileSize) * tileSize) + tileSize;
|
||||
#ifdef DEBUG
|
||||
debug->add("BASE = " + std::to_string(base));
|
||||
debug->add("BASE = " + to_string(base));
|
||||
#endif
|
||||
|
||||
// Calcula cuanto se ha entrado en el tile horizontalmente
|
||||
const int pos = (p.x % tileSize); // Esto da un valor entre 0 y 7
|
||||
#ifdef DEBUG
|
||||
debug->add("POS = " + std::to_string(pos));
|
||||
debug->add("POS = " + to_string(pos));
|
||||
#endif
|
||||
|
||||
// Se resta a la base la cantidad de pixeles pos en funcion de la rampa
|
||||
@@ -911,14 +911,14 @@ int Room::getSlopeHeight(SDL_Point p, tile_e slope)
|
||||
{
|
||||
base -= pos + 1;
|
||||
#ifdef DEBUG
|
||||
debug->add("BASE_R = " + std::to_string(base));
|
||||
debug->add("BASE_R = " + to_string(base));
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
base -= (tileSize - pos);
|
||||
#ifdef DEBUG
|
||||
debug->add("BASE_L = " + std::to_string(base));
|
||||
debug->add("BASE_L = " + to_string(base));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -928,7 +928,7 @@ int Room::getSlopeHeight(SDL_Point p, tile_e slope)
|
||||
// Calcula las superficies inferiores
|
||||
void Room::setBottomSurfaces()
|
||||
{
|
||||
std::vector<int> tile;
|
||||
vector<int> tile;
|
||||
|
||||
// Busca todos los tiles de tipo muro que no tengan debajo otro muro
|
||||
// Hay que recorrer la habitación por filas (excepto los de la última fila)
|
||||
@@ -991,7 +991,7 @@ void Room::setBottomSurfaces()
|
||||
// Calcula las superficies superiores
|
||||
void Room::setTopSurfaces()
|
||||
{
|
||||
std::vector<int> tile;
|
||||
vector<int> tile;
|
||||
|
||||
// Busca todos los tiles de tipo muro o pasable que no tengan encima un muro
|
||||
// Hay que recorrer la habitación por filas (excepto los de la primera fila)
|
||||
@@ -1054,7 +1054,7 @@ void Room::setTopSurfaces()
|
||||
// Calcula las superficies laterales izquierdas
|
||||
void Room::setLeftSurfaces()
|
||||
{
|
||||
std::vector<int> tile;
|
||||
vector<int> tile;
|
||||
|
||||
// Busca todos los tiles de tipo muro que no tienen a su izquierda un tile de tipo muro
|
||||
// Hay que recorrer la habitación por columnas (excepto los de la primera columna)
|
||||
@@ -1102,7 +1102,7 @@ void Room::setLeftSurfaces()
|
||||
// Calcula las superficies laterales derechas
|
||||
void Room::setRightSurfaces()
|
||||
{
|
||||
std::vector<int> tile;
|
||||
vector<int> tile;
|
||||
|
||||
// Busca todos los tiles de tipo muro que no tienen a su derecha un tile de tipo muro
|
||||
// Hay que recorrer la habitación por columnas (excepto los de la última columna)
|
||||
@@ -1151,7 +1151,7 @@ void Room::setRightSurfaces()
|
||||
void Room::setLeftSlopes()
|
||||
{
|
||||
// Recorre la habitación entera por filas buscando tiles de tipo t_slope_l
|
||||
std::vector<int> found;
|
||||
vector<int> found;
|
||||
for (int i = 0; i < (int)tileMap.size(); ++i)
|
||||
{
|
||||
if (getTile(i) == t_slope_l)
|
||||
@@ -1192,7 +1192,7 @@ void Room::setLeftSlopes()
|
||||
void Room::setRightSlopes()
|
||||
{
|
||||
// Recorre la habitación entera por filas buscando tiles de tipo t_slope_r
|
||||
std::vector<int> found;
|
||||
vector<int> found;
|
||||
for (int i = 0; i < (int)tileMap.size(); ++i)
|
||||
{
|
||||
if (getTile(i) == t_slope_r)
|
||||
@@ -1232,7 +1232,7 @@ void Room::setRightSlopes()
|
||||
// Calcula las superficies automaticas
|
||||
void Room::setAutoSurfaces()
|
||||
{
|
||||
std::vector<int> tile;
|
||||
vector<int> tile;
|
||||
|
||||
// Busca todos los tiles de tipo animado
|
||||
// Hay que recorrer la habitación por filas (excepto los de la primera fila)
|
||||
|
||||
138
source/room.h
138
source/room.h
@@ -17,6 +17,8 @@
|
||||
#ifndef ROOM_H
|
||||
#define ROOM_H
|
||||
|
||||
using namespace std;
|
||||
|
||||
enum tile_e
|
||||
{
|
||||
t_empty,
|
||||
@@ -36,90 +38,90 @@ struct aTile_t
|
||||
|
||||
struct room_t
|
||||
{
|
||||
std::string number; // Numero de la habitación
|
||||
std::string name; // Nombre de la habitación
|
||||
std::string bgColor; // Color de fondo de la habitación
|
||||
std::string borderColor; // Color del borde de la pantalla
|
||||
std::string itemColor1; // Color 1 para los items de la habitación
|
||||
std::string itemColor2; // Color 2 para los items de la habitación
|
||||
std::string roomUp; // Identificador de la habitación que se encuentra arriba
|
||||
std::string roomDown; // Identificador de la habitación que se encuentra abajp
|
||||
std::string roomLeft; // Identificador de la habitación que se encuentra a la izquierda
|
||||
std::string roomRight; // Identificador de la habitación que se encuentra a la derecha
|
||||
std::string tileSetFile; // Imagen con los graficos para la habitación
|
||||
std::string tileMapFile; // Fichero con el mapa de indices de tile
|
||||
std::vector<int> *tileMap; // Indice de los tiles a dibujar en la habitación
|
||||
int autoSurfaceDirection; // Sentido en el que arrastran las superficies automáticas de la habitación
|
||||
std::vector<enemy_t> enemies; // Listado con los enemigos de la habitación
|
||||
std::vector<item_t> items; // Listado con los items que hay en la habitación
|
||||
Texture *textureA; // Textura con los graficos de la habitación
|
||||
Texture *textureB; // Textura con los graficos de la habitación
|
||||
string number; // Numero de la habitación
|
||||
string name; // Nombre de la habitación
|
||||
string bgColor; // Color de fondo de la habitación
|
||||
string borderColor; // Color del borde de la pantalla
|
||||
string itemColor1; // Color 1 para los items de la habitación
|
||||
string itemColor2; // Color 2 para los items de la habitación
|
||||
string roomUp; // Identificador de la habitación que se encuentra arriba
|
||||
string roomDown; // Identificador de la habitación que se encuentra abajp
|
||||
string roomLeft; // Identificador de la habitación que se encuentra a la izquierda
|
||||
string roomRight; // Identificador de la habitación que se encuentra a la derecha
|
||||
string tileSetFile; // Imagen con los graficos para la habitación
|
||||
string tileMapFile; // Fichero con el mapa de indices de tile
|
||||
vector<int> *tileMap; // Indice de los tiles a dibujar en la habitación
|
||||
int autoSurfaceDirection; // Sentido en el que arrastran las superficies automáticas de la habitación
|
||||
vector<enemy_t> enemies; // Listado con los enemigos de la habitación
|
||||
vector<item_t> items; // Listado con los items que hay en la habitación
|
||||
Texture *textureA; // Textura con los graficos de la habitación
|
||||
Texture *textureB; // Textura con los graficos de la habitación
|
||||
};
|
||||
|
||||
// Carga las variables desde un fichero de mapa
|
||||
room_t loadRoomFile(std::string file, bool verbose = false);
|
||||
room_t loadRoomFile(string file, bool verbose = false);
|
||||
|
||||
// Carga las variables y texturas desde un fichero de mapa de tiles
|
||||
std::vector<int> loadRoomTileFile(std::string file_path, bool verbose = false);
|
||||
vector<int> loadRoomTileFile(string file_path, bool verbose = false);
|
||||
|
||||
// Asigna variables a partir de dos cadenas
|
||||
bool setVars(room_t *room, std::string var, std::string value);
|
||||
bool setVars(room_t *room, string var, string value);
|
||||
|
||||
// Asigna variables a una estructura enemy_t
|
||||
bool setEnemy(enemy_t *enemy, std::string var, std::string value);
|
||||
bool setEnemy(enemy_t *enemy, string var, string value);
|
||||
|
||||
// Asigna variables a una estructura item_t
|
||||
bool setItem(item_t *item, std::string var, std::string value);
|
||||
bool setItem(item_t *item, string var, string value);
|
||||
|
||||
class Room
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
std::vector<Enemy *> enemies; // Listado con los enemigos de la habitación
|
||||
std::vector<Item *> items; // Listado con los items que hay en la habitación
|
||||
Texture *texture; // Textura con los graficos de la habitación
|
||||
Texture *textureA; // Textura con los graficos de la habitación
|
||||
Texture *textureB; // Textura con los graficos de la habitación
|
||||
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||
ItemTracker *itemTracker; // Lleva el control de los objetos recogidos
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
SDL_Texture *mapTexture; // Textura para dibujar el mapa de la habitación
|
||||
int *itemsPicked; // Puntero a la cantidad de items recogidos que lleva el juego
|
||||
Debug *debug; // Objeto para gestionar la información de debug
|
||||
options_t *options; // Puntero a las opciones del juego
|
||||
vector<Enemy *> enemies; // Listado con los enemigos de la habitación
|
||||
vector<Item *> items; // Listado con los items que hay en la habitación
|
||||
Texture *texture; // Textura con los graficos de la habitación
|
||||
Texture *textureA; // Textura con los graficos de la habitación
|
||||
Texture *textureB; // Textura con los graficos de la habitación
|
||||
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||
ItemTracker *itemTracker; // Lleva el control de los objetos recogidos
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
SDL_Texture *mapTexture; // Textura para dibujar el mapa de la habitación
|
||||
int *itemsPicked; // Puntero a la cantidad de items recogidos que lleva el juego
|
||||
Debug *debug; // Objeto para gestionar la información de debug
|
||||
options_t *options; // Puntero a las opciones del juego
|
||||
|
||||
// Variables
|
||||
std::string number; // Numero de la habitación
|
||||
std::string name; // Nombre de la habitación
|
||||
std::string bgColor; // Color de fondo de la habitación
|
||||
std::string borderColor; // Color del borde de la pantalla
|
||||
std::string itemColor1; // Color 1 para los items de la habitación
|
||||
std::string itemColor2; // Color 2 para los items de la habitación
|
||||
std::string roomUp; // Identificador de la habitación que se encuentra arriba
|
||||
std::string roomDown; // Identificador de la habitación que se encuentra abajp
|
||||
std::string roomLeft; // Identificador de la habitación que se encuentra a la izquierda
|
||||
std::string roomRight; // Identificador de la habitación que se encuentra a la derecha
|
||||
std::string tileSetFile; // Imagen con los graficos para la habitación
|
||||
std::string tileMapFile; // Fichero con el mapa de indices de tile
|
||||
std::vector<int> tileMap; // Indice de los tiles a dibujar en la habitación
|
||||
int autoSurfaceDirection; // Sentido en el que arrastran las superficies automáticas de la habitación
|
||||
JA_Sound_t *itemSound; // Sonido producido al coger un objeto
|
||||
std::vector<h_line_t> bottomSurfaces; // Lista con las superficies inferiores de la habitación
|
||||
std::vector<h_line_t> topSurfaces; // Lista con las superficies superiores de la habitación
|
||||
std::vector<v_line_t> leftSurfaces; // Lista con las superficies laterales de la parte izquierda de la habitación
|
||||
std::vector<v_line_t> rightSurfaces; // Lista con las superficies laterales de la parte derecha de la habitación
|
||||
std::vector<d_line_t> leftSlopes; // Lista con todas las rampas que suben hacia la izquierda
|
||||
std::vector<d_line_t> rightSlopes; // Lista con todas las rampas que suben hacia la derecha
|
||||
int counter; // Contador para lo que haga falta
|
||||
bool paused; // Indica si el mapa esta en modo pausa
|
||||
std::vector<aTile_t> aTile; // Vector con los indices de tiles animados
|
||||
std::vector<h_line_t> autoSurfaces; // Lista con las superficies automaticas de la habitación
|
||||
int tileSize; // Ancho del tile en pixels
|
||||
int mapWidth; // Ancho del mapa en tiles
|
||||
int mapHeight; // Alto del mapa en tiles
|
||||
int tileSetWidth; // Ancho del tileset en tiles
|
||||
bool jailEnabled; // Indica si hay acceso a la Jail
|
||||
string number; // Numero de la habitación
|
||||
string name; // Nombre de la habitación
|
||||
string bgColor; // Color de fondo de la habitación
|
||||
string borderColor; // Color del borde de la pantalla
|
||||
string itemColor1; // Color 1 para los items de la habitación
|
||||
string itemColor2; // Color 2 para los items de la habitación
|
||||
string roomUp; // Identificador de la habitación que se encuentra arriba
|
||||
string roomDown; // Identificador de la habitación que se encuentra abajp
|
||||
string roomLeft; // Identificador de la habitación que se encuentra a la izquierda
|
||||
string roomRight; // Identificador de la habitación que se encuentra a la derecha
|
||||
string tileSetFile; // Imagen con los graficos para la habitación
|
||||
string tileMapFile; // Fichero con el mapa de indices de tile
|
||||
vector<int> tileMap; // Indice de los tiles a dibujar en la habitación
|
||||
int autoSurfaceDirection; // Sentido en el que arrastran las superficies automáticas de la habitación
|
||||
JA_Sound_t *itemSound; // Sonido producido al coger un objeto
|
||||
vector<h_line_t> bottomSurfaces; // Lista con las superficies inferiores de la habitación
|
||||
vector<h_line_t> topSurfaces; // Lista con las superficies superiores de la habitación
|
||||
vector<v_line_t> leftSurfaces; // Lista con las superficies laterales de la parte izquierda de la habitación
|
||||
vector<v_line_t> rightSurfaces; // Lista con las superficies laterales de la parte derecha de la habitación
|
||||
vector<d_line_t> leftSlopes; // Lista con todas las rampas que suben hacia la izquierda
|
||||
vector<d_line_t> rightSlopes; // Lista con todas las rampas que suben hacia la derecha
|
||||
int counter; // Contador para lo que haga falta
|
||||
bool paused; // Indica si el mapa esta en modo pausa
|
||||
vector<aTile_t> aTile; // Vector con los indices de tiles animados
|
||||
vector<h_line_t> autoSurfaces; // Lista con las superficies automaticas de la habitación
|
||||
int tileSize; // Ancho del tile en pixels
|
||||
int mapWidth; // Ancho del mapa en tiles
|
||||
int mapHeight; // Alto del mapa en tiles
|
||||
int tileSetWidth; // Ancho del tileset en tiles
|
||||
bool jailEnabled; // Indica si hay acceso a la Jail
|
||||
|
||||
// Pinta el mapa de la habitación en la textura
|
||||
void fillMapTexture();
|
||||
@@ -168,7 +170,7 @@ public:
|
||||
~Room();
|
||||
|
||||
// Devuelve el nombre de la habitación
|
||||
std::string getName();
|
||||
string getName();
|
||||
|
||||
// Devuelve el color de la habitación
|
||||
color_t getBGColor();
|
||||
@@ -189,7 +191,7 @@ public:
|
||||
void update();
|
||||
|
||||
// Devuelve la cadena del fichero de la habitación contigua segun el borde
|
||||
std::string getRoom(int border);
|
||||
string getRoom(int border);
|
||||
|
||||
// Devuelve el tipo de tile que hay en ese pixel
|
||||
tile_e getTile(SDL_Point point);
|
||||
|
||||
@@ -12,7 +12,7 @@ RoomTracker::~RoomTracker()
|
||||
}
|
||||
|
||||
// Comprueba si la habitación ya ha sido visitada
|
||||
bool RoomTracker::hasBeenVisited(std::string name)
|
||||
bool RoomTracker::hasBeenVisited(string name)
|
||||
{
|
||||
for (auto l : list)
|
||||
{
|
||||
@@ -26,7 +26,7 @@ bool RoomTracker::hasBeenVisited(std::string name)
|
||||
}
|
||||
|
||||
// Añade la habitación a la lista
|
||||
bool RoomTracker::addRoom(std::string name)
|
||||
bool RoomTracker::addRoom(string name)
|
||||
{
|
||||
// Comprueba si la habitación ya ha sido visitada
|
||||
if (!hasBeenVisited(name))
|
||||
|
||||
@@ -8,14 +8,16 @@
|
||||
#ifndef ROOM_TRACKER_H
|
||||
#define ROOM_TRACKER_H
|
||||
|
||||
using namespace std;
|
||||
|
||||
class RoomTracker
|
||||
{
|
||||
private:
|
||||
// Variables
|
||||
std::vector<std::string> list; // Lista con las habitaciones visitadas
|
||||
vector<string> list; // Lista con las habitaciones visitadas
|
||||
|
||||
// Comprueba si la habitación ya ha sido visitada
|
||||
bool hasBeenVisited(std::string name);
|
||||
bool hasBeenVisited(string name);
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
@@ -25,7 +27,7 @@ public:
|
||||
~RoomTracker();
|
||||
|
||||
// Añade la habitación a la lista
|
||||
bool addRoom(std::string name);
|
||||
bool addRoom(string name);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -14,7 +14,7 @@ ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Resource *resource, Asset *asset,
|
||||
|
||||
// Reserva memoria para los objetos
|
||||
itemTexture = resource->getTexture("items.png");
|
||||
const std::string playerANI = options->cheat.altSkin ? "player2.ani" : "player.ani";
|
||||
const string playerANI = options->cheat.altSkin ? "player2.ani" : "player.ani";
|
||||
sprite = new AnimatedSprite(renderer, resource->getAnimation(playerANI));
|
||||
sprite->setCurrentAnimation("walk_menu");
|
||||
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
|
||||
@@ -28,7 +28,7 @@ ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Resource *resource, Asset *asset,
|
||||
itemsColor = stringToColor(options->palette, "white");
|
||||
|
||||
// Inicializa el vector de colores
|
||||
const std::vector<std::string> vColors = {"blue", "magenta", "green", "cyan", "yellow", "white", "bright_blue", "bright_magenta", "bright_green", "bright_cyan", "bright_yellow", "bright_white"};
|
||||
const vector<string> vColors = {"blue", "magenta", "green", "cyan", "yellow", "white", "bright_blue", "bright_magenta", "bright_green", "bright_cyan", "bright_yellow", "bright_white"};
|
||||
for (auto v : vColors)
|
||||
{
|
||||
color.push_back(stringToColor(options->palette, v));
|
||||
@@ -77,14 +77,14 @@ void ScoreBoard::render()
|
||||
}
|
||||
|
||||
// Escribe los textos
|
||||
const std::string timeTxt = std::to_string((clock.minutes % 100) / 10) + std::to_string(clock.minutes % 10) + clock.separator + std::to_string((clock.seconds % 60) / 10) + std::to_string(clock.seconds % 10);
|
||||
const std::string itemsTxt = std::to_string(board->items / 100) + std::to_string((board->items % 100) / 10) + std::to_string(board->items % 10);
|
||||
const string timeTxt = to_string((clock.minutes % 100) / 10) + to_string(clock.minutes % 10) + clock.separator + to_string((clock.seconds % 60) / 10) + to_string(clock.seconds % 10);
|
||||
const string itemsTxt = to_string(board->items / 100) + to_string((board->items % 100) / 10) + to_string(board->items % 10);
|
||||
this->text->writeColored(BLOCK, line1, "Items collected ", board->color);
|
||||
this->text->writeColored(17 * BLOCK, line1, itemsTxt, itemsColor);
|
||||
this->text->writeColored(20 * BLOCK, line1, " Time ", board->color);
|
||||
this->text->writeColored(26 * BLOCK, line1, timeTxt, stringToColor(options->palette, "white"));
|
||||
|
||||
const std::string roomsTxt = std::to_string(board->rooms / 100) + std::to_string((board->rooms % 100) / 10) + std::to_string(board->rooms % 10);
|
||||
const string roomsTxt = to_string(board->rooms / 100) + to_string((board->rooms % 100) / 10) + to_string(board->rooms % 10);
|
||||
this->text->writeColored(22 * BLOCK, line2, "Rooms", stringToColor(options->palette, "white"));
|
||||
this->text->writeColored(28 * BLOCK, line2, roomsTxt, stringToColor(options->palette, "white"));
|
||||
}
|
||||
@@ -131,7 +131,7 @@ void ScoreBoard::reLoadTexture()
|
||||
void ScoreBoard::reLoadPalette()
|
||||
{
|
||||
// Reinicia el vector de colores
|
||||
const std::vector<std::string> vColors = {"blue", "magenta", "green", "cyan", "yellow", "white", "bright_blue", "bright_magenta", "bright_green", "bright_cyan", "bright_yellow", "bright_white"};
|
||||
const vector<string> vColors = {"blue", "magenta", "green", "cyan", "yellow", "white", "bright_blue", "bright_magenta", "bright_green", "bright_cyan", "bright_yellow", "bright_white"};
|
||||
color.clear();
|
||||
for (auto v : vColors)
|
||||
{
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#ifndef SCOREBOARD_H
|
||||
#define SCOREBOARD_H
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct board_t
|
||||
{
|
||||
int items; // Lleva la cuenta de los objetos recogidos
|
||||
@@ -31,7 +33,7 @@ private:
|
||||
int hours;
|
||||
int minutes;
|
||||
int seconds;
|
||||
std::string separator;
|
||||
string separator;
|
||||
};
|
||||
|
||||
// Objetos y punteros
|
||||
@@ -45,14 +47,14 @@ private:
|
||||
options_t *options; // Puntero a las opciones del juego
|
||||
|
||||
// Variables
|
||||
std::vector<color_t> color; // Vector con los colores del objeto
|
||||
int counter; // Contador interno
|
||||
int colorChangeSpeed; // Cuanto mas alto, mas tarda en cambiar de color
|
||||
bool paused; // Indica si el marcador esta en modo pausa
|
||||
Uint32 timePaused; // Milisegundos que ha estado el marcador en pausa
|
||||
Uint32 totalTimePaused; // Tiempo acumulado en pausa
|
||||
clock_t clock; // Contiene las horas, minutos y segundos transcurridos desde el inicio de la partida
|
||||
color_t itemsColor; // Color de la cantidad de items recogidos
|
||||
vector<color_t> color; // Vector con los colores del objeto
|
||||
int counter; // Contador interno
|
||||
int colorChangeSpeed; // Cuanto mas alto, mas tarda en cambiar de color
|
||||
bool paused; // Indica si el marcador esta en modo pausa
|
||||
Uint32 timePaused; // Milisegundos que ha estado el marcador en pausa
|
||||
Uint32 totalTimePaused; // Tiempo acumulado en pausa
|
||||
clock_t clock; // Contiene las horas, minutos y segundos transcurridos desde el inicio de la partida
|
||||
color_t itemsColor; // Color de la cantidad de items recogidos
|
||||
|
||||
// Obtiene el tiempo transcurrido de partida
|
||||
clock_t getTime();
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <sstream>
|
||||
|
||||
// Constructor
|
||||
Stats::Stats(std::string file, std::string buffer, options_t *options)
|
||||
Stats::Stats(string file, string buffer, options_t *options)
|
||||
{
|
||||
this->options = options;
|
||||
bufferPath = buffer;
|
||||
@@ -51,10 +51,10 @@ void Stats::init()
|
||||
}
|
||||
|
||||
// Añade una muerte a las estadisticas
|
||||
void Stats::addDeath(std::string name)
|
||||
void Stats::addDeath(string name)
|
||||
{
|
||||
// Normaliza el nombre
|
||||
// std::replace(name.begin(), name.end(), ' ', '_');
|
||||
// replace(name.begin(), name.end(), ' ', '_');
|
||||
|
||||
// Primero busca si ya hay una entrada con ese nombre
|
||||
const int index = findByName(name, bufferList);
|
||||
@@ -75,10 +75,10 @@ void Stats::addDeath(std::string name)
|
||||
}
|
||||
|
||||
// Añade una visita a las estadisticas
|
||||
void Stats::addVisit(std::string name)
|
||||
void Stats::addVisit(string name)
|
||||
{
|
||||
// Normaliza el nombre
|
||||
// std::replace(name.begin(), name.end(), ' ', '_');
|
||||
// replace(name.begin(), name.end(), ' ', '_');
|
||||
|
||||
// Primero busca si ya hay una entrada con ese nombre
|
||||
const int index = findByName(name, bufferList);
|
||||
@@ -99,7 +99,7 @@ void Stats::addVisit(std::string name)
|
||||
}
|
||||
|
||||
// Busca una entrada en la lista por nombre
|
||||
int Stats::findByName(std::string name, std::vector<stats_t> &list)
|
||||
int Stats::findByName(string name, vector<stats_t> &list)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
@@ -116,7 +116,7 @@ int Stats::findByName(std::string name, std::vector<stats_t> &list)
|
||||
}
|
||||
|
||||
// Carga las estadisticas desde un fichero
|
||||
bool Stats::loadFromFile(std::string filePath, std::vector<stats_t> &list)
|
||||
bool Stats::loadFromFile(string filePath, vector<stats_t> &list)
|
||||
{
|
||||
list.clear();
|
||||
|
||||
@@ -124,21 +124,21 @@ bool Stats::loadFromFile(std::string filePath, std::vector<stats_t> &list)
|
||||
bool success = true;
|
||||
|
||||
// Variables para manejar el fichero
|
||||
std::string line;
|
||||
std::ifstream file(filePath);
|
||||
string line;
|
||||
ifstream file(filePath);
|
||||
|
||||
// Si el fichero se puede abrir
|
||||
if (file.good())
|
||||
{
|
||||
// Procesa el fichero linea a linea
|
||||
while (std::getline(file, line))
|
||||
while (getline(file, line))
|
||||
{
|
||||
// Comprueba que la linea no sea un comentario
|
||||
if (line.substr(0, 1) != "#")
|
||||
{
|
||||
stats_t stat;
|
||||
std::stringstream ss(line);
|
||||
std::string tmp;
|
||||
stringstream ss(line);
|
||||
string tmp;
|
||||
|
||||
// Obtiene el nombre
|
||||
getline(ss, tmp, ';');
|
||||
@@ -146,11 +146,11 @@ bool Stats::loadFromFile(std::string filePath, std::vector<stats_t> &list)
|
||||
|
||||
// Obtiene las visitas
|
||||
getline(ss, tmp, ';');
|
||||
stat.visited = std::stoi(tmp);
|
||||
stat.visited = stoi(tmp);
|
||||
|
||||
// Obtiene las muertes
|
||||
getline(ss, tmp, ';');
|
||||
stat.died = std::stoi(tmp);
|
||||
stat.died = stoi(tmp);
|
||||
|
||||
list.push_back(stat);
|
||||
}
|
||||
@@ -177,14 +177,14 @@ void Stats::loadFromServer()
|
||||
|
||||
list.clear();
|
||||
|
||||
std::string data;
|
||||
string data;
|
||||
if (options->online.enabled)
|
||||
{
|
||||
data = jscore::getUserData(options->online.gameID, options->online.jailerID);
|
||||
}
|
||||
|
||||
std::stringstream ss(data);
|
||||
std::string tmp;
|
||||
stringstream ss(data);
|
||||
string tmp;
|
||||
|
||||
int count = 0;
|
||||
|
||||
@@ -206,11 +206,11 @@ void Stats::loadFromServer()
|
||||
|
||||
// Obtiene las visitas
|
||||
getline(ss, tmp, ';');
|
||||
stat.visited = std::stoi(tmp);
|
||||
stat.visited = stoi(tmp);
|
||||
|
||||
// Obtiene las muertes
|
||||
getline(ss, tmp, ';');
|
||||
stat.died = std::stoi(tmp);
|
||||
stat.died = stoi(tmp);
|
||||
|
||||
list.push_back(stat);
|
||||
count = count - 3;
|
||||
@@ -218,16 +218,16 @@ void Stats::loadFromServer()
|
||||
}
|
||||
|
||||
// Guarda las estadisticas en un fichero
|
||||
void Stats::saveToFile(std::string filePath, std::vector<stats_t> &list)
|
||||
void Stats::saveToFile(string filePath, vector<stats_t> &list)
|
||||
{
|
||||
// Crea y abre el fichero de texto
|
||||
std::ofstream file(filePath);
|
||||
ofstream file(filePath);
|
||||
|
||||
// Escribe en el fichero
|
||||
file << "# ROOM NAME;VISITS;DEATHS" << std::endl;
|
||||
file << "# ROOM NAME;VISITS;DEATHS" << endl;
|
||||
for (auto item : list)
|
||||
{
|
||||
file << item.name << ";" << item.visited << ";" << item.died << std::endl;
|
||||
file << item.name << ";" << item.visited << ";" << item.died << endl;
|
||||
}
|
||||
|
||||
// Cierra el fichero
|
||||
@@ -237,12 +237,12 @@ void Stats::saveToFile(std::string filePath, std::vector<stats_t> &list)
|
||||
// Guarda las estadisticas en un servidor
|
||||
void Stats::saveToServer()
|
||||
{
|
||||
std::string data = "";
|
||||
string data = "";
|
||||
if (options->online.enabled)
|
||||
{
|
||||
for (auto item : list)
|
||||
{
|
||||
data = data + nameToNumber(item.name) + ";" + std::to_string(item.visited) + ";" + std::to_string(item.died) + ";";
|
||||
data = data + nameToNumber(item.name) + ";" + to_string(item.visited) + ";" + to_string(item.died) + ";";
|
||||
}
|
||||
jscore::setUserData(options->online.gameID, options->online.jailerID, data);
|
||||
}
|
||||
@@ -263,13 +263,13 @@ void Stats::checkWorstNightmare()
|
||||
}
|
||||
|
||||
// Añade una entrada al diccionario
|
||||
void Stats::addDictionary(std::string number, std::string name)
|
||||
void Stats::addDictionary(string number, string name)
|
||||
{
|
||||
dictionary.push_back({number, name});
|
||||
}
|
||||
|
||||
// Obtiene el nombre de una habitación a partir del número
|
||||
std::string Stats::numberToName(std::string number)
|
||||
string Stats::numberToName(string number)
|
||||
{
|
||||
for (auto l : dictionary)
|
||||
{
|
||||
@@ -282,7 +282,7 @@ std::string Stats::numberToName(std::string number)
|
||||
}
|
||||
|
||||
// Obtiene el número de una habitación a partir del nombre
|
||||
std::string Stats::nameToNumber(std::string name)
|
||||
string Stats::nameToNumber(string name)
|
||||
{
|
||||
for (auto l : dictionary)
|
||||
{
|
||||
|
||||
@@ -7,43 +7,45 @@
|
||||
#ifndef STATS_H
|
||||
#define STATS_H
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Stats
|
||||
{
|
||||
private:
|
||||
struct stats_t
|
||||
{
|
||||
std::string name; // Nombre de la habitación
|
||||
int visited; // Cuenta las veces que se ha visitado una habitación
|
||||
int died; // Cuenta las veces que se ha muerto en una habitación
|
||||
string name; // Nombre de la habitación
|
||||
int visited; // Cuenta las veces que se ha visitado una habitación
|
||||
int died; // Cuenta las veces que se ha muerto en una habitación
|
||||
};
|
||||
|
||||
struct stats_dictionary_t
|
||||
{
|
||||
std::string number; // Numero de la habitación
|
||||
std::string name; // Nombre de la habitación
|
||||
string number; // Numero de la habitación
|
||||
string name; // Nombre de la habitación
|
||||
};
|
||||
|
||||
// Punteros y objetos
|
||||
options_t *options;
|
||||
|
||||
// Variables
|
||||
std::vector<stats_dictionary_t> dictionary; // Lista con la equivalencia nombre-numero de habitacion
|
||||
std::vector<stats_t> bufferList; // Lista con las estadisticas temporales por habitación
|
||||
std::vector<stats_t> list; // Lista con las estadisticas completas por habitación
|
||||
std::string bufferPath; // Fichero con las estadísticas temporales
|
||||
std::string filePath; // Fichero con las estadísticas completas
|
||||
vector<stats_dictionary_t> dictionary; // Lista con la equivalencia nombre-numero de habitacion
|
||||
vector<stats_t> bufferList; // Lista con las estadisticas temporales por habitación
|
||||
vector<stats_t> list; // Lista con las estadisticas completas por habitación
|
||||
string bufferPath; // Fichero con las estadísticas temporales
|
||||
string filePath; // Fichero con las estadísticas completas
|
||||
|
||||
// Busca una entrada en la lista por nombre
|
||||
int findByName(std::string name, std::vector<stats_t> &list);
|
||||
int findByName(string name, vector<stats_t> &list);
|
||||
|
||||
// Carga las estadisticas desde un fichero
|
||||
bool loadFromFile(std::string filePath, std::vector<stats_t> &list);
|
||||
bool loadFromFile(string filePath, vector<stats_t> &list);
|
||||
|
||||
// Carga las estadisticas desde un servidor
|
||||
void loadFromServer();
|
||||
|
||||
// Guarda las estadisticas en un fichero
|
||||
void saveToFile(std::string filePath, std::vector<stats_t> &list);
|
||||
void saveToFile(string filePath, vector<stats_t> &list);
|
||||
|
||||
// Guarda las estadisticas en un servidor
|
||||
void saveToServer();
|
||||
@@ -52,10 +54,10 @@ private:
|
||||
void checkWorstNightmare();
|
||||
|
||||
// Obtiene el nombre de una habitación a partir del número
|
||||
std::string numberToName(std::string number);
|
||||
string numberToName(string number);
|
||||
|
||||
// Obtiene el número de una habitación a partir del nombre
|
||||
std::string nameToNumber(std::string name);
|
||||
string nameToNumber(string name);
|
||||
|
||||
// Vuelca los datos del buffer en la lista de estadisticas
|
||||
void updateListFromBuffer();
|
||||
@@ -65,7 +67,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Stats(std::string file, std::string buffer, options_t *options);
|
||||
Stats(string file, string buffer, options_t *options);
|
||||
|
||||
// Destructor
|
||||
~Stats();
|
||||
@@ -75,13 +77,13 @@ public:
|
||||
void init();
|
||||
|
||||
// Añade una muerte a las estadisticas
|
||||
void addDeath(std::string name);
|
||||
void addDeath(string name);
|
||||
|
||||
// Añade una visita a las estadisticas
|
||||
void addVisit(std::string name);
|
||||
void addVisit(string name);
|
||||
|
||||
// Añade una entrada al diccionario
|
||||
void addDictionary(std::string number, std::string name);
|
||||
void addDictionary(string number, string name);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user