demo: Se puede cambiar el efecto de fondo desde el teclado

This commit is contained in:
2023-05-25 17:13:44 +02:00
parent c8960704c1
commit 6012b6ac5f

View File

@@ -33,13 +33,6 @@ Text *debugText;
Texture *texture; Texture *texture;
MovingSprite *sprite; MovingSprite *sprite;
// Listas
enum e_fx // Tipos de efectos disponibles para el fondo
{
fx_fire,
fx_gradient
};
// Variables de uso general // Variables de uso general
Uint32 ticks = 0; // Variable para la frecuencia de actualización de la lógica del programa Uint32 ticks = 0; // Variable para la frecuencia de actualización de la lógica del programa
const Uint32 ticksSpeed = 15; // Variable para la frecuencia de actualización de la lógica del programa const Uint32 ticksSpeed = 15; // Variable para la frecuencia de actualización de la lógica del programa
@@ -47,8 +40,10 @@ bool should_exit = false; // Variable para saber si ha terminado el progra,a
int counter = 0; // Contador para lo que se necesite int counter = 0; // Contador para lo que se necesite
string controllerName; // Nombre del primer mando detectado string controllerName; // Nombre del primer mando detectado
string inputPressed; // Texto con el último input que se ha pulsado string inputPressed; // Texto con el último input que se ha pulsado
e_fx fx = fx_fire; // Efecto seleccionado para el fondo int fx = 0; // Efecto seleccionado para el fondo
int fxTotal = 2; // Cantidad total de efectos disponibles para el fondo // 0 - Degradado
// 1 - Fuego
int fxTotal = 2; // Cantidad total de efectos disponibles para el fondo
// Variables para el efecto del degradado // Variables para el efecto del degradado
int gradColorMin = 64; // Minimo color más alto del degradado int gradColorMin = 64; // Minimo color más alto del degradado
@@ -328,7 +323,6 @@ void checkEvents()
{ {
switch (event->key.keysym.scancode) switch (event->key.keysym.scancode)
{ {
case SDL_SCANCODE_ESCAPE: case SDL_SCANCODE_ESCAPE:
should_exit = true; should_exit = true;
break; break;
@@ -351,6 +345,10 @@ void checkEvents()
fireModifier = std::min(30, fireModifier); fireModifier = std::min(30, fireModifier);
break; break;
case SDL_SCANCODE_SPACE:
++fx %= fxTotal;
break;
case SDL_SCANCODE_N: case SDL_SCANCODE_N:
screen->showNotification("Ejemplo de notificacion", "con 2 lineas de texto", 0); screen->showNotification("Ejemplo de notificacion", "con 2 lineas de texto", 0);
break; break;
@@ -447,23 +445,15 @@ void updateFire()
const int w = fireScreenWidth; const int w = fireScreenWidth;
const int h = fireScreenHeight; const int h = fireScreenHeight;
const int mod = 157 - fireModifier; const int mod = 157 - fireModifier;
// for (int x = 0; x < w; ++x)
// const int max = 10; // Crea la fila inferior del fuego con pixels aleatorios
// const int mod = max - abs((counter % (max * 2)) - max);
// for (int x = 0; x < w; ++x)
// fire[h - 1][x] = 0;
// for (int x = mod; x < w - mod; ++x)
// randomize the bottom row of the fire buffer
for (int x = 0; x < w; ++x) for (int x = 0; x < w; ++x)
// fire[h - 1][x] = abs(32768 + rand()) % 256;
fire[h - 1][x] = rand() % 256; fire[h - 1][x] = rand() % 256;
// do the fire calculations for every pixel, from top to bottom
// Calcula los pixeles del efecto de fuego, desde la fila superior hasta la inferior
for (int y = 0; y < h - 1; ++y) for (int y = 0; y < h - 1; ++y)
for (int x = 0; x < w; ++x) for (int x = 0; x < w; ++x)
{ fire[y][x] = ((fire[(y + 1) % h][(x - 1 + w) % w] + fire[(y + 1) % h][(x) % w] + fire[(y + 1) % h][(x + 1) % w] + fire[(y + 2) % h][(x) % w]) * 32) / mod;
fire[y][x] =
((fire[(y + 1) % h][(x - 1 + w) % w] + fire[(y + 1) % h][(x) % w] + fire[(y + 1) % h][(x + 1) % w] + fire[(y + 2) % h][(x) % w]) * 32) / mod;
}
} }
// Actualiza el efecto de fondo // Actualiza el efecto de fondo
@@ -471,12 +461,12 @@ void updateFX()
{ {
switch (fx) switch (fx)
{ {
case fx_fire: case 0: // Degradado
updateFire(); updateGradient();
break; break;
case fx_gradient: case 1: // Fuego
updateGradient(); updateFire();
break; break;
default: default:
@@ -555,12 +545,12 @@ void renderFX()
{ {
switch (fx) switch (fx)
{ {
case fx_fire: case 0: // Degradado
renderFire(); renderGradient();
break; break;
case fx_gradient: case 1: // Fuego
renderGradient(); renderFire();
break; break;
default: default:
@@ -571,16 +561,19 @@ void renderFX()
// Dibuja el texto // Dibuja el texto
void renderText() void renderText()
{ {
const string fxName = fx == 0 ? "Degradado" : "Fuego";
text->setZoom(2); text->setZoom(2);
text->writeDX(TXT_CENTER | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize(), "Jail Engine DEMO", 1, {255, 255, 255}, 1, {0, 0, 192}); text->writeDX(TXT_CENTER | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize(), "Jail Engine DEMO", 1, {255, 255, 255}, 1, {0, 0, 192});
text->disableZoom(); text->disableZoom();
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize() * 4, "2023 JailDesigner", 1, {240, 240, 240}, 1, {0, 0, 192}); text->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize() * 4, "2023 JailDesigner", 1, {240, 240, 240}, 1, {0, 0, 192});
debugText->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize() * 7, "Pulsa 'F1' o 'F2' para disminuir o aumentar la ventana", 1, {240, 240, 240}, 1, {0, 0, 192}); debugText->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize() * 7, "Pulsa 'F1' o 'F2' para disminuir o aumentar la ventana", 1, {240, 240, 240}, 1, {0, 0, 192});
debugText->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize() * 9, "Pulsa 'N' para mostrar una notificacion", 1, {240, 240, 240}, 1, {0, 0, 192}); debugText->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize() * 9, "Pulsa 'ESPACIO' para cambiar el efecto de fondo: " + fxName, 1, {240, 240, 240}, 1, {0, 0, 192});
debugText->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize() * 11, controllerName, 1, {240, 240, 240}, 1, {0, 0, 192}); if (fxName == "Fuego")
debugText->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize() * 13, inputPressed, 1, {240, 240, 240}, 1, {0, 0, 192}); debugText->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize() * 11, "Pulsa 'F3' o 'F4' para modificar el fuego: " + to_string(fireModifier), 1, {240, 240, 240}, 1, {0, 0, 192});
debugText->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize() * 13, "Pulsa 'N' para mostrar una notificacion", 1, {240, 240, 240}, 1, {0, 0, 192});
debugText->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize() * 15, controllerName, 1, {240, 240, 240}, 1, {0, 0, 192});
debugText->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize() * 17, inputPressed, 1, {240, 240, 240}, 1, {0, 0, 192});
debugText->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, options->screen.nativeHeight - (text->getCharacterSize() * 2), "Pulsa 'ESCAPE' para terminar el programa", 1, {240, 240, 240}, 1, {0, 0, 192}); debugText->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, options->screen.nativeHeight - (text->getCharacterSize() * 2), "Pulsa 'ESCAPE' para terminar el programa", 1, {240, 240, 240}, 1, {0, 0, 192});
debugText->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize() * 17, "Pulsa 'F3' o 'F4' para modificar el fuego: " + to_string(fireModifier), 1, {240, 240, 240}, 1, {0, 0, 192});
} }
// Dibuja los elementos del programa en pantalla // Dibuja los elementos del programa en pantalla