Compare commits
5 Commits
2025-02-07
...
f8449ea6d1
| Author | SHA1 | Date | |
|---|---|---|---|
| f8449ea6d1 | |||
| f43d18e6f0 | |||
| a42141ebd7 | |||
| 29c85fecad | |||
| 04ff428aa0 |
@@ -3,6 +3,9 @@
|
|||||||
cmake_minimum_required(VERSION 3.10)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
project(coffee_crisis_arcade_edition VERSION 0.01)
|
project(coffee_crisis_arcade_edition VERSION 0.01)
|
||||||
|
|
||||||
|
# Establece las políticas
|
||||||
|
cmake_policy(SET CMP0072 NEW)
|
||||||
|
|
||||||
# Configuración de compilador para MinGW en Windows, si es necesario
|
# Configuración de compilador para MinGW en Windows, si es necesario
|
||||||
if(WIN32 AND NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
if(WIN32 AND NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||||
set(CMAKE_CXX_COMPILER "g++")
|
set(CMAKE_CXX_COMPILER "g++")
|
||||||
|
|||||||
BIN
data/gfx/logo/logo_retroweekend.png
Normal file
BIN
data/gfx/logo/logo_retroweekend.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.5 KiB |
@@ -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
|
||||||
|
|||||||
@@ -316,12 +316,10 @@ bool Director::initSDL()
|
|||||||
std::cout << "Warning: texture filtering not enabled!\n";
|
std::cout << "Warning: texture filtering not enabled!\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NO_SHADERS
|
|
||||||
if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"))
|
if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"))
|
||||||
{
|
{
|
||||||
std::cout << "Warning: opengl not enabled!\n";
|
std::cout << "Warning: opengl not enabled!\n";
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// Crea la ventana
|
// Crea la ventana
|
||||||
window_ = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, param.game.width * options.video.window.size, param.game.height * options.video.window.size, SDL_WINDOW_HIDDEN);
|
window_ = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, param.game.width * options.video.window.size, param.game.height * options.video.window.size, SDL_WINDOW_HIDDEN);
|
||||||
@@ -339,10 +337,8 @@ bool Director::initSDL()
|
|||||||
flags = SDL_RENDERER_PRESENTVSYNC;
|
flags = SDL_RENDERER_PRESENTVSYNC;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NO_SHADERS
|
|
||||||
// La aceleración se activa según el define
|
// La aceleración se activa según el define
|
||||||
flags = flags | SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
|
flags = flags | SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
|
||||||
#endif
|
|
||||||
|
|
||||||
renderer_ = SDL_CreateRenderer(window_, -1, flags);
|
renderer_ = SDL_CreateRenderer(window_, -1, flags);
|
||||||
|
|
||||||
@@ -484,6 +480,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
|
||||||
|
|||||||
@@ -9,22 +9,22 @@
|
|||||||
#include <unordered_map> // Para unordered_map, operator==, _Node_cons...
|
#include <unordered_map> // Para unordered_map, operator==, _Node_cons...
|
||||||
#include <utility> // Para pair
|
#include <utility> // Para pair
|
||||||
|
|
||||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
// [SINGLETON]
|
||||||
Input *Input::input_ = nullptr;
|
Input *Input::input_ = nullptr;
|
||||||
|
|
||||||
// [SINGLETON] Crearemos el objeto input con esta función estática
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
void Input::init(const std::string &game_controller_db_path)
|
void Input::init(const std::string &game_controller_db_path)
|
||||||
{
|
{
|
||||||
Input::input_ = new Input(game_controller_db_path);
|
Input::input_ = new Input(game_controller_db_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [SINGLETON] Destruiremos el objeto input con esta función estática
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
void Input::destroy()
|
void Input::destroy()
|
||||||
{
|
{
|
||||||
delete Input::input_;
|
delete Input::input_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// [SINGLETON] Con este método obtenemos el objeto input y podemos trabajar con él
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
Input *Input::get()
|
Input *Input::get()
|
||||||
{
|
{
|
||||||
return Input::input_;
|
return Input::input_;
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ enum class InputDeviceToUse : int
|
|||||||
class Input
|
class Input
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// [SINGLETON] Objeto screen privado para Don Melitón
|
// [SINGLETON] Objeto privado
|
||||||
static Input *input_;
|
static Input *input_;
|
||||||
|
|
||||||
struct KeyBindings
|
struct KeyBindings
|
||||||
@@ -109,13 +109,13 @@ private:
|
|||||||
~Input() = default;
|
~Input() = 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 &game_controller_db_path);
|
static void init(const std::string &game_controller_db_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 Input *get();
|
static Input *get();
|
||||||
|
|
||||||
// Asigna inputs a teclas
|
// Asigna inputs a teclas
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#ifndef NO_SHADERS
|
|
||||||
|
|
||||||
#include "jail_shader.h"
|
#include "jail_shader.h"
|
||||||
#include <SDL2/SDL_rect.h> // para SDL_Point
|
#include <SDL2/SDL_rect.h> // para SDL_Point
|
||||||
#include <stdlib.h> // para NULL, free, malloc, exit
|
#include <stdlib.h> // para NULL, free, malloc, exit
|
||||||
@@ -247,5 +245,4 @@ namespace shader
|
|||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
#ifndef NO_SHADERS
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_render.h> // para SDL_Texture
|
#include <SDL2/SDL_render.h> // para SDL_Texture
|
||||||
@@ -44,5 +42,4 @@ namespace shader
|
|||||||
const char *vertexShader, const char *fragmentShader = nullptr);
|
const char *vertexShader, const char *fragmentShader = nullptr);
|
||||||
|
|
||||||
void render();
|
void render();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
224
source/logo.cpp
224
source/logo.cpp
@@ -3,24 +3,24 @@
|
|||||||
#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
|
||||||
Logo::Logo()
|
Logo::Logo()
|
||||||
: since_texture_(Resource::get()->getTexture("logo_since_1998.png")),
|
: since_texture_(Resource::get()->getTexture("logo_since_1998.png")),
|
||||||
since_sprite_(std::make_unique<Sprite>(since_texture_)),
|
since_sprite_(std::make_unique<Sprite>(since_texture_)),
|
||||||
jail_texture_(Resource::get()->getTexture("logo_jailgames.png")),
|
jail_texture_(Resource::get()->getTexture("logo_jailgames.png"))
|
||||||
ticks_(0)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
@@ -61,6 +61,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
|
||||||
@@ -114,7 +115,7 @@ void Logo::checkInput()
|
|||||||
globalInputs::check();
|
globalInputs::check();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gestiona el logo de JAILGAME
|
// Gestiona el logo de JAILGAMES
|
||||||
void Logo::updateJAILGAMES()
|
void Logo::updateJAILGAMES()
|
||||||
{
|
{
|
||||||
if (counter_ == 30)
|
if (counter_ == 30)
|
||||||
@@ -147,6 +148,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
|
// Gestiona el color de las texturas
|
||||||
@@ -190,21 +207,24 @@ void Logo::update()
|
|||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
checkInput();
|
checkInput();
|
||||||
|
|
||||||
// Gestiona el logo de JAILGAME
|
switch (state_)
|
||||||
updateJAILGAMES();
|
|
||||||
|
|
||||||
// Gestiona el color de las texturas
|
|
||||||
updateTextureColors();
|
|
||||||
|
|
||||||
// Gestiona el contador y sus eventos
|
|
||||||
counter_++;
|
|
||||||
|
|
||||||
// Comprueba si ha terminado el logo
|
|
||||||
if (counter_ == END_LOGO_COUNTER_MARK + POST_LOGO_DURATION)
|
|
||||||
{
|
{
|
||||||
section::name = section::Name::INTRO;
|
case LogoState::JAILGAMES:
|
||||||
|
updateJAILGAMES();
|
||||||
|
updateTextureColors();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LogoState::RETROWEEKEND:
|
||||||
|
updateRETROWEEKEND();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gestiona el contador
|
||||||
|
counter_++;
|
||||||
|
|
||||||
// Actualiza las variables de globalInputs
|
// Actualiza las variables de globalInputs
|
||||||
globalInputs::update();
|
globalInputs::update();
|
||||||
}
|
}
|
||||||
@@ -213,24 +233,23 @@ void Logo::update()
|
|||||||
// Dibuja en pantalla
|
// Dibuja en pantalla
|
||||||
void Logo::render()
|
void Logo::render()
|
||||||
{
|
{
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
|
||||||
Screen::get()->start();
|
Screen::get()->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
|
||||||
Screen::get()->clean();
|
Screen::get()->clean();
|
||||||
|
|
||||||
// Dibuja los sprites
|
switch (state_)
|
||||||
for (auto &sprite : jail_sprite_)
|
|
||||||
{
|
{
|
||||||
sprite->render();
|
case LogoState::JAILGAMES:
|
||||||
|
renderJAILGAMES();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LogoState::RETROWEEKEND:
|
||||||
|
renderRETROWEEKEND();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter_ >= SHOW_SINCE_SPRITE_COUNTER_MARK)
|
|
||||||
{
|
|
||||||
since_sprite_->render();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
|
||||||
Screen::get()->render();
|
Screen::get()->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,4 +266,133 @@ void Logo::run()
|
|||||||
checkEvents(); // Tiene que ir antes del render
|
checkEvents(); // Tiene que ir antes del render
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Renderiza el logo de JAILGAMES
|
||||||
|
void Logo::renderJAILGAMES()
|
||||||
|
{
|
||||||
|
// Dibuja los sprites
|
||||||
|
for (auto &sprite : jail_sprite_)
|
||||||
|
{
|
||||||
|
sprite->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (counter_ >= SHOW_SINCE_SPRITE_COUNTER_MARK)
|
||||||
|
{
|
||||||
|
since_sprite_->render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -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,10 +17,31 @@ 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
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
enum class LogoState
|
||||||
|
{
|
||||||
|
JAILGAMES,
|
||||||
|
RETROWEEKEND,
|
||||||
|
};
|
||||||
|
|
||||||
// Constantes
|
// Constantes
|
||||||
static constexpr int SHOW_SINCE_SPRITE_COUNTER_MARK = 70; // Tiempo del contador en el que empieza a verse el sprite de "SINCE 1998"
|
static constexpr int SHOW_SINCE_SPRITE_COUNTER_MARK = 70; // Tiempo del contador en el que empieza a verse el sprite de "SINCE 1998"
|
||||||
static constexpr int INIT_FADE_COUNTER_MARK = 300; // Tiempo del contador cuando inicia el fade a negro
|
static constexpr int INIT_FADE_COUNTER_MARK = 300; // Tiempo del contador cuando inicia el fade a negro
|
||||||
@@ -34,10 +56,14 @@ private:
|
|||||||
std::vector<std::unique_ptr<Sprite>> jail_sprite_; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
|
std::vector<std::unique_ptr<Sprite>> jail_sprite_; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::vector<Color> color_; // Vector con los colores para el fade
|
std::vector<Color> color_; // Vector con los colores para el fade
|
||||||
int counter_; // Contador
|
int counter_; // Contador
|
||||||
Uint32 ticks_; // 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
|
||||||
|
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();
|
||||||
@@ -51,15 +77,28 @@ private:
|
|||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
void checkInput();
|
void checkInput();
|
||||||
|
|
||||||
// Gestiona el logo de JAILGAME
|
// Gestiona el logo de JAILGAMES
|
||||||
void updateJAILGAMES();
|
void updateJAILGAMES();
|
||||||
|
|
||||||
|
// Gestiona el logo de RETROWEEKEND
|
||||||
|
void updateRETROWEEKEND();
|
||||||
|
|
||||||
|
// Renderiza el logo de JAILGAMES
|
||||||
|
void renderJAILGAMES();
|
||||||
|
|
||||||
|
// Renderiza el logo de RETROWEEKEND
|
||||||
|
void renderRETROWEEKEND();
|
||||||
|
|
||||||
// Gestiona el color de las texturas
|
// Gestiona el color de las texturas
|
||||||
void updateTextureColors();
|
void updateTextureColors();
|
||||||
|
|
||||||
// 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();
|
||||||
|
|||||||
@@ -12,22 +12,22 @@
|
|||||||
#include "texture.h" // Para Texture
|
#include "texture.h" // Para Texture
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
|
|
||||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
// [SINGLETON]
|
||||||
Notifier *Notifier::notifier_ = nullptr;
|
Notifier *Notifier::notifier_ = nullptr;
|
||||||
|
|
||||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
void Notifier::init(const std::string &icon_file, std::shared_ptr<Text> text)
|
void Notifier::init(const std::string &icon_file, std::shared_ptr<Text> text)
|
||||||
{
|
{
|
||||||
Notifier::notifier_ = new Notifier(icon_file, text);
|
Notifier::notifier_ = new Notifier(icon_file, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
void Notifier::destroy()
|
void Notifier::destroy()
|
||||||
{
|
{
|
||||||
delete Notifier::notifier_;
|
delete Notifier::notifier_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// [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
|
||||||
Notifier *Notifier::get()
|
Notifier *Notifier::get()
|
||||||
{
|
{
|
||||||
return Notifier::notifier_;
|
return Notifier::notifier_;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class Texture; // lines 11-11
|
|||||||
class Notifier
|
class Notifier
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// [SINGLETON] Objeto notifier privado para Don Melitón
|
// [SINGLETON] Objeto notifier
|
||||||
static Notifier *notifier_;
|
static Notifier *notifier_;
|
||||||
|
|
||||||
enum class NotificationStatus
|
enum class NotificationStatus
|
||||||
@@ -77,13 +77,13 @@ private:
|
|||||||
~Notifier() = default;
|
~Notifier() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// [SINGLETON] Crearemos el objeto notifier con esta función estática
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
static void init(const std::string &icon_file, std::shared_ptr<Text> text);
|
static void init(const std::string &icon_file, std::shared_ptr<Text> text);
|
||||||
|
|
||||||
// [SINGLETON] Destruiremos el objeto notifier 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 notifier y podemos trabajar con él
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
static Notifier *get();
|
static Notifier *get();
|
||||||
|
|
||||||
// Dibuja las notificaciones por pantalla
|
// Dibuja las notificaciones por pantalla
|
||||||
|
|||||||
@@ -15,27 +15,24 @@
|
|||||||
#include "on_screen_help.h" // Para OnScreenHelp
|
#include "on_screen_help.h" // Para OnScreenHelp
|
||||||
#include "options.h" // Para Options, OptionsVideo, options, Options...
|
#include "options.h" // Para Options, OptionsVideo, options, Options...
|
||||||
#include "mouse.h"
|
#include "mouse.h"
|
||||||
|
|
||||||
#ifndef NO_SHADERS
|
|
||||||
#include "jail_shader.h" // para init, render
|
#include "jail_shader.h" // para init, render
|
||||||
#endif
|
|
||||||
|
|
||||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
// [SINGLETON]
|
||||||
Screen *Screen::screen_ = nullptr;
|
Screen *Screen::screen_ = nullptr;
|
||||||
|
|
||||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
void Screen::init(SDL_Window *window, SDL_Renderer *renderer)
|
void Screen::init(SDL_Window *window, SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
Screen::screen_ = new Screen(window, renderer);
|
Screen::screen_ = new Screen(window, renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
void Screen::destroy()
|
void Screen::destroy()
|
||||||
{
|
{
|
||||||
delete Screen::screen_;
|
delete Screen::screen_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// [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
|
||||||
Screen *Screen::get()
|
Screen *Screen::get()
|
||||||
{
|
{
|
||||||
return Screen::screen_;
|
return Screen::screen_;
|
||||||
@@ -105,11 +102,6 @@ void Screen::renderScreen()
|
|||||||
SDL_SetRenderTarget(renderer_, nullptr);
|
SDL_SetRenderTarget(renderer_, nullptr);
|
||||||
clean();
|
clean();
|
||||||
|
|
||||||
#ifdef NO_SHADERS
|
|
||||||
// Actualiza la pantalla con el contenido del buffer de renderizado
|
|
||||||
SDL_RenderCopy(renderer_, game_canvas_, nullptr, nullptr);
|
|
||||||
SDL_RenderPresent(renderer_);
|
|
||||||
#else
|
|
||||||
if (options.video.shaders)
|
if (options.video.shaders)
|
||||||
{
|
{
|
||||||
// Aplica shaders y renderiza el contenido
|
// Aplica shaders y renderiza el contenido
|
||||||
@@ -121,7 +113,6 @@ void Screen::renderScreen()
|
|||||||
SDL_RenderCopy(renderer_, game_canvas_, nullptr, nullptr);
|
SDL_RenderCopy(renderer_, game_canvas_, nullptr, nullptr);
|
||||||
SDL_RenderPresent(renderer_);
|
SDL_RenderPresent(renderer_);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el modo de video
|
// Establece el modo de video
|
||||||
@@ -174,13 +165,11 @@ void Screen::setVideoMode(ScreenVideoMode videoMode)
|
|||||||
// Reinicia los shaders
|
// Reinicia los shaders
|
||||||
if (options.video.shaders)
|
if (options.video.shaders)
|
||||||
{
|
{
|
||||||
#ifndef NO_SHADERS
|
|
||||||
const std::string glsl_file = param.game.game_area.rect.h == 256 ? "crtpi_256.glsl" : "crtpi_240.glsl";
|
const std::string glsl_file = param.game.game_area.rect.h == 256 ? "crtpi_256.glsl" : "crtpi_240.glsl";
|
||||||
std::ifstream f(Asset::get()->get(glsl_file).c_str());
|
std::ifstream f(Asset::get()->get(glsl_file).c_str());
|
||||||
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
||||||
|
|
||||||
shader::init(window_, game_canvas_, source.c_str());
|
shader::init(window_, game_canvas_, source.c_str());
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,12 +352,6 @@ void Screen::attenuate(bool value)
|
|||||||
attenuate_effect_ = value;
|
attenuate_effect_ = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el puntero al renderizador
|
|
||||||
SDL_Renderer *Screen::getRenderer()
|
|
||||||
{
|
|
||||||
return renderer_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calcula los frames por segundo
|
// Calcula los frames por segundo
|
||||||
void Screen::updateFPS()
|
void Screen::updateFPS()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ enum class ScreenVideoMode : int
|
|||||||
class Screen
|
class Screen
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// [SINGLETON] Objeto screen privado para Don Melitón
|
// [SINGLETON] Objeto privado
|
||||||
static Screen *screen_;
|
static Screen *screen_;
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
@@ -110,14 +110,9 @@ private:
|
|||||||
// Calcula la nueva posición de la ventana a partir de la antigua al cambiarla de tamaño
|
// Calcula la nueva posición de la ventana a partir de la antigua al cambiarla de tamaño
|
||||||
SDL_Point getNewPosition();
|
SDL_Point getNewPosition();
|
||||||
|
|
||||||
// Actualiza la pantalla con el contenido del game_canvas_
|
|
||||||
void presentGameCanvas();
|
|
||||||
|
|
||||||
// Selecciona y ejecuta el método de renderizado adecuado basado en la configuración de shaders
|
// Selecciona y ejecuta el método de renderizado adecuado basado en la configuración de shaders
|
||||||
void renderScreen();
|
void renderScreen();
|
||||||
|
|
||||||
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos screen desde fuera
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Screen(SDL_Window *window, SDL_Renderer *renderer);
|
Screen(SDL_Window *window, SDL_Renderer *renderer);
|
||||||
|
|
||||||
@@ -125,13 +120,13 @@ private:
|
|||||||
~Screen();
|
~Screen();
|
||||||
|
|
||||||
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(SDL_Window *window, SDL_Renderer *renderer);
|
static void init(SDL_Window *window, SDL_Renderer *renderer);
|
||||||
|
|
||||||
// [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 Screen *get();
|
static Screen *get();
|
||||||
|
|
||||||
// Actualiza la lógica de la clase
|
// Actualiza la lógica de la clase
|
||||||
@@ -182,6 +177,6 @@ public:
|
|||||||
// Atenua la pantalla
|
// Atenua la pantalla
|
||||||
void attenuate(bool value);
|
void attenuate(bool value);
|
||||||
|
|
||||||
// Obtiene el puntero al renderizador
|
// Getters
|
||||||
SDL_Renderer *getRenderer();
|
SDL_Renderer *getRenderer() { return renderer_; }
|
||||||
};
|
};
|
||||||
@@ -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();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user