diff --git a/source/common/animatedsprite.cpp b/source/common/animatedsprite.cpp index bcc91d9..da71ee3 100644 --- a/source/common/animatedsprite.cpp +++ b/source/common/animatedsprite.cpp @@ -73,7 +73,7 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath) else { - printf("Warning: file %s, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str()); + std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl; } } } while (line != "[/animation]"); @@ -108,7 +108,7 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath) else { - printf("Warning: file %s, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str()); + std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl; } // Normaliza valores @@ -133,11 +133,11 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath) // El fichero no se puede abrir else { - printf("Warning: Unable to open %s file\n", filename.c_str()); + std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl; } // Pone un valor por defecto - //setRect({0, 0, frameWidth, frameHeight}); + // setRect({0, 0, frameWidth, frameHeight}); return as; } @@ -212,7 +212,7 @@ int AnimatedSprite::getIndex(std::string name) } } - printf("** Warning: could not find \"%s\" animation\n", name.c_str()); + std::cout << "** Warning: could not find \"" << name.c_str() << "\" animation" << std::endl; return -1; } @@ -409,7 +409,7 @@ animatedSprite_t AnimatedSprite::loadFromFile(std::string filePath) else { - printf("Warning: file %s, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str()); + std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl; } } } while (line != "[/animation]"); @@ -445,7 +445,7 @@ animatedSprite_t AnimatedSprite::loadFromFile(std::string filePath) else { - printf("Warning: file %s, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str()); + std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl; } // Normaliza valores @@ -470,7 +470,7 @@ animatedSprite_t AnimatedSprite::loadFromFile(std::string filePath) // El fichero no se puede abrir else { - printf("Warning: Unable to open %s file\n", filename.c_str()); + std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl; } // Pone un valor por defecto diff --git a/source/common/asset.cpp b/source/common/asset.cpp index bd598cf..2f9b926 100644 --- a/source/common/asset.cpp +++ b/source/common/asset.cpp @@ -1,4 +1,5 @@ #include "asset.h" +#include // Constructor Asset::Asset(std::string path) @@ -31,7 +32,7 @@ std::string Asset::get(std::string text) } } - printf("Warning: file %s not found\n", text.c_str()); + std::cout << "Warning: file " << text.c_str() << " not found" << std::endl; return ""; } @@ -40,7 +41,7 @@ bool Asset::check() { bool success = true; - printf("\n** Checking files.\n"); + std::cout << "\n** Checking files." << std::endl; // Comprueba la lista de ficheros clasificandolos por tipo for (int type = 0; type < t_maxAssetType; ++type) @@ -59,7 +60,7 @@ bool Asset::check() // Si hay ficheros de ese tipo, comprueba si existen if (any) { - printf("\n>> %s FILES\n", getTypeName(type).c_str()); + std::cout << "\n>> " << getTypeName(type).c_str() << " FILES" << std::endl; for (auto f : fileList) { @@ -74,11 +75,13 @@ bool Asset::check() // Resultado if (success) { - printf("\n** All files OK.\n\n"); + std::cout << "\n** All files OK.\n" + << std::endl; } else { - printf("\n** A file is missing. Exiting.\n\n"); + std::cout << "\n** A file is missing. Exiting.\n" + << std::endl; } return success; diff --git a/source/common/menu.cpp b/source/common/menu.cpp index a4886b3..d0b96b3 100644 --- a/source/common/menu.cpp +++ b/source/common/menu.cpp @@ -107,7 +107,7 @@ bool Menu::load(std::string file_path) if (file.good()) { // Procesa el fichero linea a linea - printf("Reading file %s\n", filename.c_str()); + std::cout << "Reading file " << filename.c_str() << std::endl; while (std::getline(file, line)) { if (line == "[item]") @@ -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()))) { - printf("Warning: file %s\n, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str()); + std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::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()))) { - printf("Warning: file %s, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str()); + std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl; success = false; } @@ -161,13 +161,13 @@ bool Menu::load(std::string file_path) } // Cierra el fichero - printf("Closing file %s\n", filename.c_str()); + std::cout << "Closing file " << filename.c_str() << std::endl; file.close(); } // El fichero no se puede abrir else { - printf("Warning: Unable to open %s file\n", filename.c_str()); + std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl; success = false; } @@ -208,7 +208,7 @@ bool Menu::setItem(item_t *item, std::string var, std::string value) else if ((var == "") || (var == "[/item]")) { } - + else { success = false; @@ -405,7 +405,7 @@ void Menu::updateSelector() selector.moving = false; } } - + else if (selector.despY < 0) // Va hacia arriba { if (selector.y < selector.targetY) // Ha llegado al destino @@ -434,7 +434,7 @@ void Menu::updateSelector() selector.resizing = false; } } - + else if (selector.incH < 0) // Decrece { if (selector.h < selector.targetH) // Ha llegado al destino @@ -642,7 +642,7 @@ void Menu::render() { text->writeColored(item.at(i).rect.x, item.at(i).rect.y, item.at(i).label, colorGreyed); } - + else { // No seleccionable if ((item.at(i).linkedUp) && (i == selector.index + 1)) diff --git a/source/common/text.cpp b/source/common/text.cpp index 3e5d371..bd7dc69 100644 --- a/source/common/text.cpp +++ b/source/common/text.cpp @@ -50,14 +50,14 @@ textFile_t LoadTextFile(std::string file) }; // Cierra el fichero - printf("Text loaded: %s\n", filename.c_str()); + std::cout << "Text loaded: " << filename.c_str() << std::endl; rfile.close(); } // El fichero no se puede abrir else { - printf("Warning: Unable to open %s file\n", filename.c_str()); + std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl; } // Establece las coordenadas para cada caracter ascii de la cadena y su ancho @@ -243,14 +243,14 @@ void Text::initOffsetFromFile(std::string file) }; // Cierra el fichero - printf("Text loaded: %s\n", filename.c_str()); + std::cout << "Text loaded: " << filename.c_str() << std::endl; rfile.close(); } // El fichero no se puede abrir else { - printf("Warning: Unable to open %s file\n", filename.c_str()); + std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl; } // Establece las coordenadas para cada caracter ascii de la cadena y su ancho diff --git a/source/common/texture.cpp b/source/common/texture.cpp index 980d853..dd0597d 100644 --- a/source/common/texture.cpp +++ b/source/common/texture.cpp @@ -2,6 +2,7 @@ #include "texture.h" #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" +#include // Constructor Texture::Texture(SDL_Renderer *renderer, std::string path) @@ -32,7 +33,7 @@ Texture::~Texture() // Carga una imagen desde un fichero bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer) { - const std::string filename = path.substr(path.find_last_of("\\/") + 1); + const std::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); @@ -43,7 +44,7 @@ bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer) } else { - printf("Image loaded: %s\n", filename.c_str()); + std::cout << "Image loaded: " << filename.c_str() << std::endl; } int depth, pitch; @@ -71,7 +72,7 @@ bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer) SDL_Surface *loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom((void *)data, width, height, depth, pitch, pixel_format); if (loadedSurface == nullptr) { - printf("Unable to load image %s!\n", path.c_str()); + std::cout << "Unable to load image " << path.c_str() << std::endl; } else { @@ -79,7 +80,7 @@ bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer) newTexture = SDL_CreateTextureFromSurface(renderer, loadedSurface); if (newTexture == nullptr) { - printf("Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError()); + std::cout << "Unable to create texture from " << path.c_str() << "! SDL Error: " << SDL_GetError() << std::endl; } else { @@ -104,7 +105,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) { - printf("Unable to create blank texture! SDL Error: %s\n", SDL_GetError()); + std::cout << "Unable to create blank texture! SDL Error: " << SDL_GetError() << std::endl; } else { diff --git a/source/director.cpp b/source/director.cpp index c3ea41c..fdbb505 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -990,8 +990,7 @@ void Director::setSection(section_t section) // Ejecuta la seccion de juego con el logo void Director::runLogo() { - std::cout << std::endl - << "* SECTION: LOGO" << std::endl; + std::cout << "\n* SECTION: LOGO" << std::endl; loadResources(section); logo = new Logo(renderer, screen, resource, asset, options, section.subsection); setSection(logo->run()); @@ -1002,8 +1001,7 @@ void Director::runLogo() // Ejecuta la seccion de juego de la introducción void Director::runIntro() { - std::cout << std::endl - << "* SECTION: INTRO" << std::endl; + std::cout << "\n* SECTION: INTRO" << std::endl; loadResources(section); intro = new Intro(renderer, screen, resource, asset, options); setSection(intro->run()); @@ -1014,8 +1012,7 @@ void Director::runIntro() // Ejecuta la seccion de juego con el titulo y los menus void Director::runTitle() { - std::cout << std::endl - << "* SECTION: TITLE" << std::endl; + std::cout << "\n* SECTION: TITLE" << std::endl; if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) { JA_PlayMusic(music); @@ -1030,8 +1027,7 @@ void Director::runTitle() // Ejecuta la seccion de los creditos del juego void Director::runCredits() { - std::cout << std::endl - << "* SECTION: CREDITS" << std::endl; + std::cout << "\n* SECTION: CREDITS" << std::endl; loadResources(section); credits = new Credits(renderer, screen, resource, asset, options); setSection(credits->run()); @@ -1042,8 +1038,7 @@ void Director::runCredits() // Ejecuta la seccion de la demo, donde se ven pantallas del juego void Director::runDemo() { - std::cout << std::endl - << "* SECTION: DEMO" << std::endl; + std::cout << "\n* SECTION: DEMO" << std::endl; loadResources(section); demo = new Demo(renderer, screen, resource, asset, options, debug); setSection(demo->run()); @@ -1054,8 +1049,7 @@ void Director::runDemo() // Ejecuta la seccion de juego donde se juega void Director::runGame() { - std::cout << std::endl - << "* SECTION: GAME" << std::endl; + std::cout << "\n* SECTION: GAME" << std::endl; JA_StopMusic(); loadResources(section); game = new Game(renderer, screen, resource, asset, options, input, debug); diff --git a/source/room.cpp b/source/room.cpp index 77b050f..17b5793 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -15,8 +15,6 @@ std::vector loadRoomTileFile(std::string file_path) if (file.good()) { // Procesa el fichero linea a linea - // printf("Reading file %s\n", filename.c_str()); - while (std::getline(file, line)) { // Lee el fichero linea a linea if (line.find("data encoding") != std::string::npos) @@ -39,13 +37,13 @@ std::vector loadRoomTileFile(std::string file_path) } // Cierra el fichero - printf("TileMap loaded: %s\n", filename.c_str()); + std::cout << "TileMap loaded: " << filename.c_str() << std::endl; file.close(); } else { // El fichero no se puede abrir - printf("Warning: Unable to open %s file\n", filename.c_str()); + std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl; } return tileMapFile; @@ -86,7 +84,7 @@ room_t loadRoomFile(std::string file_path) // Procesa las dos subcadenas if (!setEnemy(&enemy, line.substr(0, pos), line.substr(pos + 1, line.length()))) { - printf("Warning: file %s\n, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str()); + std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl; } } while (line != "[/enemy]"); @@ -112,7 +110,7 @@ room_t loadRoomFile(std::string file_path) // Procesa las dos subcadenas if (!setItem(&item, line.substr(0, pos), line.substr(pos + 1, line.length()))) { - printf("Warning: file %s\n, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str()); + std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl; } } while (line != "[/item]"); @@ -129,19 +127,19 @@ room_t loadRoomFile(std::string file_path) // Procesa las dos subcadenas if (!setVars(&room, line.substr(0, pos), line.substr(pos + 1, line.length()))) { - printf("Warning: file %s, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str()); + std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl; } } } // Cierra el fichero - printf("Room loaded: %s\n", filename.c_str()); + std::cout << "Room loaded: " << filename.c_str() << std::endl; file.close(); } // El fichero no se puede abrir else { - printf("Warning: Unable to open %s file\n", filename.c_str()); + std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl; } return room; @@ -435,7 +433,7 @@ Room::Room(room_t *room, SDL_Renderer *renderer, Screen *screen, Asset *asset, o mapTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); if (mapTexture == nullptr) { - printf("Error: mapTexture could not be created!\nSDL Error: %s\n", SDL_GetError()); + std::cout << "Error: mapTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl; } SDL_SetTextureBlendMode(mapTexture, SDL_BLENDMODE_BLEND);