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

View File

@@ -3,16 +3,17 @@
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
#include <SDL2/SDL_video.h> // Para SDL_WINDOWEVENT_SIZE_CHANGED
#include <utility> // 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 <iostream>
#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()
{
}
// 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();
}
}