diff --git a/source/common/resource.cpp b/source/common/resource.cpp index 8e3194f..2ff35d8 100644 --- a/source/common/resource.cpp +++ b/source/common/resource.cpp @@ -21,13 +21,20 @@ void Resource::loadTextures(std::vector list) } } -// Libera los recursos -void Resource::freeTextures() +// Recarga las texturas +void Resource::reLoadTextures() +{ + for (auto texture : textures) + { + texture.texture->reLoad(); + } +} + +// Libera las texturas +void Resource::freeTextures() { - // Libera las texturas for (auto texture : textures) { - texture.texture->unload(); delete texture.texture; } textures.clear(); @@ -36,18 +43,15 @@ void Resource::freeTextures() // Obtiene una textura Texture *Resource::getTexture(std::string name) { - //std::cout << "BUSCANDO TEXTURA" << std::endl; for (auto texture : textures) { - //std::cout << "COMPROBANDO: " << texture.name << " - " << name << std::endl; - if (texture.name.find(name) != std::string::npos) { std::cout << "CACHE: " << name << std::endl; return texture.texture; } } - std::cout << "NO ENCONTRADA: " << name << std::endl; + std::cout << "NO ENCONTRADA: " << name << std::endl; return nullptr; } \ No newline at end of file diff --git a/source/common/resource.h b/source/common/resource.h index c30777b..b965787 100644 --- a/source/common/resource.h +++ b/source/common/resource.h @@ -34,7 +34,10 @@ public: // Carga todos los recursos necesarios void loadTextures(std::vector textureList); - // Libera los recursos + // Recarga las texturas + void reLoadTextures(); + + // Libera las texturas void freeTextures(); // Obtiene una textura diff --git a/source/director.cpp b/source/director.cpp index 2ede6a3..945009f 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -9,7 +9,7 @@ Director::Director(std::string path) section.name = SECTION_PROG_LOGO; section.subsection = SUBSECTION_LOGO_TO_INTRO; - section.name = SECTION_PROG_GAME; + section.name = SECTION_PROG_TITLE; // Crea el objeto que controla los ficheros de recursos asset = new Asset(path.substr(0, path.find_last_of("\\/"))); diff --git a/source/intro.cpp b/source/intro.cpp index c4d911a..f73ee45 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -14,13 +14,13 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset * eventHandler = new SDL_Event(); if (options->palette == p_zxspectrum) { - loadingScreenTexture1 =resource->getTexture("loading_screen_bn.png"); - loadingScreenTexture2 =resource->getTexture("loading_screen_color.png"); + loadingScreenTexture1 = resource->getTexture("loading_screen_bn.png"); + loadingScreenTexture2 = resource->getTexture("loading_screen_color.png"); } else if (options->palette == p_zxarne) { - loadingScreenTexture1 =resource->getTexture("loading_screen_bn_zxarne.png"); - loadingScreenTexture2 =resource->getTexture("loading_screen_color_zxarne.png"); + loadingScreenTexture1 = resource->getTexture("loading_screen_bn_zxarne.png"); + loadingScreenTexture2 = resource->getTexture("loading_screen_color_zxarne.png"); } sprite1 = new Sprite(0, 0, loadingScreenTexture1->getWidth(), loadingScreenTexture1->getHeight(), loadingScreenTexture1, renderer); sprite2 = new Sprite(0, 0, loadingScreenTexture2->getWidth(), loadingScreenTexture2->getHeight(), loadingScreenTexture2, renderer); @@ -97,8 +97,46 @@ void Intro::checkEventHandler() // Cualquier tecla pulsada if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN)) { - section.name = SECTION_PROG_TITLE; - section.subsection = 0; + switch (eventHandler->key.keysym.scancode) + { + case SDL_SCANCODE_B: + screen->switchBorder(); + resource->reLoadTextures(); + break; + + case SDL_SCANCODE_F: + screen->switchVideoMode(); + resource->reLoadTextures(); + break; + + case SDL_SCANCODE_F1: + screen->setWindowSize(1); + resource->reLoadTextures(); + break; + + case SDL_SCANCODE_F2: + screen->setWindowSize(2); + resource->reLoadTextures(); + break; + + case SDL_SCANCODE_F3: + screen->setWindowSize(3); + resource->reLoadTextures(); + break; + + case SDL_SCANCODE_F4: + screen->setWindowSize(4); + resource->reLoadTextures(); + break; + + case SDL_SCANCODE_F5: + switchPalette(); + break; + + default: + section.name = SECTION_PROG_TITLE; + break; + } } } } @@ -248,3 +286,20 @@ section_t Intro::run() return section; } + +// Cambia la paleta +void Intro::switchPalette() +{ + if (options->palette == p_zxspectrum) + { + options->palette = p_zxarne; + loadingScreenTexture1 = resource->getTexture("loading_screen_bn_zxarne.png"); + loadingScreenTexture2 = resource->getTexture("loading_screen_color_zxarne.png"); + } + else + { + options->palette = p_zxspectrum; + loadingScreenTexture1 = resource->getTexture("loading_screen_bn.png"); + loadingScreenTexture2 = resource->getTexture("loading_screen_color.png"); + } +} \ No newline at end of file diff --git a/source/intro.h b/source/intro.h index 3066c04..afe83b5 100644 --- a/source/intro.h +++ b/source/intro.h @@ -64,6 +64,9 @@ private: // Dibuja la pantalla de carga void renderLoad(); + // Cambia la paleta + void switchPalette(); + public: // Constructor Intro(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options); diff --git a/source/room.cpp b/source/room.cpp index 877613e..58144c4 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -783,8 +783,9 @@ void Room::reLoadTexture() { texture->loadFromFile(asset->get("standard_zxarne.png"), renderer); } - // texture->reLoad(); + fillMapTexture(); + for (auto enemy : enemies) { enemy->reLoadTexture(); diff --git a/source/title.cpp b/source/title.cpp index 51e5a0c..fcaac2e 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -14,11 +14,11 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset * eventHandler = new SDL_Event(); if (options->palette == p_zxspectrum) { - texture =resource->getTexture("loading_screen_color.png"); + texture = resource->getTexture("loading_screen_color.png"); } else if (options->palette == p_zxarne) { - texture =resource->getTexture("loading_screen_color_zxarne.png"); + texture = resource->getTexture("loading_screen_color_zxarne.png"); } sprite = new Sprite(0, 0, texture->getWidth(), texture->getHeight(), texture, renderer); text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer); @@ -107,7 +107,7 @@ void Title::checkEventHandler() case SDL_SCANCODE_F5: switchPalette(); - reLoadTextures(); + // reLoadTextures(); break; default: @@ -247,12 +247,19 @@ void Title::switchPalette() if (options->palette == p_zxspectrum) { options->palette = p_zxarne; + texture = resource->getTexture("loading_screen_color_zxarne.png"); + sprite->setTexture(texture); } else { options->palette = p_zxspectrum; + texture = resource->getTexture("loading_screen_color.png"); + sprite->setTexture(texture); } + // resource->reLoadTextures(); + // reLoadTextures(); + // Cambia el color del borde screen->setBorderColor(stringToColor(options->palette, "bright_blue")); } \ No newline at end of file