canvi de pc

This commit is contained in:
2025-02-21 18:26:32 +01:00
parent 04ff428aa0
commit 29c85fecad
6 changed files with 179 additions and 36 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

View File

@@ -56,13 +56,13 @@ private:
~Asset() = default; ~Asset() = default;
public: 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); 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(); 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(); static Asset *get();
// Añade un elemento a la lista // Añade un elemento a la lista

View File

@@ -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.png", AssetType::BITMAP);
Asset::get()->add(prefix + "/data/gfx/logo/logo_jailgames_mini.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_since_1998.png", AssetType::BITMAP);
Asset::get()->add(prefix + "/data/gfx/logo/logo_retroweekend.png", AssetType::BITMAP);
} }
{ // Items { // Items

View File

@@ -3,16 +3,17 @@
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks #include <SDL2/SDL_timer.h> // Para SDL_GetTicks
#include <SDL2/SDL_video.h> // Para SDL_WINDOWEVENT_SIZE_CHANGED #include <SDL2/SDL_video.h> // Para SDL_WINDOWEVENT_SIZE_CHANGED
#include <utility> // Para move #include <utility> // Para move
#include "global_inputs.h" // Para check #include <iostream>
#include "input.h" // Para Input #include "global_inputs.h" // Para check
#include "jail_audio.h" // Para JA_StopMusic #include "input.h" // Para Input
#include "param.h" // Para Param, ParamGame, param #include "jail_audio.h" // Para JA_StopMusic
#include "resource.h" // Para Resource #include "param.h" // Para Param, ParamGame, param
#include "screen.h" // Para Screen #include "resource.h" // Para Resource
#include "section.h" // Para Name, name, Options, options #include "screen.h" // Para Screen
#include "sprite.h" // Para Sprite #include "section.h" // Para Name, name, Options, options
#include "texture.h" // Para Texture #include "sprite.h" // Para Sprite
#include "utils.h" // Para Color, Zone #include "texture.h" // Para Texture
#include "utils.h" // Para Color, Zone
#include "mouse.h" #include "mouse.h"
// Constructor // Constructor
@@ -52,6 +53,9 @@ Logo::Logo()
color_.push_back(Color(0x00, 0xd8, 0xd8)); // Cyan color_.push_back(Color(0x00, 0xd8, 0xd8)); // Cyan
color_.push_back(Color(0xd8, 0xd8, 0x00)); // Yellow color_.push_back(Color(0xd8, 0xd8, 0x00)); // Yellow
color_.push_back(Color(0xFF, 0xFF, 0xFF)); // Bright white 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 // Destructor
@@ -60,6 +64,7 @@ Logo::~Logo()
jail_texture_->setColor(255, 255, 255); jail_texture_->setColor(255, 255, 255);
since_texture_->setColor(255, 255, 255); since_texture_->setColor(255, 255, 255);
JA_StopChannel(-1); JA_StopChannel(-1);
SDL_DestroyTexture(mi_textura);
} }
// Recarga todas las texturas // 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 // Gestiona el logo de RETROWEEKEND
void Logo::updateRETROWEEKEND() void Logo::updateRETROWEEKEND()
{ {
if (SDL_GetTicks() >= ticks_start_ + 5000)
{
section::name = section::Name::INTRO;
}
} }
// Gestiona el color de las texturas // Gestiona el color de las texturas
@@ -209,15 +225,9 @@ void Logo::update()
break; break;
} }
// Gestiona el contador y sus eventos // Gestiona el contador
counter_++; 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 // Actualiza las variables de globalInputs
globalInputs::update(); globalInputs::update();
} }
@@ -279,4 +289,113 @@ void Logo::renderJAILGAMES()
// Renderiza el logo de RETROWEEKEND // Renderiza el logo de RETROWEEKEND
void Logo::renderRETROWEEKEND() void Logo::renderRETROWEEKEND()
{ {
} // 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<Pixel> Logo::extractPixels(SDL_Texture *texture)
{
std::vector<Pixel> 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<Pixel> &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();
}
}

View File

@@ -2,8 +2,9 @@
#include <SDL2/SDL_rect.h> // Para SDL_Point #include <SDL2/SDL_rect.h> // Para SDL_Point
#include <SDL2/SDL_stdinc.h> // Para Uint32 #include <SDL2/SDL_stdinc.h> // Para Uint32
#include <memory> // Para shared_ptr, unique_ptr #include <SDL2/SDL.h>
#include <vector> // Para vector #include <memory> // Para shared_ptr, unique_ptr
#include <vector> // Para vector
class Sprite; class Sprite;
class Texture; // lines 9-9 class Texture; // lines 9-9
struct Color; struct Color;
@@ -16,6 +17,21 @@ struct Color;
ZX Spectrum 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 // Clase Logo
class Logo class Logo
{ {
@@ -45,6 +61,9 @@ private:
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
SDL_Point dest_; // Posición X donde dibujar el logo SDL_Point dest_; // Posición X donde dibujar el logo
LogoState state_ = LogoState::JAILGAMES; // El estado indica qué logo se está procesando 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<Pixel> pixels_; // Vector con los pixels que forman el logo de "RETROWEEKEND"
SDL_Texture *mi_textura;
// Actualiza las variables // Actualiza las variables
void update(); void update();
@@ -76,6 +95,10 @@ private:
// Recarga todas las texturas // Recarga todas las texturas
void reloadTextures(); void reloadTextures();
std::vector<Pixel> extractPixels(SDL_Texture *texture);
void renderAndEvaporate(SDL_Renderer *renderer, std::vector<Pixel> &pixels);
public: public:
// Constructor // Constructor
Logo(); Logo();

View File

@@ -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 // Obtiene un color del vector de colores imitando al Coche Fantástico
Color getColorLikeKnightRider(const std::vector<Color> &colors, int counter_) Color getColorLikeKnightRider(const std::vector<Color> &colors, int counter_)
{ {
int cycle_length = colors.size() * 2 - 2; int cycle_length = colors.size() * 2 - 2;
size_t n = counter_ % cycle_length; size_t n = counter_ % cycle_length;
size_t index; size_t index;
if (n < colors.size()) if (n < colors.size())
{ {
index = n; // Avanza: 0,1,2,3 index = n; // Avanza: 0,1,2,3
} }
else else
{ {
index = 2 * (colors.size() - 1) - n; // Retrocede: 2,1 index = 2 * (colors.size() - 1) - n; // Retrocede: 2,1
} }
return colors[index]; return colors[index];
} }
// Calcula el cuadrado de la distancia entre dos puntos // 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); std::filesystem::path path(full_path);
return path.parent_path().string(); return path.parent_path().string();
} }