demo: Pequeños retoques en el efecto de fuego
This commit is contained in:
27
main.cpp
27
main.cpp
@@ -52,14 +52,16 @@ int gradCurrentColor = 192; // Color actual más alto del degradado
|
|||||||
int gradBreathDirection = 0; // Indica si gradCurrentColor crece o decrece
|
int gradBreathDirection = 0; // Indica si gradCurrentColor crece o decrece
|
||||||
|
|
||||||
// Variables para el efecto de fuego
|
// Variables para el efecto de fuego
|
||||||
const int fireScreenWidth = 320; // Ancho del efecto de fuego
|
const int fireDesp = 3; // Desplazamiento inferior del efecto de fuego para eliminar las primeras filas
|
||||||
const int fireScreenHeight = 240; // Alto del efecto de fuego
|
const int fireWidth = 320; // Ancho del efecto de fuego
|
||||||
Uint8 fire[fireScreenHeight][fireScreenWidth]; // Buffer con el fuego
|
const int fireHeight = 240 + fireDesp; // Alto del efecto de fuego
|
||||||
|
Uint8 fire[fireHeight][fireWidth]; // Buffer con el fuego
|
||||||
Uint32 palette[256]; // Paleta de color para el fuego
|
Uint32 palette[256]; // Paleta de color para el fuego
|
||||||
int fireModifier = 28; // Valor para modificar el efecto de fuego (0-30)
|
int fireModifier = 28; // Valor para modificar el efecto de fuego (0-30)
|
||||||
SDL_Texture *fireTexture; // Textura donde pintar los pixels del fuego
|
SDL_Texture *fireTexture; // Textura donde pintar los pixels del fuego
|
||||||
Uint32 *fireBuffer; // Ubiación donde se guardan los pixeles del fuego
|
Uint32 *fireBuffer; // Ubiación donde se guardan los pixeles del fuego
|
||||||
int pitch;
|
int pitch; // No se utiliza pero se necesita para dibujar los pixeles en la textura
|
||||||
|
SDL_Rect fireSource = {0, 0, fireWidth, fireHeight - fireDesp}; // Parte de la textura donde está el efecto de fuego que se copiará a la pantalla
|
||||||
|
|
||||||
// Inicializa las opciones
|
// Inicializa las opciones
|
||||||
void initOptions();
|
void initOptions();
|
||||||
@@ -256,11 +258,11 @@ void initFire()
|
|||||||
srand((unsigned)SDL_GetTicks());
|
srand((unsigned)SDL_GetTicks());
|
||||||
|
|
||||||
// Inicializa el buffer de fuego
|
// Inicializa el buffer de fuego
|
||||||
for (int y = 0; y < fireScreenHeight; ++y)
|
for (int y = 0; y < fireHeight; ++y)
|
||||||
for (int x = 0; x < fireScreenWidth; ++x)
|
for (int x = 0; x < fireWidth; ++x)
|
||||||
fire[y][x] = 0;
|
fire[y][x] = 0;
|
||||||
|
|
||||||
fireTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, fireScreenWidth, fireScreenHeight);
|
fireTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, fireWidth, fireHeight);
|
||||||
|
|
||||||
// Inicializa la paleta
|
// Inicializa la paleta
|
||||||
for (int x = 0; x < 256; ++x)
|
for (int x = 0; x < 256; ++x)
|
||||||
@@ -270,9 +272,14 @@ void initFire()
|
|||||||
// Saturation is always the maximum: 255
|
// Saturation is always the maximum: 255
|
||||||
// Lightness is 0..255 for x=0..128, and 255 for x=128..255
|
// Lightness is 0..255 for x=0..128, and 255 for x=128..255
|
||||||
ColorRGB color = HSLtoRGB(ColorHSL(x / 3, 255, std::min(255, x * 2)));
|
ColorRGB color = HSLtoRGB(ColorHSL(x / 3, 255, std::min(255, x * 2)));
|
||||||
|
|
||||||
// Pon en la paleta el color calculado
|
// Pon en la paleta el color calculado
|
||||||
palette[x] = (Uint32)16777216 * 255 + 65536 * color.r + 256 * color.g + color.b;
|
palette[x] = (Uint32)16777216 * 255 + 65536 * color.r + 256 * color.g + color.b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Coloca algo de fuego en la textura
|
||||||
|
for (int x = 0; x < 100; ++x)
|
||||||
|
updateFire();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa todo
|
// Inicializa todo
|
||||||
@@ -445,8 +452,8 @@ void updateGradient()
|
|||||||
// Actualiza el efecto de fuego
|
// Actualiza el efecto de fuego
|
||||||
void updateFire()
|
void updateFire()
|
||||||
{
|
{
|
||||||
const int w = fireScreenWidth;
|
const int w = fireWidth;
|
||||||
const int h = fireScreenHeight;
|
const int h = fireHeight;
|
||||||
const int mod = 157 - fireModifier;
|
const int mod = 157 - fireModifier;
|
||||||
|
|
||||||
// Bloquea la textura para poder escribir en los pixeles
|
// Bloquea la textura para poder escribir en los pixeles
|
||||||
@@ -546,7 +553,7 @@ void renderGradient()
|
|||||||
// Dibuja el efecto de fuego
|
// Dibuja el efecto de fuego
|
||||||
void renderFire()
|
void renderFire()
|
||||||
{
|
{
|
||||||
SDL_RenderCopy(renderer, fireTexture, NULL, NULL);
|
SDL_RenderCopy(renderer, fireTexture, &fireSource, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja el efecto de fondo
|
// Dibuja el efecto de fondo
|
||||||
|
|||||||
Reference in New Issue
Block a user