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;
MovingSprite *sprite;
// Listas
enum e_fx // Tipos de efectos disponibles para el fondo
{
fx_fire,
fx_gradient
};
// Variables de uso general
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
@@ -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
string controllerName; // Nombre del primer mando detectado
string inputPressed; // Texto con el último input que se ha pulsado
e_fx fx = fx_fire; // Efecto seleccionado para el fondo
int fxTotal = 2; // Cantidad total de efectos disponibles para el fondo
int fx = 0; // Efecto seleccionado para el fondo
// 0 - Degradado
// 1 - Fuego
int fxTotal = 2; // Cantidad total de efectos disponibles para el fondo
// Variables para el efecto del degradado
int gradColorMin = 64; // Minimo color más alto del degradado
@@ -328,7 +323,6 @@ void checkEvents()
{
switch (event->key.keysym.scancode)
{
case SDL_SCANCODE_ESCAPE:
should_exit = true;
break;
@@ -351,6 +345,10 @@ void checkEvents()
fireModifier = std::min(30, fireModifier);
break;
case SDL_SCANCODE_SPACE:
++fx %= fxTotal;
break;
case SDL_SCANCODE_N:
screen->showNotification("Ejemplo de notificacion", "con 2 lineas de texto", 0);
break;
@@ -447,23 +445,15 @@ void updateFire()
const int w = fireScreenWidth;
const int h = fireScreenHeight;
const int mod = 157 - fireModifier;
// for (int x = 0; x < w; ++x)
// const int max = 10;
// 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
// Crea la fila inferior del fuego con pixels aleatorios
for (int x = 0; x < w; ++x)
// fire[h - 1][x] = abs(32768 + 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 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
@@ -471,12 +461,12 @@ void updateFX()
{
switch (fx)
{
case fx_fire:
updateFire();
case 0: // Degradado
updateGradient();
break;
case fx_gradient:
updateGradient();
case 1: // Fuego
updateFire();
break;
default:
@@ -555,12 +545,12 @@ void renderFX()
{
switch (fx)
{
case fx_fire:
renderFire();
case 0: // Degradado
renderGradient();
break;
case fx_gradient:
renderGradient();
case 1: // Fuego
renderFire();
break;
default:
@@ -571,16 +561,19 @@ void renderFX()
// Dibuja el texto
void renderText()
{
const string fxName = fx == 0 ? "Degradado" : "Fuego";
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->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});
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() * 11, controllerName, 1, {240, 240, 240}, 1, {0, 0, 192});
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() * 9, "Pulsa 'ESPACIO' para cambiar el efecto de fondo: " + fxName, 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() * 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, 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