From 8232055d221484948e81cc4c6714f00c27d9e466 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 2 Nov 2022 08:36:00 +0100 Subject: [PATCH] =?UTF-8?q?A=C3=B1adidos=20parametros=20al=20programa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/common/asset.cpp | 60 +++++++++++------ source/common/asset.h | 10 ++- source/common/input.cpp | 36 ++++++++-- source/common/input.h | 10 ++- source/common/resource.cpp | 41 ++++++++--- source/common/utils.h | 2 + source/credits.cpp | 10 ++- source/director.cpp | 135 +++++++++++++++++++++++++++++++------ source/director.h | 36 +++++----- source/game.cpp | 16 ++++- source/logo.cpp | 2 +- source/main.cpp | 6 +- source/room.cpp | 21 ++++-- 13 files changed, 292 insertions(+), 93 deletions(-) diff --git a/source/common/asset.cpp b/source/common/asset.cpp index dbd63fa..711f043 100644 --- a/source/common/asset.cpp +++ b/source/common/asset.cpp @@ -6,6 +6,7 @@ Asset::Asset(std::string path) { executablePath = path; longestName = 0; + verbose = true; } // Añade un elemento a la lista @@ -26,8 +27,8 @@ std::string Asset::get(std::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 size_t lastIndex = f.file.find_last_of("/") + 1; + const std::string file = f.file.substr(lastIndex, std::string::npos); if (file == text) { @@ -35,7 +36,10 @@ std::string Asset::get(std::string text) } } - std::cout << "Warning: file " << text.c_str() << " not found" << std::endl; + if (verbose) + { + std::cout << "Warning: file " << text.c_str() << " not found" << std::endl; + } return ""; } @@ -44,7 +48,10 @@ bool Asset::check() { bool success = true; - std::cout << "\n** Checking files." << std::endl; + if (verbose) + { + std::cout << "\n** Checking files." << std::endl; + } // Comprueba la lista de ficheros clasificandolos por tipo for (int type = 0; type < t_maxAssetType; ++type) @@ -63,7 +70,10 @@ bool Asset::check() // Si hay ficheros de ese tipo, comprueba si existen if (any) { - std::cout << "\n>> " << getTypeName(type).c_str() << " FILES" << std::endl; + if (verbose) + { + std::cout << "\n>> " << getTypeName(type).c_str() << " FILES" << std::endl; + } for (auto f : fileList) { @@ -76,15 +86,18 @@ bool Asset::check() } // Resultado - if (success) + if (verbose) { - std::cout << "\n** All files OK.\n" - << std::endl; - } - else - { - std::cout << "\n** A file is missing. Exiting.\n" - << std::endl; + if (success) + { + std::cout << "\n** All files OK.\n" + << std::endl; + } + else + { + std::cout << "\n** A file is missing. Exiting.\n" + << std::endl; + } } return success; @@ -107,12 +120,15 @@ bool Asset::checkFile(std::string path) SDL_RWclose(file); } - 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; + 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; + } return success; } @@ -162,4 +178,10 @@ std::string Asset::getTypeName(int type) return "ERROR"; break; } +} + +// Establece si ha de mostrar texto por pantalla +void Asset::setVerbose(bool value) +{ + verbose = value; } \ No newline at end of file diff --git a/source/common/asset.h b/source/common/asset.h index e9750e3..4f3762f 100644 --- a/source/common/asset.h +++ b/source/common/asset.h @@ -34,9 +34,10 @@ private: }; // Variables - int longestName; // Contiene la longitud del nombre de fichero mas largo - std::vector fileList; - std::string executablePath; + 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 + bool verbose; // Indica si ha de mostrar información por pantalla // Comprueba que existe un fichero bool checkFile(std::string path); @@ -56,6 +57,9 @@ public: // Comprueba que existen todos los elementos bool check(); + + // Establece si ha de mostrar texto por pantalla + void setVerbose(bool value); }; #endif diff --git a/source/common/input.cpp b/source/common/input.cpp index dd5a683..f6cdbbf 100644 --- a/source/common/input.cpp +++ b/source/common/input.cpp @@ -18,17 +18,19 @@ Input::Input(std::string file) gcb.active = false; gameControllerBindings.resize(17, gcb); + verbose = true; + // Comprueba si hay un mando conectado discoverGameController(); } -// Asigna uno de los posibles inputs a una tecla del teclado +// Asigna inputs a teclas void Input::bindKey(Uint8 input, SDL_Scancode code) { keyBindings.at(input).scancode = code; } -// Asigna uno de los posibles inputs a un botón del mando +// Asigna inputs a botones del mando void Input::bindGameControllerButton(Uint8 input, SDL_GameControllerButton button) { gameControllerBindings.at(input).button = button; @@ -41,7 +43,9 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index) bool successGameController = false; if (device == INPUT_USE_ANY) + { index = 0; + } if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY) { @@ -183,7 +187,10 @@ bool Input::discoverGameController() if (SDL_GameControllerAddMappingsFromFile(dbPath.c_str()) < 0) { - std::cout << "Error, could not load " << dbPath.c_str() << " file: " << SDL_GetError() << std::endl; + if (verbose) + { + std::cout << "Error, could not load " << dbPath.c_str() << " file: " << SDL_GetError() << std::endl; + } } const int nJoysticks = SDL_NumJoysticks(); @@ -198,8 +205,11 @@ bool Input::discoverGameController() } } - std::cout << "\nChecking for game controllers...\n"; - std::cout << nJoysticks << " joysticks found, " << numGamepads << " are gamepads\n"; + if (verbose) + { + std::cout << "\nChecking for game controllers...\n"; + std::cout << nJoysticks << " joysticks found, " << numGamepads << " are gamepads\n"; + } if (numGamepads > 0) { @@ -216,12 +226,18 @@ bool Input::discoverGameController() std::string name = SDL_GameControllerNameForIndex(i); name.resize(25); name = name + separator + std::to_string(i); - std::cout << name << std::endl; + if (verbose) + { + std::cout << name << std::endl; + } controllerNames.push_back(name); } else { - std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl; + if (verbose) + { + std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl; + } } } @@ -261,4 +277,10 @@ std::string Input::getControllerName(int index) int Input::getNumControllers() { return numGamepads; +} + +// Establece si ha de mostrar mensajes +void Input::setVerbose(bool value) +{ + verbose = value; } \ No newline at end of file diff --git a/source/common/input.h b/source/common/input.h index a4a85d6..9ff3c55 100644 --- a/source/common/input.h +++ b/source/common/input.h @@ -49,7 +49,7 @@ private: }; // Objetos y punteros - std::vector connectedControllers; // Vector con todos los mandos conectados + std::vector connectedControllers; // Vector con todos los mandos conectados // Variables std::vector keyBindings; // Vector con las teclas asociadas a los inputs predefinidos @@ -57,6 +57,7 @@ private: std::vector controllerNames; // Vector con los nombres de los mandos int numGamepads; // Numero de mandos conectados std::string dbPath; // Ruta al archivo gamecontrollerdb.txt + bool verbose; // Indica si ha de mostrar mensajes // Comprueba si hay un mando conectado bool discoverGameController(); @@ -65,10 +66,10 @@ public: // Constructor Input(std::string file); - // Asigna uno de los posibles inputs a una tecla del teclado + // Asigna inputs a teclas void bindKey(Uint8 input, SDL_Scancode code); - // Asigna uno de los posibles inputs a un botón del mando + // Asigna inputs a botones del mando void bindGameControllerButton(Uint8 input, SDL_GameControllerButton button); // Comprueba si un input esta activo @@ -85,6 +86,9 @@ public: // Obten el nombre de un mando de juego std::string getControllerName(int index); + + // Establece si ha de mostrar mensajes + void setVerbose(bool value); }; #endif diff --git a/source/common/resource.cpp b/source/common/resource.cpp index 204b807..7d8e7ec 100644 --- a/source/common/resource.cpp +++ b/source/common/resource.cpp @@ -14,8 +14,11 @@ void Resource::loadTextures(std::vector list) { for (auto l : list) { - std::cout << "\nLOAD TEXTURE: " << l << std::endl; - std::cout << "png: " << asset->get(l) << std::endl; + if (options->console) + { + std::cout << "\nLOAD TEXTURE: " << l << std::endl; + std::cout << "png: " << asset->get(l) << std::endl; + } res_texture_t t; t.name = l; @@ -33,9 +36,12 @@ void Resource::loadAnimations(std::vector list) const size_t lastIndex = l.find_last_of("."); const std::string pngFile = l.substr(0, lastIndex) + ".png"; - std::cout << "\nLOAD ANIMATION: " << l << std::endl; - std::cout << "png: " << asset->get(pngFile) << std::endl; - std::cout << "ani: " << asset->get(l) << std::endl; + if (options->console) + { + std::cout << "\nLOAD ANIMATION: " << l << std::endl; + std::cout << "png: " << asset->get(pngFile) << std::endl; + std::cout << "ani: " << asset->get(l) << std::endl; + } res_animation_t as; as.name = l; @@ -196,7 +202,10 @@ Texture *Resource::getTexture(std::string name) } } - std::cout << "NOT FOUND ON CACHE: " << name << std::endl; + if (options->console) + { + std::cout << "NOT FOUND ON CACHE: " << name << std::endl; + } return nullptr; } @@ -214,7 +223,10 @@ animatedSprite_t *Resource::getAnimation(std::string name) } } - std::cout << "NOT FOUND ON CACHE: " << name << std::endl; + if (options->console) + { + std::cout << "NOT FOUND ON CACHE: " << name << std::endl; + } return nullptr; } @@ -230,7 +242,10 @@ textFile_t *Resource::getOffset(std::string name) } } - std::cout << "NOT FOUND ON CACHE: " << name << std::endl; + if (options->console) + { + std::cout << "NOT FOUND ON CACHE: " << name << std::endl; + } return nullptr; } @@ -246,7 +261,10 @@ std::vector *Resource::getTileMap(std::string name) } } - std::cout << "NOT FOUND ON CACHE: " << name << std::endl; + if (options->console) + { + std::cout << "NOT FOUND ON CACHE: " << name << std::endl; + } return nullptr; } @@ -262,6 +280,9 @@ room_t *Resource::getRoom(std::string name) } } - std::cout << "NOT FOUND ON CACHE: " << name << std::endl; + if (options->console) + { + std::cout << "NOT FOUND ON CACHE: " << name << std::endl; + } return nullptr; } \ No newline at end of file diff --git a/source/common/utils.h b/source/common/utils.h index 1cd10f5..4ac8d5f 100644 --- a/source/common/utils.h +++ b/source/common/utils.h @@ -75,6 +75,8 @@ struct options_t bool borderEnabled; // Indica si ha de mostrar el borde en el modo de ventana float borderSize; // Porcentaje de borde que se añade a lo ventana palette_e palette; // Paleta de colores a usar en el juego + bool console; // Indica si ha de mostrar información por la consola de texto + bool infiniteLives; // Indica si el jugador dispone de vidas infinitas }; // Calcula el cuadrado de la distancia entre dos puntos diff --git a/source/credits.cpp b/source/credits.cpp index c0dee3d..694915e 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -33,7 +33,10 @@ Credits::Credits(SDL_Renderer *renderer, Screen *screen, Resource *resource, Ass textTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); if (textTexture == nullptr) { - std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl; + if (options->console) + { + std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl; + } } SDL_SetTextureBlendMode(textTexture, SDL_BLENDMODE_BLEND); @@ -41,7 +44,10 @@ Credits::Credits(SDL_Renderer *renderer, Screen *screen, Resource *resource, Ass coverTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); if (coverTexture == nullptr) { - std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl; + if (options->console) + { + std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl; + } } SDL_SetTextureBlendMode(coverTexture, SDL_BLENDMODE_BLEND); diff --git a/source/director.cpp b/source/director.cpp index 7d106e5..ecea013 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -4,7 +4,7 @@ #include // Constructor -Director::Director(std::string path) +Director::Director(int argc, char *argv[]) { section.name = SECTION_PROG_LOGO; section.subsection = SUBSECTION_LOGO_TO_INTRO; @@ -12,7 +12,8 @@ Director::Director(std::string path) section.name = SECTION_PROG_GAME; // Crea el objeto que controla los ficheros de recursos - asset = new Asset(path.substr(0, path.find_last_of("\\/"))); + executablePath = argv[0]; + asset = new Asset(executablePath.substr(0, executablePath.find_last_of("\\/"))); // Si falta algún fichero no inicia el programa if (!setFileList()) @@ -20,6 +21,13 @@ Director::Director(std::string path) section.name = SECTION_PROG_QUIT; } + // Crea e inicializa las opciones del programa + iniOptions(); + + // Comprueba los parametros del programa + checkProgramArguments(argc, argv); + asset->setVerbose(options->console); + // Inicializa variables desde el fichero de configuración loadConfig(); @@ -59,11 +67,13 @@ Director::~Director() SDL_Quit(); } -// Carga el fichero de configuración -bool Director::loadConfig() +// Crea e inicializa las opciones del programa +void Director::iniOptions() { - // Crea el puntero a la estructura de opciones e inicializa valores + // Crea el puntero a la estructura de opciones options = new options_t; + + // Inicializa valores options->fullScreenMode = 0; options->windowSize = 3; options->filter = FILTER_NEAREST; @@ -74,6 +84,31 @@ bool Director::loadConfig() options->borderSize = 0.1f; options->palette = p_zxspectrum; + // Estos valores no se guardan en el fichero de configuraci´ón + options->console = false; + options->infiniteLives = false; +} + +// Comprueba los parametros del programa +void Director::checkProgramArguments(int argc, char *argv[]) +{ + for (int i = 0; i < argc; ++i) + { + if (strcmp(argv[i], "--console") == 0) + { + options->console = true; + } + + else if (strcmp(argv[i], "--infiniteLives") == 0) + { + options->infiniteLives = true; + } + } +} + +// Carga el fichero de configuración +bool Director::loadConfig() +{ // Indicador de éxito en la carga bool success = true; @@ -85,7 +120,10 @@ bool Director::loadConfig() if (file.good()) { // Procesa el fichero linea a linea - std::cout << "Reading file config.txt\n"; + if (options->console) + { + std::cout << "Reading file config.txt\n"; + } while (std::getline(file, line)) { // Comprueba que la linea no sea un comentario @@ -96,15 +134,21 @@ bool Director::loadConfig() // Procesa las dos subcadenas if (!setOptions(options, line.substr(0, pos), line.substr(pos + 1, line.length()))) { - std::cout << "Warning: file config.txt\n"; - std::cout << "unknown parameter " << line.substr(0, pos).c_str() << std::endl; + if (options->console) + { + std::cout << "Warning: file config.txt\n"; + std::cout << "unknown parameter " << line.substr(0, pos).c_str() << std::endl; + } success = false; } } } // Cierra el fichero - std::cout << "Closing file config.txt\n\n"; + if (options->console) + { + std::cout << "Closing file config.txt\n\n"; + } file.close(); } @@ -182,7 +226,10 @@ bool Director::saveConfig() // Carga los recursos void Director::loadResources(section_t section) { - std::cout << "** LOAD RESOURCES" << std::endl; + if (options->console) + { + std::cout << "** LOAD RESOURCES" << std::endl; + } if (section.name == SECTION_PROG_LOGO) { @@ -503,7 +550,10 @@ void Director::loadResources(section_t section) resource->loadRooms(roomList); } - std::cout << "** RESOURCES LOADED" << std::endl; + if (options->console) + { + std::cout << "** RESOURCES LOADED" << std::endl; + } } // Asigna variables a partir de dos cadenas @@ -608,6 +658,10 @@ bool Director::setOptions(options_t *options, std::string var, std::string value // Inicia las variables necesarias para arrancar el programa void Director::initInput() { + // Establece si ha de mostrar mensajes + input->setVerbose(options->console); + + // Asigna inputs a teclas input->bindKey(INPUT_UP, SDL_SCANCODE_UP); input->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN); input->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT); @@ -645,7 +699,10 @@ bool Director::initSDL() // Inicializa SDL if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO) < 0) { - std::cout << "SDL could not initialize!\nSDL Error: " << SDL_GetError() << std::endl; + if (options->console) + { + std::cout << "SDL could not initialize!\nSDL Error: " << SDL_GetError() << std::endl; + } success = false; } else @@ -656,27 +713,40 @@ bool Director::initSDL() // Establece el filtro de la textura a nearest if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(options->filter).c_str())) { - std::cout << "Warning: Nearest texture filtering not enabled!\n"; + if (options->console) + { + std::cout << "Warning: Nearest texture filtering not enabled!\n"; + } } // Crea la ventana window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, options->screenWidth, options->screenHeight, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI); if (window == nullptr) { - std::cout << "Window could not be created!\nSDL Error: " << SDL_GetError() << std::endl; + if (options->console) + { + std::cout << "Window could not be created!\nSDL Error: " << SDL_GetError() << std::endl; + } success = false; } else { // Crea un renderizador para la ventana. El vsync se activa en funcion de las opciones if (options->vSync) + { renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); + } else + { renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); + } if (renderer == nullptr) { - std::cout << "Renderer could not be created!\nSDL Error: " << SDL_GetError() << std::endl; + if (options->console) + { + std::cout << "Renderer could not be created!\nSDL Error: " << SDL_GetError() << std::endl; + } success = false; } else @@ -693,7 +763,10 @@ bool Director::initSDL() } } - std::cout << std::endl; + if (options->console) + { + std::cout << std::endl; + } return success; } @@ -1010,7 +1083,10 @@ void Director::setSection(section_t section) // Ejecuta la seccion de juego con el logo void Director::runLogo() { - std::cout << "\n* SECTION: LOGO" << std::endl; + if (options->console) + { + std::cout << "\n* SECTION: LOGO" << std::endl; + } loadResources(section); logo = new Logo(renderer, screen, resource, asset, options, section.subsection); setSection(logo->run()); @@ -1021,7 +1097,10 @@ void Director::runLogo() // Ejecuta la seccion de juego de la introducción void Director::runIntro() { - std::cout << "\n* SECTION: INTRO" << std::endl; + if (options->console) + { + std::cout << "\n* SECTION: INTRO" << std::endl; + } loadResources(section); intro = new Intro(renderer, screen, resource, asset, options); setSection(intro->run()); @@ -1032,7 +1111,10 @@ void Director::runIntro() // Ejecuta la seccion de juego con el titulo y los menus void Director::runTitle() { - std::cout << "\n* SECTION: TITLE" << std::endl; + if (options->console) + { + std::cout << "\n* SECTION: TITLE" << std::endl; + } if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) { JA_PlayMusic(music); @@ -1047,7 +1129,10 @@ void Director::runTitle() // Ejecuta la seccion de los creditos del juego void Director::runCredits() { - std::cout << "\n* SECTION: CREDITS" << std::endl; + if (options->console) + { + std::cout << "\n* SECTION: CREDITS" << std::endl; + } loadResources(section); credits = new Credits(renderer, screen, resource, asset, options); setSection(credits->run()); @@ -1058,7 +1143,10 @@ void Director::runCredits() // Ejecuta la seccion de la demo, donde se ven pantallas del juego void Director::runDemo() { - std::cout << "\n* SECTION: DEMO" << std::endl; + if (options->console) + { + std::cout << "\n* SECTION: DEMO" << std::endl; + } loadResources(section); demo = new Demo(renderer, screen, resource, asset, options, debug); setSection(demo->run()); @@ -1069,7 +1157,10 @@ void Director::runDemo() // Ejecuta la seccion de juego donde se juega void Director::runGame() { - std::cout << "\n* SECTION: GAME" << std::endl; + if (options->console) + { + 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/director.h b/source/director.h index f63e108..9f94d1f 100644 --- a/source/director.h +++ b/source/director.h @@ -24,26 +24,32 @@ class Director { private: // Objetos y punteros - SDL_Window *window; // La ventana donde dibujamos - 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 que gestiona todos los ficheros de recursos - Input *input; // Objeto Input para gestionar las entradas - Game *game; // Objeto para gestionar la sección del juego - Logo *logo; // Objeto para gestionar la sección del logo del programa - Title *title; // Objeto para gestionar la pantalla de título - Intro *intro; // Objeto para gestionar la introducción del juego - Credits *credits; // Objeto para gestionar los creditos del juego - Demo *demo; // Objeto para gestionar el modo demo, en el que se ven pantallas del juego - Debug *debug; // Objeto para getsionar la información de debug + SDL_Window *window; // La ventana donde dibujamos + 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 que gestiona todos los ficheros de recursos + Input *input; // Objeto Input para gestionar las entradas + Game *game; // Objeto para gestionar la sección del juego + Logo *logo; // Objeto para gestionar la sección del logo del programa + Title *title; // Objeto para gestionar la pantalla de título + Intro *intro; // Objeto para gestionar la introducción del juego + Credits *credits; // Objeto para gestionar los creditos del juego + Demo *demo; // Objeto para gestionar el modo demo, en el que se ven pantallas del juego + Debug *debug; // Objeto para getsionar la información de debug + struct options_t *options; // Variable con todas las opciones del programa // Variables JA_Music music; // Musica del titulo - struct options_t *options; // Variable con todas las opciones del programa std::string executablePath; // Path del ejecutable section_t section; // Sección y subsección actual del programa; + // Crea e inicializa las opciones del programa + void iniOptions(); + + // Comprueba los parametros del programa + void checkProgramArguments(int argc, char *argv[]); + // Carga el fichero de configuración bool loadConfig(); @@ -97,7 +103,7 @@ private: public: // Constructor - Director(std::string path); + Director(int argc, char *argv[]); // Destructor ~Director(); diff --git a/source/game.cpp b/source/game.cpp index da301b6..11f2be3 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -389,7 +389,11 @@ void Game::killPlayer() return; } - // board.lives--; + // Resta una vida al jugador + if (!options->infiniteLives) + { + board.lives--; + } // Destruye la habitacion y el jugador delete room; @@ -412,7 +416,10 @@ void Game::killPlayer() // Recarga todas las texturas void Game::reLoadTextures() { - std::cout << "** RELOAD REQUESTED" << std::endl; + if (options->console) + { + std::cout << "** RELOAD REQUESTED" << std::endl; + } player->reLoadTexture(); room->reLoadTexture(); scoreboard->reLoadTexture(); @@ -422,7 +429,10 @@ void Game::reLoadTextures() // Cambia la paleta void Game::switchPalette() { - std::cout << "** PALETTE SWITCH REQUESTED" << std::endl; + if (options->console) + { + std::cout << "** PALETTE SWITCH REQUESTED" << std::endl; + } // Modifica la variable options->palette = (options->palette == p_zxspectrum) ? p_zxarne : p_zxspectrum; diff --git a/source/logo.cpp b/source/logo.cpp index ce78c9f..e603153 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -85,7 +85,7 @@ void Logo::checkEventHandler() switch (eventHandler->key.keysym.scancode) { case SDL_SCANCODE_ESCAPE: - std::cout << "PULSADO ESCAPE" << std::endl; + //std::cout << "PULSADO ESCAPE" << std::endl; section.name = SECTION_PROG_QUIT; break; diff --git a/source/main.cpp b/source/main.cpp index b5329b1..0f7fc17 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -8,12 +8,12 @@ Empezado en Castalla el 01/07/2022. #include "director.h" #include -int main(int argc, char *args[]) +int main(int argc, char *argv[]) { std::cout << "Starting the game...\n\n"; // Crea el objeto Director - Director *director = new Director(args[0]); + Director *director = new Director(argc, argv); // Bucle principal director->run(); @@ -22,7 +22,7 @@ int main(int argc, char *args[]) delete director; director = nullptr; - std::cout << "\nShutting down the game...\n"; + std::cout << "\nShutting down the game..." << std::endl; return 0; } diff --git a/source/room.cpp b/source/room.cpp index 24ec4b6..b0a0067 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -110,7 +110,9 @@ room_t loadRoomFile(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; + { + std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl; + } } } while (line != "[/item]"); @@ -127,19 +129,25 @@ room_t loadRoomFile(std::string file_path) // Procesa las dos subcadenas if (!setVars(&room, 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; + { + std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl; + } } } } // Cierra el fichero - std::cout << "Room loaded: " << filename.c_str() << std::endl; + { + std::cout << "Room loaded: " << filename.c_str() << std::endl; + } file.close(); } // El fichero no se puede abrir else { - std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl; + { + std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl; + } } return room; @@ -434,7 +442,10 @@ 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) { - std::cout << "Error: mapTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl; + if (options->console) + { + std::cout << "Error: mapTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl; + } } SDL_SetTextureBlendMode(mapTexture, SDL_BLENDMODE_BLEND);