diff --git a/main.cpp b/main.cpp index 9e22f5f..4c985fb 100644 --- a/main.cpp +++ b/main.cpp @@ -97,6 +97,13 @@ int main(int argc, char *argv[]) input->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN); input->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT); input->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT); + string controllerName = ""; + int numControllers= input->getNumControllers(); + if (numControllers>0) + { + controllerName=getControllerName(1); + } + // Inicializa el texto Text *text = new Text(asset->get("smb2.txt"), asset->get("smb2.png"), renderer); diff --git a/units/animatedsprite.cpp b/units/animatedsprite.cpp index 6ce6729..7e339d6 100644 --- a/units/animatedsprite.cpp +++ b/units/animatedsprite.cpp @@ -1,7 +1,7 @@ #include "animatedsprite.h" // Carga la animación desde un fichero -animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, bool verbose) +animatedSprite_t loadAnimationFromFile(Texture *texture, string filePath, bool verbose) { // Inicializa variables animatedSprite_t as; @@ -11,9 +11,9 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b int frameHeight = 0; int maxTiles = 0; - const std::string filename = filePath.substr(filePath.find_last_of("\\/") + 1); - std::ifstream file(filePath); - std::string line; + const string filename = filePath.substr(filePath.find_last_of("\\/") + 1); + ifstream file(filePath); + string line; // El fichero se puede abrir if (file.good()) @@ -21,9 +21,9 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b // Procesa el fichero linea a linea if (verbose) { - std::cout << "Animation loaded: " << filename << std::endl; + cout << "Animation loaded: " << filename << endl; } - while (std::getline(file, line)) + while (getline(file, line)) { // Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación if (line == "[animation]") @@ -35,7 +35,7 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b do { - std::getline(file, line); + getline(file, line); // Encuentra la posición del caracter '=' int pos = line.find("="); @@ -50,24 +50,24 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b else if (line.substr(0, pos) == "speed") { - buffer.speed = std::stoi(line.substr(pos + 1, line.length())); + buffer.speed = stoi(line.substr(pos + 1, line.length())); } else if (line.substr(0, pos) == "loop") { - buffer.loop = std::stoi(line.substr(pos + 1, line.length())); + buffer.loop = stoi(line.substr(pos + 1, line.length())); } else if (line.substr(0, pos) == "frames") { // Se introducen los valores separados por comas en un vector - std::stringstream ss(line.substr(pos + 1, line.length())); - std::string tmp; + stringstream ss(line.substr(pos + 1, line.length())); + string tmp; SDL_Rect rect = {0, 0, frameWidth, frameHeight}; while (getline(ss, tmp, ',')) { // Comprueba que el tile no sea mayor que el maximo indice permitido - const int numTile = std::stoi(tmp) > maxTiles ? 0 : std::stoi(tmp); + const int numTile = stoi(tmp) > maxTiles ? 0 : stoi(tmp); rect.x = (numTile % framesPerRow) * frameWidth; rect.y = (numTile / framesPerRow) * frameHeight; buffer.frames.push_back(rect); @@ -76,7 +76,7 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b else { - 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 != "[/animation]"); @@ -96,22 +96,22 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b { if (line.substr(0, pos) == "framesPerRow") { - framesPerRow = std::stoi(line.substr(pos + 1, line.length())); + framesPerRow = stoi(line.substr(pos + 1, line.length())); } else if (line.substr(0, pos) == "frameWidth") { - frameWidth = std::stoi(line.substr(pos + 1, line.length())); + frameWidth = stoi(line.substr(pos + 1, line.length())); } else if (line.substr(0, pos) == "frameHeight") { - frameHeight = std::stoi(line.substr(pos + 1, line.length())); + frameHeight = stoi(line.substr(pos + 1, line.length())); } else { - 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; } // Normaliza valores @@ -138,7 +138,7 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b { if (verbose) { - std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl; + cout << "Warning: Unable to open " << filename.c_str() << " file" << endl; } } @@ -146,9 +146,9 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b } // Constructor -AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, std::string file, std::vector *buffer) +AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, string file, vector *buffer) { - //std::cout << "Creado AnimatedSprite" << std::endl; + //cout << "Creado AnimatedSprite" << endl; // Copia los punteros setTexture(texture); setRenderer(renderer); @@ -177,7 +177,7 @@ AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, std::st // Constructor AnimatedSprite::AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation) { - //std::cout << "Creado AnimatedSprite" << std::endl; + //cout << "Creado AnimatedSprite" << endl; // Copia los punteros setTexture(animation->texture); setRenderer(renderer); @@ -195,7 +195,7 @@ AnimatedSprite::AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animati // Destructor AnimatedSprite::~AnimatedSprite() { - //std::cout << "Destruido AnimatedSprite" << std::endl; + //cout << "Destruido AnimatedSprite" << endl; for (auto &a : animation) { a.frames.clear(); @@ -204,7 +204,7 @@ AnimatedSprite::~AnimatedSprite() } // Obtiene el indice de la animación a partir del nombre -int AnimatedSprite::getIndex(std::string name) +int AnimatedSprite::getIndex(string name) { int index = -1; @@ -217,7 +217,7 @@ int AnimatedSprite::getIndex(std::string name) } } - std::cout << "** Warning: could not find \"" << name.c_str() << "\" animation" << std::endl; + cout << "** Warning: could not find \"" << name.c_str() << "\" animation" << endl; return -1; } @@ -283,13 +283,13 @@ void AnimatedSprite::setCurrentFrame(int num) } // Establece el valor del contador -void AnimatedSprite::setAnimationCounter(std::string name, int num) +void AnimatedSprite::setAnimationCounter(string name, int num) { animation[getIndex(name)].counter = num; } // Establece la velocidad de una animación -void AnimatedSprite::setAnimationSpeed(std::string name, int speed) +void AnimatedSprite::setAnimationSpeed(string name, int speed) { animation[getIndex(name)].counter = speed; } @@ -301,7 +301,7 @@ void AnimatedSprite::setAnimationSpeed(int index, int speed) } // Establece si la animación se reproduce en bucle -void AnimatedSprite::setAnimationLoop(std::string name, int loop) +void AnimatedSprite::setAnimationLoop(string name, int loop) { animation[getIndex(name)].loop = loop; } @@ -313,7 +313,7 @@ void AnimatedSprite::setAnimationLoop(int index, int loop) } // Establece el valor de la variable -void AnimatedSprite::setAnimationCompleted(std::string name, bool value) +void AnimatedSprite::setAnimationCompleted(string name, bool value) { animation[getIndex(name)].completed = value; } @@ -331,7 +331,7 @@ bool AnimatedSprite::animationIsCompleted() } // Devuelve el rectangulo de una animación y frame concreto -SDL_Rect AnimatedSprite::getAnimationClip(std::string name, Uint8 index) +SDL_Rect AnimatedSprite::getAnimationClip(string name, Uint8 index) { return animation[getIndex(name)].frames[index]; } @@ -343,7 +343,7 @@ SDL_Rect AnimatedSprite::getAnimationClip(int indexA, Uint8 indexF) } // Carga la animación desde un vector -bool AnimatedSprite::loadFromVector(std::vector *source) +bool AnimatedSprite::loadFromVector(vector *source) { // Inicializa variables int framesPerRow = 0; @@ -353,7 +353,7 @@ bool AnimatedSprite::loadFromVector(std::vector *source) // Indicador de éxito en el proceso bool success = true; - std::string line; + string line; // Recorre todo el vector int index = 0; @@ -389,24 +389,24 @@ bool AnimatedSprite::loadFromVector(std::vector *source) else if (line.substr(0, pos) == "speed") { - buffer.speed = std::stoi(line.substr(pos + 1, line.length())); + buffer.speed = stoi(line.substr(pos + 1, line.length())); } else if (line.substr(0, pos) == "loop") { - buffer.loop = std::stoi(line.substr(pos + 1, line.length())); + buffer.loop = stoi(line.substr(pos + 1, line.length())); } else if (line.substr(0, pos) == "frames") { // Se introducen los valores separados por comas en un vector - std::stringstream ss(line.substr(pos + 1, line.length())); - std::string tmp; + stringstream ss(line.substr(pos + 1, line.length())); + string tmp; SDL_Rect rect = {0, 0, frameWidth, frameHeight}; while (getline(ss, tmp, ',')) { // Comprueba que el tile no sea mayor que el maximo indice permitido - const int numTile = std::stoi(tmp) > maxTiles ? 0 : std::stoi(tmp); + const int numTile = stoi(tmp) > maxTiles ? 0 : stoi(tmp); rect.x = (numTile % framesPerRow) * frameWidth; rect.y = (numTile / framesPerRow) * frameHeight; buffer.frames.push_back(rect); @@ -415,7 +415,7 @@ bool AnimatedSprite::loadFromVector(std::vector *source) else { - std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl; + cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << endl; success = false; } } @@ -436,22 +436,22 @@ bool AnimatedSprite::loadFromVector(std::vector *source) { if (line.substr(0, pos) == "framesPerRow") { - framesPerRow = std::stoi(line.substr(pos + 1, line.length())); + framesPerRow = stoi(line.substr(pos + 1, line.length())); } else if (line.substr(0, pos) == "frameWidth") { - frameWidth = std::stoi(line.substr(pos + 1, line.length())); + frameWidth = stoi(line.substr(pos + 1, line.length())); } else if (line.substr(0, pos) == "frameHeight") { - frameHeight = std::stoi(line.substr(pos + 1, line.length())); + frameHeight = stoi(line.substr(pos + 1, line.length())); } else { - std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl; + cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << endl; success = false; } @@ -481,7 +481,7 @@ bool AnimatedSprite::loadFromVector(std::vector *source) } // Establece la animacion actual -void AnimatedSprite::setCurrentAnimation(std::string name) +void AnimatedSprite::setCurrentAnimation(string name) { const int newAnimation = getIndex(name); if (currentAnimation != newAnimation) diff --git a/units/animatedsprite.h b/units/animatedsprite.h index 97b4e36..6d6fbd5 100644 --- a/units/animatedsprite.h +++ b/units/animatedsprite.h @@ -11,10 +11,12 @@ #ifndef ANIMATEDSPRITE_H #define ANIMATEDSPRITE_H +using namespace std; + struct animation_t { - std::string name; // Nombre de la animacion - std::vector frames; // Cada uno de los frames que componen la animación + string name; // Nombre de la animacion + vector frames; // Cada uno de los frames que componen la animación int speed; // Velocidad de la animación int loop; // Indica a que frame vuelve la animación al terminar. -1 para que no vuelva bool completed; // Indica si ha finalizado la animación @@ -24,23 +26,23 @@ struct animation_t struct animatedSprite_t { - std::vector animations; // Vector con las diferentes animaciones + vector animations; // Vector con las diferentes animaciones Texture *texture; // Textura con los graficos para el sprite }; // Carga la animación desde un fichero -animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, bool verbose = false); +animatedSprite_t loadAnimationFromFile(Texture *texture, string filePath, bool verbose = false); class AnimatedSprite : public MovingSprite { private: // Variables - std::vector animation; // Vector con las diferentes animaciones + vector animation; // Vector con las diferentes animaciones int currentAnimation; // Animacion activa public: // Constructor - AnimatedSprite(Texture *texture = nullptr, SDL_Renderer *renderer = nullptr, std::string file = "", std::vector *buffer = nullptr); + AnimatedSprite(Texture *texture = nullptr, SDL_Renderer *renderer = nullptr, string file = "", vector *buffer = nullptr); AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation); // Destructor @@ -56,35 +58,35 @@ public: void setCurrentFrame(int num); // Establece el valor del contador - void setAnimationCounter(std::string name, int num); + void setAnimationCounter(string name, int num); // Establece la velocidad de una animación - void setAnimationSpeed(std::string name, int speed); + void setAnimationSpeed(string name, int speed); void setAnimationSpeed(int index, int speed); // Establece el frame al que vuelve la animación al finalizar - void setAnimationLoop(std::string name, int loop); + void setAnimationLoop(string name, int loop); void setAnimationLoop(int index, int loop); // Establece el valor de la variable - void setAnimationCompleted(std::string name, bool value); + void setAnimationCompleted(string name, bool value); void setAnimationCompleted(int index, bool value); // Comprueba si ha terminado la animación bool animationIsCompleted(); // Devuelve el rectangulo de una animación y frame concreto - SDL_Rect getAnimationClip(std::string name = "default", Uint8 index = 0); + SDL_Rect getAnimationClip(string name = "default", Uint8 index = 0); SDL_Rect getAnimationClip(int indexA = 0, Uint8 indexF = 0); // Obtiene el indice de la animación a partir del nombre - int getIndex(std::string name); + int getIndex(string name); // Carga la animación desde un vector - bool loadFromVector(std::vector *source); + bool loadFromVector(vector *source); // Establece la animacion actual - void setCurrentAnimation(std::string name = "default"); + void setCurrentAnimation(string name = "default"); void setCurrentAnimation(int index = 0); // Actualiza las variables del objeto diff --git a/units/asset.cpp b/units/asset.cpp index d1e0255..e11e176 100644 --- a/units/asset.cpp +++ b/units/asset.cpp @@ -2,9 +2,9 @@ #include // Constructor -Asset::Asset(std::string executablePath) +Asset::Asset(string executablePath) { - //std::cout << "Construido Asset" << std::endl; + //cout << "Construido Asset" << endl; this->executablePath = executablePath.substr(0, executablePath.find_last_of("\\/")); longestName = 0; verbose = true; @@ -13,11 +13,11 @@ Asset::Asset(std::string executablePath) // Destructot Asset::~Asset() { - //std::cout << "Destruido Asset" << std::endl; + //cout << "Destruido Asset" << endl; } // Añade un elemento a la lista -void Asset::add(std::string file, enum assetType type, bool required, bool absolute) +void Asset::add(string file, enum assetType type, bool required, bool absolute) { item_t temp; temp.file = absolute ? file : executablePath + file; @@ -25,17 +25,17 @@ void Asset::add(std::string file, enum assetType type, bool required, bool absol temp.required = required; fileList.push_back(temp); - const std::string filename = file.substr(file.find_last_of("\\/") + 1); + const string filename = file.substr(file.find_last_of("\\/") + 1); longestName = SDL_max(longestName, filename.size()); } // Devuelve el fichero de un elemento de la lista a partir de una cadena -std::string Asset::get(std::string text) +string Asset::get(string text) { for (auto f : fileList) { const size_t lastIndex = f.file.find_last_of("/") + 1; - const std::string file = f.file.substr(lastIndex, std::string::npos); + const string file = f.file.substr(lastIndex, string::npos); if (file == text) { @@ -45,7 +45,7 @@ std::string Asset::get(std::string text) if (verbose) { - std::cout << "Warning: file " << text.c_str() << " not found" << std::endl; + cout << "Warning: file " << text.c_str() << " not found" << endl; } return ""; } @@ -57,10 +57,10 @@ bool Asset::check() if (verbose) { - std::cout << "\n** Checking files" << std::endl; + cout << "\n** Checking files" << endl; - std::cout << "Executable path is: " << executablePath << std::endl; - std::cout << "Sample filepath: " << fileList.back().file << std::endl; + cout << "Executable path is: " << executablePath << endl; + cout << "Sample filepath: " << fileList.back().file << endl; } // Comprueba la lista de ficheros clasificandolos por tipo @@ -82,7 +82,7 @@ bool Asset::check() { if (verbose) { - std::cout << "\n>> " << getTypeName(type).c_str() << " FILES" << std::endl; + cout << "\n>> " << getTypeName(type).c_str() << " FILES" << endl; } for (auto f : fileList) @@ -100,13 +100,13 @@ bool Asset::check() { if (success) { - std::cout << "\n** All files OK.\n" - << std::endl; + cout << "\n** All files OK.\n" + << endl; } else { - std::cout << "\n** A file is missing. Exiting.\n" - << std::endl; + cout << "\n** A file is missing. Exiting.\n" + << endl; } } @@ -114,13 +114,13 @@ bool Asset::check() } // Comprueba que existe un fichero -bool Asset::checkFile(std::string path) +bool Asset::checkFile(string path) { bool success = false; - std::string result = "ERROR"; + string result = "ERROR"; // Comprueba si existe el fichero - const std::string filename = path.substr(path.find_last_of("\\/") + 1); + const string filename = path.substr(path.find_last_of("\\/") + 1); SDL_RWops *file = SDL_RWFromFile(path.c_str(), "rb"); if (file != nullptr) @@ -132,19 +132,19 @@ bool Asset::checkFile(std::string path) if (verbose) { - std::cout.setf(std::ios::left, std::ios::adjustfield); - std::cout << "Checking file: "; - std::cout.width(longestName + 2); - std::cout.fill('.'); - std::cout << filename + " "; - std::cout << " [" + result + "]" << std::endl; + cout.setf(ios::left, ios::adjustfield); + cout << "Checking file: "; + cout.width(longestName + 2); + cout.fill('.'); + cout << filename + " "; + cout << " [" + result + "]" << endl; } return success; } // Devuelve el nombre del tipo de recurso -std::string Asset::getTypeName(int type) +string Asset::getTypeName(int type) { switch (type) { diff --git a/units/asset.h b/units/asset.h index c1040f8..9cd50f5 100644 --- a/units/asset.h +++ b/units/asset.h @@ -7,6 +7,8 @@ #ifndef ASSET_H #define ASSET_H +using namespace std; + enum assetType { t_bitmap, @@ -28,7 +30,7 @@ private: // Estructura para definir un item struct item_t { - std::string file; // Ruta del fichero desde la raiz del directorio + string file; // Ruta del fichero desde la raiz del directorio enum assetType type; // Indica el tipo de recurso bool required; // Indica si es un fichero que debe de existir //bool absolute; // Indica si la ruta que se ha proporcionado es una ruta absoluta @@ -36,28 +38,28 @@ private: // Variables int longestName; // Contiene la longitud del nombre de fichero mas largo - std::vector fileList; // Listado con todas las rutas a los ficheros - std::string executablePath; // Ruta al ejecutable + vector fileList; // Listado con todas las rutas a los ficheros + string executablePath; // Ruta al ejecutable bool verbose; // Indica si ha de mostrar información por pantalla // Comprueba que existe un fichero - bool checkFile(std::string executablePath); + bool checkFile(string executablePath); // Devuelve el nombre del tipo de recurso - std::string getTypeName(int type); + string getTypeName(int type); public: // Constructor - Asset(std::string path); + Asset(string path); // Destructor ~Asset(); // Añade un elemento a la lista - void add(std::string file, enum assetType type, bool required = true, bool absolute = false); + void add(string file, enum assetType type, bool required = true, bool absolute = false); // Devuelve un elemento de la lista a partir de una cadena - std::string get(std::string text); + string get(string text); // Comprueba que existen todos los elementos bool check(); diff --git a/units/debug.cpp b/units/debug.cpp index c3b1bc8..b941dc0 100644 --- a/units/debug.cpp +++ b/units/debug.cpp @@ -39,7 +39,7 @@ void Debug::render() for (auto s : slot) { text->write(x, y, s); - w = (std::max(w, (int)s.length())); + w = (max(w, (int)s.length())); y += text->getCharacterSize() + 1; if (y > 192 - text->getCharacterSize()) { @@ -64,7 +64,7 @@ void Debug::setPos(SDL_Point p) } // Añade un texto para mostrar -void Debug::add(std::string text) +void Debug::add(string text) { slot.push_back(text); } @@ -76,7 +76,7 @@ void Debug::clear() } // Añade un texto para mostrar en el apartado log -void Debug::addToLog(std::string text) +void Debug::addToLog(string text) { log.push_back(text); } diff --git a/units/debug.h b/units/debug.h index 6546ab1..5632df9 100644 --- a/units/debug.h +++ b/units/debug.h @@ -12,6 +12,8 @@ #ifndef DEBUG_H #define DEBUG_H +using namespace std; + // Clase Debug class Debug { @@ -24,8 +26,8 @@ private: Texture *texture; // Textura para el texto // Variables - std::vector slot; // Vector con los textos a escribir - std::vector log; // Vector con los textos a escribir + vector slot; // Vector con los textos a escribir + vector log; // Vector con los textos a escribir int x; // Posicion donde escribir el texto de debug int y; // Posición donde escribir el texto de debug bool enabled; // Indica si esta activo el modo debug @@ -47,13 +49,13 @@ public: void setPos(SDL_Point p); // Añade un texto para mostrar - void add(std::string text); + void add(string text); // Borra la información de debug void clear(); // Añade un texto para mostrar en el apartado log - void addToLog(std::string text); + void addToLog(string text); // Borra la información de debug del apartado log void clearLog(); diff --git a/units/input.cpp b/units/input.cpp index 4277c85..c423644 100644 --- a/units/input.cpp +++ b/units/input.cpp @@ -2,7 +2,7 @@ #include // Constructor -Input::Input(std::string file) +Input::Input(string file) { // Fichero gamecontrollerdb.txt dbPath = file; @@ -201,7 +201,7 @@ bool Input::discoverGameController() { if (verbose) { - std::cout << "Error, could not load " << dbPath.c_str() << " file: " << SDL_GetError() << std::endl; + cout << "Error, could not load " << dbPath.c_str() << " file: " << SDL_GetError() << endl; } } @@ -219,8 +219,8 @@ bool Input::discoverGameController() if (verbose) { - std::cout << "\nChecking for game controllers...\n"; - std::cout << nJoysticks << " joysticks found, " << numGamepads << " are gamepads\n"; + cout << "\nChecking for game controllers...\n"; + cout << nJoysticks << " joysticks found, " << numGamepads << " are gamepads\n"; } if (numGamepads > 0) @@ -234,13 +234,13 @@ bool Input::discoverGameController() if (SDL_GameControllerGetAttached(pad) == 1) { connectedControllers.push_back(pad); - const std::string separator(" #"); - std::string name = SDL_GameControllerNameForIndex(i); + const string separator(" #"); + string name = SDL_GameControllerNameForIndex(i); name.resize(25); - name = name + separator + std::to_string(i); + name = name + separator + to_string(i); if (verbose) { - std::cout << name << std::endl; + cout << name << endl; } controllerNames.push_back(name); } @@ -248,7 +248,7 @@ bool Input::discoverGameController() { if (verbose) { - std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl; + cout << "SDL_GetError() = " << SDL_GetError() << endl; } } } @@ -273,7 +273,7 @@ bool Input::gameControllerFound() } // Obten el nombre de un mando de juego -std::string Input::getControllerName(int index) +string Input::getControllerName(int index) { if (numGamepads > 0) { diff --git a/units/input.h b/units/input.h index 5d039f9..ad8491f 100644 --- a/units/input.h +++ b/units/input.h @@ -7,6 +7,8 @@ #ifndef INPUT_H #define INPUT_H +using namespace std; + // Tipos diferentes de eventos de entrada #define INPUT_NULL 0 #define INPUT_UP 1 @@ -72,21 +74,21 @@ private: }; // Objetos y punteros - std::vector connectedControllers; // Vector con todos los mandos conectados + vector connectedControllers; // Vector con todos los mandos conectados // Variables - std::vector keyBindings; // Vector con las teclas asociadas a los inputs predefinidos - std::vector gameControllerBindings; // Vector con las teclas asociadas a los inputs predefinidos - std::vector controllerNames; // Vector con los nombres de los mandos + vector keyBindings; // Vector con las teclas asociadas a los inputs predefinidos + vector gameControllerBindings; // Vector con las teclas asociadas a los inputs predefinidos + vector controllerNames; // Vector con los nombres de los mandos int numGamepads; // Numero de mandos conectados - std::string dbPath; // Ruta al archivo gamecontrollerdb.txt + string dbPath; // Ruta al archivo gamecontrollerdb.txt bool verbose; // Indica si ha de mostrar mensajes i_disable_e disabledUntil; // Tiempo que esta deshabilitado bool enabled; // Indica si está habilitado public: // Constructor - Input(std::string file); + Input(string file); // Actualiza el estado del objeto void update(); @@ -113,7 +115,7 @@ public: int getNumControllers(); // Obten el nombre de un mando de juego - std::string getControllerName(int index); + string getControllerName(int index); // Establece si ha de mostrar mensajes void setVerbose(bool value); diff --git a/units/menu.cpp b/units/menu.cpp index 8ccd827..1ba6d95 100644 --- a/units/menu.cpp +++ b/units/menu.cpp @@ -1,8 +1,8 @@ #include "menu.h" // Constructor -//Menu::Menu(SDL_Renderer *renderer, Resource *resource, Asset *asset, Input *input, std::string file) -Menu::Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file) +//Menu::Menu(SDL_Renderer *renderer, Resource *resource, Asset *asset, Input *input, string file) +Menu::Menu(SDL_Renderer *renderer, Asset *asset, Input *input, string file) { // Copia punteros this->renderer = renderer; @@ -91,7 +91,7 @@ Menu::~Menu() } // Carga la configuración del menu desde un archivo de texto -bool Menu::load(std::string file_path) +bool Menu::load(string file_path) { // Indicador de éxito en la carga bool success = true; @@ -99,16 +99,16 @@ bool Menu::load(std::string file_path) // Indica si se ha creado ya el objeto de texto bool textAllocated = false; - const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1); - std::string line; - std::ifstream file(file_path); + 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 - std::cout << "Reading file " << filename.c_str() << std::endl; - while (std::getline(file, line)) + cout << "Reading file " << filename.c_str() << endl; + while (getline(file, line)) { if (line == "[item]") { @@ -122,7 +122,7 @@ bool Menu::load(std::string file_path) do { // Lee la siguiente linea - std::getline(file, line); + getline(file, line); // Encuentra la posición del caracter '=' int pos = line.find("="); @@ -130,7 +130,7 @@ bool Menu::load(std::string file_path) // Procesa las dos subcadenas if (!setItem(&item, line.substr(0, pos), line.substr(pos + 1, line.length()))) { - 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; success = false; } @@ -147,7 +147,7 @@ bool Menu::load(std::string file_path) // Procesa las dos subcadenas if (!setVars(line.substr(0, pos), line.substr(pos + 1, line.length()))) { - 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; success = false; } @@ -161,13 +161,13 @@ bool Menu::load(std::string file_path) } // Cierra el fichero - std::cout << "Closing file " << filename.c_str() << std::endl; + cout << "Closing file " << filename.c_str() << endl; file.close(); } // El fichero no se puede abrir else { - std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl; + cout << "Warning: Unable to open " << filename.c_str() << " file" << endl; success = false; } @@ -175,7 +175,7 @@ bool Menu::load(std::string file_path) } // Asigna variables a partir de dos cadenas -bool Menu::setItem(item_t *item, std::string var, std::string value) +bool Menu::setItem(item_t *item, string var, string value) { // Indicador de éxito en la asignación bool success = true; @@ -187,7 +187,7 @@ bool Menu::setItem(item_t *item, std::string var, std::string value) else if (var == "hPaddingDown") { - item->hPaddingDown = std::stoi(value); + item->hPaddingDown = stoi(value); } else if (var == "selectable") @@ -218,7 +218,7 @@ bool Menu::setItem(item_t *item, std::string var, std::string value) } // Asigna variables a partir de dos cadenas -bool Menu::setVars(std::string var, std::string value) +bool Menu::setVars(string var, string value) { // Indicador de éxito en la asignación bool success = true; @@ -255,70 +255,70 @@ bool Menu::setVars(std::string var, std::string value) else if (var == "x") { - x = std::stoi(value); + x = stoi(value); } else if (var == "centerX") { - centerX = std::stoi(value); + centerX = stoi(value); } else if (var == "centerY") { - centerY = std::stoi(value); + centerY = stoi(value); } else if (var == "y") { - y = std::stoi(value); + y = stoi(value); } else if (var == "backgroundType") { - backgroundType = std::stoi(value); + backgroundType = stoi(value); } else if (var == "backgroundColor") { // Se introducen los valores separados por comas en un vector - std::stringstream ss(value); - std::string tmp; + stringstream ss(value); + string tmp; getline(ss, tmp, ','); - rectBG.color.r = std::stoi(tmp); + rectBG.color.r = stoi(tmp); getline(ss, tmp, ','); - rectBG.color.g = std::stoi(tmp); + rectBG.color.g = stoi(tmp); getline(ss, tmp, ','); - rectBG.color.b = std::stoi(tmp); + rectBG.color.b = stoi(tmp); getline(ss, tmp, ','); - rectBG.a = std::stoi(tmp); + rectBG.a = stoi(tmp); } else if (var == "selector_color") { // Se introducen los valores separados por comas en un vector - std::stringstream ss(value); - std::string tmp; + stringstream ss(value); + string tmp; getline(ss, tmp, ','); - selector.color.r = std::stoi(tmp); + selector.color.r = stoi(tmp); getline(ss, tmp, ','); - selector.color.g = std::stoi(tmp); + selector.color.g = stoi(tmp); getline(ss, tmp, ','); - selector.color.b = std::stoi(tmp); + selector.color.b = stoi(tmp); getline(ss, tmp, ','); - selector.a = std::stoi(tmp); + selector.a = stoi(tmp); } else if (var == "selector_text_color") { // Se introducen los valores separados por comas en un vector - std::stringstream ss(value); - std::string tmp; + stringstream ss(value); + string tmp; getline(ss, tmp, ','); - selector.itemColor.r = std::stoi(tmp); + selector.itemColor.r = stoi(tmp); getline(ss, tmp, ','); - selector.itemColor.g = std::stoi(tmp); + selector.itemColor.g = stoi(tmp); getline(ss, tmp, ','); - selector.itemColor.b = std::stoi(tmp); + selector.itemColor.b = stoi(tmp); } else if (var == "areElementsCenteredOnX") @@ -338,7 +338,7 @@ bool Menu::setVars(std::string var, std::string value) else if (var == "defaultActionWhenCancel") { - defaultActionWhenCancel = std::stoi(value); + defaultActionWhenCancel = stoi(value); } else if (var == "") @@ -354,7 +354,7 @@ bool Menu::setVars(std::string var, std::string value) } // Carga los ficheros de audio -void Menu::loadAudioFile(std::string file, int sound) +void Menu::loadAudioFile(string file, int sound) { switch (sound) { @@ -376,7 +376,7 @@ void Menu::loadAudioFile(std::string file, int sound) } // Obtiene el nombre del menu -std::string Menu::getName() +string Menu::getName() { return name; } @@ -475,7 +475,7 @@ int Menu::getWidestItem() // Obtenemos la anchura del item mas ancho for (auto &i : item) { - result = std::max(result, i.rect.w); + result = max(result, i.rect.w); } return result; @@ -797,7 +797,7 @@ void Menu::centerMenuElementsOnX() } // Añade un item al menu -void Menu::addItem(std::string text, int hPaddingDown, bool selectable, bool greyed, bool linkedDown) +void Menu::addItem(string text, int hPaddingDown, bool selectable, bool greyed, bool linkedDown) { item_t temp; @@ -833,7 +833,7 @@ void Menu::addItem(std::string text, int hPaddingDown, bool selectable, bool gre } // Cambia el texto de un item -void Menu::setItemCaption(int index, std::string text) +void Menu::setItemCaption(int index, string text) { item[index].label = text; item[index].rect.w = this->text->lenght(item[index].label); @@ -954,7 +954,7 @@ int Menu::getSelectorHeight(int value) } // Establece el nombre del menu -void Menu::setName(std::string name) +void Menu::setName(string name) { this->name = name; } @@ -973,7 +973,7 @@ void Menu::setBackgroundType(int value) } // Establece la fuente de texto que se utilizará -void Menu::setText(std::string font_png, std::string font_txt) +void Menu::setText(string font_png, string font_txt) { if (!text) { diff --git a/units/menu.h b/units/menu.h index a2f7c0b..585513f 100644 --- a/units/menu.h +++ b/units/menu.h @@ -15,6 +15,8 @@ #ifndef MENU_H #define MENU_H +using namespace std; + // Tipos de fondos para el menu #define MENU_BACKGROUND_TRANSPARENT 0 #define MENU_BACKGROUND_SOLID 1 @@ -40,7 +42,7 @@ private: struct item_t { - std::string label; // Texto + string label; // Texto SDL_Rect rect; // Rectangulo que delimita el elemento int hPaddingDown; // Espaciado bajo el elemento bool selectable; // Indica si se puede seleccionar @@ -77,7 +79,7 @@ private: Input *input; // Gestor de eventos de entrada de teclado o gamepad // Variables - std::string name; // Nombre del menu + string name; // Nombre del menu int x; // Posición en el eje X de la primera letra del primer elemento int y; // Posición en el eje Y de la primera letra del primer elemento int h; // Altura del menu @@ -96,19 +98,19 @@ private: JA_Sound_t* soundMove; // Sonido al mover el selector color_t colorGreyed; // Color para los elementos agrisados rectangle_t rectBG; // Rectangulo de fondo del menu - std::vector item; // Estructura para cada elemento del menu + vector item; // Estructura para cada elemento del menu selector_t selector; // Variables para pintar el selector del menu - std::string font_png; - std::string font_txt; + string font_png; + string font_txt; // Carga la configuración del menu desde un archivo de texto - bool load(std::string file_path); + bool load(string file_path); // Asigna variables a partir de dos cadenas - bool setVars(std::string var, std::string value); + bool setVars(string var, string value); // Asigna variables a partir de dos cadenas - bool setItem(item_t *item, std::string var, std::string value); + bool setItem(item_t *item, string var, string value); // Actualiza el menu para recolocarlo correctamente y establecer el tamaño void reorganize(); @@ -142,17 +144,17 @@ private: public: // Constructor - //Menu(SDL_Renderer *renderer, Resource *resource, Asset *asset, Input *input, std::string file = ""); - Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file = ""); + //Menu(SDL_Renderer *renderer, Resource *resource, Asset *asset, Input *input, string file = ""); + Menu(SDL_Renderer *renderer, Asset *asset, Input *input, string file = ""); // Destructor ~Menu(); // Carga los ficheros de audio - void loadAudioFile(std::string file, int sound); + void loadAudioFile(string file, int sound); // Obtiene el nombre del menu - std::string getName(); + string getName(); // Obtiene el valor de la variable int getItemSelected(); @@ -188,10 +190,10 @@ public: void centerMenuElementsOnX(); // Añade un item al menu - void addItem(std::string text, int hPaddingDown = 1, bool selectable = true, bool greyed = false, bool linkedDown = false); + void addItem(string text, int hPaddingDown = 1, bool selectable = true, bool greyed = false, bool linkedDown = false); // Cambia el texto de un item - void setItemCaption(int index, std::string text); + void setItemCaption(int index, string text); // Establece el indice del item que se usará por defecto al cancelar el menu void setDefaultActionWhenCancel(int item); @@ -209,7 +211,7 @@ public: void setLinkedDown(int index, bool value); // Establece el nombre del menu - void setName(std::string name); + void setName(string name); // Establece la posición del menu void setPos(int x, int y); @@ -218,7 +220,7 @@ public: void setBackgroundType(int value); // Establece la fuente de texto que se utilizará - void setText(std::string font_png, std::string font_txt); + void setText(string font_png, string font_txt); // Establece el rectangulo de fondo del menu void setRectSize(int w = 0, int h = 0); diff --git a/units/screen.cpp b/units/screen.cpp index 3d50406..6e72207 100644 --- a/units/screen.cpp +++ b/units/screen.cpp @@ -5,7 +5,7 @@ // Constructor Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options) { - //std::cout << "Construido Screen" << std::endl; + //cout << "Construido Screen" << endl; // Inicializa variables this->window = window; this->renderer = renderer; @@ -26,7 +26,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options) { if (options->console) { - std::cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << std::endl; + cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << endl; } } SDL_SetTextureBlendMode(gameCanvas, SDL_BLENDMODE_BLEND); @@ -38,7 +38,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options) // Destructor Screen::~Screen() { - //std::cout << "Destruido Screen" << std::endl; + //cout << "Destruido Screen" << endl; if (notify != nullptr) { delete notify; @@ -195,7 +195,7 @@ void Screen::setWindowSize(int size) void Screen::decWindowSize() { --options->screen.windowZoom; - options->screen.windowZoom = std::max(options->screen.windowZoom, 1); + options->screen.windowZoom = max(options->screen.windowZoom, 1); setVideoMode(0); } @@ -203,7 +203,7 @@ void Screen::decWindowSize() void Screen::incWindowSize() { ++options->screen.windowZoom; - options->screen.windowZoom = std::min(options->screen.windowZoom, 4); + options->screen.windowZoom = min(options->screen.windowZoom, 4); setVideoMode(0); } @@ -327,7 +327,7 @@ void Screen::iniSpectrumFade() spectrumColor.clear(); // Inicializa el vector de colores - const std::vector vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"}; + const vector vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"}; for (auto v : vColors) { spectrumColor.push_back(stringToColor(options->palette, v)); @@ -392,7 +392,7 @@ void Screen::updateNotifier() } // Muestra una notificación de texto por pantalla; -void Screen::showNotification(std::string text1, std::string text2, int icon) +void Screen::showNotification(string text1, string text2, int icon) { notify->showText(text1, text2, icon); } diff --git a/units/screen.h b/units/screen.h index e7ad871..de6a23e 100644 --- a/units/screen.h +++ b/units/screen.h @@ -8,6 +8,8 @@ #ifndef SCREEN_H #define SCREEN_H +using namespace std; + #define FILTER_NEAREST 0 #define FILTER_LINEAL 1 @@ -38,7 +40,7 @@ private: bool spectrumFade; // Indica si esta activo el efecto de fade spectrum int spectrumFadeCounter; // Temporizador para el efecto de fade spectrum int spectrumFadeLenght; // Duración del fade spectrum - std::vector spectrumColor; // Colores para el fade spectrum + vector spectrumColor; // Colores para el fade spectrum // Inicializa las variables para el fade void iniFade(); @@ -133,7 +135,7 @@ public: void updateNotifier(); // Muestra una notificación de texto por pantalla; - void showNotification(std::string text1 = "", std::string text2 = "", int icon = -1); + void showNotification(string text1 = "", string text2 = "", int icon = -1); // Actualiza la lógica del objeto void update(); diff --git a/units/texture.cpp b/units/texture.cpp index 35dc87b..93f9bbf 100644 --- a/units/texture.cpp +++ b/units/texture.cpp @@ -5,9 +5,9 @@ #include // Constructor -Texture::Texture(SDL_Renderer *renderer, std::string path, bool verbose) +Texture::Texture(SDL_Renderer *renderer, string path, bool verbose) { - //std::cout << "Construido Texture" << std::endl; + //cout << "Construido Texture" << endl; // Copia punteros this->renderer = renderer; this->path = path; @@ -27,16 +27,16 @@ Texture::Texture(SDL_Renderer *renderer, std::string path, bool verbose) // Destructor Texture::~Texture() { - //std::cout << "Destruido Texture" << std::endl; + //cout << "Destruido Texture" << endl; // Libera memoria unload(); } // Carga una imagen desde un fichero -bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer, bool verbose) +bool Texture::loadFromFile(string path, SDL_Renderer *renderer, bool verbose) { - const std::string filename = path.substr(path.find_last_of("\\/") + 1); + const string filename = path.substr(path.find_last_of("\\/") + 1); int req_format = STBI_rgb_alpha; int width, height, orig_format; unsigned char *data = stbi_load(path.c_str(), &width, &height, &orig_format, req_format); @@ -49,7 +49,7 @@ bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer, bool verbos { if (verbose) { - std::cout << "Image loaded: " << filename.c_str() << std::endl; + cout << "Image loaded: " << filename.c_str() << endl; } } @@ -80,7 +80,7 @@ bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer, bool verbos { if (verbose) { - std::cout << "Unable to load image " << path.c_str() << std::endl; + cout << "Unable to load image " << path.c_str() << endl; } } else @@ -91,7 +91,7 @@ bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer, bool verbos { if (verbose) { - std::cout << "Unable to create texture from " << path.c_str() << "! SDL Error: " << SDL_GetError() << std::endl; + cout << "Unable to create texture from " << path.c_str() << "! SDL Error: " << SDL_GetError() << endl; } } else @@ -118,7 +118,7 @@ bool Texture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_Tex texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, access, width, height); if (texture == nullptr) { - std::cout << "Unable to create blank texture! SDL Error: " << SDL_GetError() << std::endl; + cout << "Unable to create blank texture! SDL Error: " << SDL_GetError() << endl; } else { diff --git a/units/texture.h b/units/texture.h index d83d7e2..afd8ce9 100644 --- a/units/texture.h +++ b/units/texture.h @@ -7,6 +7,8 @@ #ifndef TEXTURE_H #define TEXTURE_H +using namespace std; + class Texture { private: @@ -17,17 +19,17 @@ private: // Variables int width; // Ancho de la imagen int height; // Alto de la imagen - std::string path; // Ruta de la imagen de la textura + string path; // Ruta de la imagen de la textura public: // Constructor - Texture(SDL_Renderer *renderer, std::string path = "", bool verbose = false); + Texture(SDL_Renderer *renderer, string path = "", bool verbose = false); // Destructor ~Texture(); // Carga una imagen desde un fichero - bool loadFromFile(std::string path, SDL_Renderer *renderer, bool verbose = false); + bool loadFromFile(string path, SDL_Renderer *renderer, bool verbose = false); // Crea una textura en blanco bool createBlank(SDL_Renderer *renderer, int width, int height, SDL_TextureAccess = SDL_TEXTUREACCESS_STREAMING);