diff --git a/data/gfx/logo/logo_retroweekend.png b/data/gfx/logo/logo_retroweekend.png new file mode 100644 index 0000000..5e10ebf Binary files /dev/null and b/data/gfx/logo/logo_retroweekend.png differ diff --git a/source/asset.h b/source/asset.h index 0dad8a2..229d5d1 100644 --- a/source/asset.h +++ b/source/asset.h @@ -56,13 +56,13 @@ private: ~Asset() = default; public: - // [SINGLETON] Crearemos el objeto screen con esta función estática + // [SINGLETON] Crearemos el objeto con esta función estática static void init(const std::string &executable_path); - // [SINGLETON] Destruiremos el objeto screen con esta función estática + // [SINGLETON] Destruiremos el objeto con esta función estática static void destroy(); - // [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él + // [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él static Asset *get(); // Añade un elemento a la lista diff --git a/source/director.cpp b/source/director.cpp index 9814801..1bd0380 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -484,6 +484,7 @@ void Director::setFileList() Asset::get()->add(prefix + "/data/gfx/logo/logo_jailgames.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/logo/logo_jailgames_mini.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/logo/logo_since_1998.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/logo/logo_retroweekend.png", AssetType::BITMAP); } { // Items diff --git a/source/logo.cpp b/source/logo.cpp index 0491d33..aa85d9e 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -3,16 +3,17 @@ #include // Para SDL_GetTicks #include // Para SDL_WINDOWEVENT_SIZE_CHANGED #include // Para move -#include "global_inputs.h" // Para check -#include "input.h" // Para Input -#include "jail_audio.h" // Para JA_StopMusic -#include "param.h" // Para Param, ParamGame, param -#include "resource.h" // Para Resource -#include "screen.h" // Para Screen -#include "section.h" // Para Name, name, Options, options -#include "sprite.h" // Para Sprite -#include "texture.h" // Para Texture -#include "utils.h" // Para Color, Zone +#include +#include "global_inputs.h" // Para check +#include "input.h" // Para Input +#include "jail_audio.h" // Para JA_StopMusic +#include "param.h" // Para Param, ParamGame, param +#include "resource.h" // Para Resource +#include "screen.h" // Para Screen +#include "section.h" // Para Name, name, Options, options +#include "sprite.h" // Para Sprite +#include "texture.h" // Para Texture +#include "utils.h" // Para Color, Zone #include "mouse.h" // Constructor @@ -52,6 +53,9 @@ Logo::Logo() color_.push_back(Color(0x00, 0xd8, 0xd8)); // Cyan color_.push_back(Color(0xd8, 0xd8, 0x00)); // Yellow color_.push_back(Color(0xFF, 0xFF, 0xFF)); // Bright white + + mi_textura = copyTextureToTarget(Screen::get()->getRenderer(), Resource::get()->getTexture("logo_retroweekend.png")->getSDLTexture()); + pixels_ = extractPixels(mi_textura); } // Destructor @@ -60,6 +64,7 @@ Logo::~Logo() jail_texture_->setColor(255, 255, 255); since_texture_->setColor(255, 255, 255); JA_StopChannel(-1); + SDL_DestroyTexture(mi_textura); } // Recarga todas las texturas @@ -146,11 +151,22 @@ void Logo::updateJAILGAMES() } } } + + // Comprueba si ha terminado el logo + if (counter_ == END_LOGO_COUNTER_MARK + POST_LOGO_DURATION) + { + state_ = LogoState::RETROWEEKEND; + ticks_start_ = SDL_GetTicks(); + } } // Gestiona el logo de RETROWEEKEND void Logo::updateRETROWEEKEND() { + if (SDL_GetTicks() >= ticks_start_ + 5000) + { + section::name = section::Name::INTRO; + } } // Gestiona el color de las texturas @@ -209,15 +225,9 @@ void Logo::update() break; } - // Gestiona el contador y sus eventos + // Gestiona el contador counter_++; - // Comprueba si ha terminado el logo - if (counter_ == END_LOGO_COUNTER_MARK + POST_LOGO_DURATION) - { - section::name = section::Name::INTRO; - } - // Actualiza las variables de globalInputs globalInputs::update(); } @@ -279,4 +289,113 @@ void Logo::renderJAILGAMES() // Renderiza el logo de RETROWEEKEND void Logo::renderRETROWEEKEND() { -} \ No newline at end of file + // SDL_RenderCopy(Screen::get()->getRenderer(), mi_textura, nullptr, nullptr); + + // SDL_RenderCopy(Screen::get()->getRenderer(), Resource::get()->getTexture("logo_retroweekend.png")->getSDLTexture(), nullptr, nullptr); + // Dibujar y evaporar los píxeles + renderAndEvaporate(Screen::get()->getRenderer(), pixels_); +} + +std::vector Logo::extractPixels(SDL_Texture *texture) +{ + std::vector pixels; + + // Obtener el formato y tamaño de la textura + Uint32 format; + int access, width, height; + SDL_QueryTexture(texture, &format, &access, &width, &height); + + // Imprimir el nombre del formato de la textura + std::cout << "Texture format: " << SDL_GetPixelFormatName(format) << std::endl; + + // Crear una superficie temporal para leer los píxeles + SDL_Surface *temp_surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 32, format); + if (!temp_surface) + { + std::cout << "Error: SDL_CreateRGBSurfaceWithFormat failed - " << SDL_GetError() << std::endl; + return pixels; + } + + SDL_Renderer *renderer = Screen::get()->getRenderer(); + SDL_SetRenderTarget(renderer, nullptr); // Dibujar en pantalla principal + SDL_RenderClear(renderer); // Limpiar pantalla + SDL_RenderCopy(renderer, texture, nullptr, nullptr); + SDL_RenderPresent(renderer); // Mostrar en pantalla + + std::cout << "Se ha dibujado la textura en pantalla." << std::endl; + + if (SDL_RenderReadPixels(Screen::get()->getRenderer(), nullptr, format, temp_surface->pixels, temp_surface->pitch) != 0) + { + std::cout << "Error: SDL_RenderReadPixels failed - " << SDL_GetError() << std::endl; + SDL_FreeSurface(temp_surface); + return pixels; + } + else + { + std::cout << "SDL_RenderReadPixels se ejecutó correctamente." << std::endl; + } + + // Leer los píxeles de la textura + if (SDL_RenderReadPixels(Screen::get()->getRenderer(), nullptr, format, temp_surface->pixels, temp_surface->pitch) != 0) + { + std::cout << "Error: SDL_RenderReadPixels failed - " << SDL_GetError() << std::endl; + SDL_FreeSurface(temp_surface); + return pixels; + } + + // Extraer los píxeles y almacenarlos en el vector + SDL_PixelFormat *pixel_format = SDL_AllocFormat(format); + Uint8 r, g, b, a; + /*for (int y = 0; y < height; ++y) + { + for (int x = 0; x < width; ++x) + { + Uint32 pixel_value = ((Uint32 *)temp_surface->pixels)[y * (temp_surface->pitch / 4) + x]; + SDL_GetRGBA(pixel_value, pixel_format, &r, &g, &b, &a); + if (a > 0) + { + pixels.push_back({x, y, r, g, b, a}); + } + } + }*/ + + for (int y = 0; y < height; ++y) + { + for (int x = 0; x < width; ++x) + { + Uint32 pixel_value = ((Uint32 *)temp_surface->pixels)[y * (temp_surface->pitch / 4) + x]; + SDL_GetRGBA(pixel_value, pixel_format, &r, &g, &b, &a); + + // Imprimir algunos píxeles para depuración + if (x < 5 && y < 5) + { + std::cout << "Pixel (" << x << "," << y << ") - RGBA(" + << (int)r << "," << (int)g << "," << (int)b << "," << (int)a << ")" << std::endl; + } + + // No filtrar por alfa por ahora + pixels.push_back({x, y, r, g, b, a}); + } + } + + std::cout << "Cantidad de píxeles a renderizar: " << pixels.size() << std::endl; + + // Liberar recursos + SDL_FreeFormat(pixel_format); + SDL_FreeSurface(temp_surface); + + return pixels; +} + +void Logo::renderAndEvaporate(SDL_Renderer *renderer, std::vector &pixels) +{ + for (auto &pixel : pixels) + { + // Establecer el color para el píxel actual + SDL_SetRenderDrawColor(renderer, pixel.r, pixel.g, pixel.b, pixel.a); + // Dibujar el píxel + SDL_RenderDrawPoint(renderer, pixel.x, pixel.y); + // Evaporar el píxel + // pixel.evaporate(); + } +} diff --git a/source/logo.h b/source/logo.h index 84ccd82..6c0678d 100644 --- a/source/logo.h +++ b/source/logo.h @@ -2,8 +2,9 @@ #include // Para SDL_Point #include // Para Uint32 -#include // Para shared_ptr, unique_ptr -#include // Para vector +#include +#include // Para shared_ptr, unique_ptr +#include // Para vector class Sprite; class Texture; // lines 9-9 struct Color; @@ -16,6 +17,21 @@ struct Color; ZX Spectrum */ +struct Pixel +{ + int x, y; // Coordenadas del píxel + Uint8 r, g, b, a; // Color del píxel + + // Método para ascender y desvanecerse + void evaporate() + { + y -= 1; // Asciende hacia arriba + a = (a > 5) ? a - 5 : 0; // Desvanece el alfa (transparencia) + // Añadir movimiento zig-zag aleatorio + x += (rand() % 3 - 1); // Movimiento horizontal aleatorio (-1, 0, 1) + } +}; + // Clase Logo class Logo { @@ -45,6 +61,9 @@ private: Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa SDL_Point dest_; // Posición X donde dibujar el logo LogoState state_ = LogoState::JAILGAMES; // El estado indica qué logo se está procesando + Uint32 ticks_start_ = 0; // Almacena el valor actual de los ticks de SDL + std::vector pixels_; // Vector con los pixels que forman el logo de "RETROWEEKEND" + SDL_Texture *mi_textura; // Actualiza las variables void update(); @@ -76,6 +95,10 @@ private: // Recarga todas las texturas void reloadTextures(); + std::vector extractPixels(SDL_Texture *texture); + + void renderAndEvaporate(SDL_Renderer *renderer, std::vector &pixels); + public: // Constructor Logo(); diff --git a/source/utils.cpp b/source/utils.cpp index 6c9360f..f2e0e24 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -32,20 +32,20 @@ const Color green_sky_color = Color(0X00, 0X79, 0X6B); // Obtiene un color del vector de colores imitando al Coche Fantástico Color getColorLikeKnightRider(const std::vector &colors, int counter_) { - int cycle_length = colors.size() * 2 - 2; - size_t n = counter_ % cycle_length; + int cycle_length = colors.size() * 2 - 2; + size_t n = counter_ % cycle_length; - size_t index; - if (n < colors.size()) - { - index = n; // Avanza: 0,1,2,3 - } - else - { - index = 2 * (colors.size() - 1) - n; // Retrocede: 2,1 - } + size_t index; + if (n < colors.size()) + { + index = n; // Avanza: 0,1,2,3 + } + else + { + index = 2 * (colors.size() - 1) - n; // Retrocede: 2,1 + } - return colors[index]; + return colors[index]; } // Calcula el cuadrado de la distancia entre dos puntos @@ -339,4 +339,4 @@ std::string getPath(const std::string &full_path) { std::filesystem::path path(full_path); return path.parent_path().string(); -} +} \ No newline at end of file