From f13947e73c48ca368935c029f170e46904b89535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Thu, 25 May 2023 07:22:14 +0200 Subject: [PATCH] =?UTF-8?q?demo:=20fire=20effect=20arreglado=20bug=20en=20?= =?UTF-8?q?la=20creaci=C3=B3n=20de=20la=20primera=20linea=20del=20efecto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index 553a6f5..fea0a78 100644 --- a/main.cpp +++ b/main.cpp @@ -60,7 +60,6 @@ int gradBreathDirection = 0; // Indica si gradCurrentColor crece o decrece const int fireScreenWidth = 320; // Ancho del efecto de fuego const int fireScreenHeight = 180; // Alto del efecto de fuego Uint32 fire[fireScreenHeight][fireScreenWidth]; // Buffer con el fuego -Uint32 buffer[fireScreenHeight][fireScreenWidth]; // Buffer para dibujar en pantalla ColorRGB palette[256]; // Paleta de color para el fuego const int fireDesp = 240 - fireScreenHeight + 3; // Fila donde comienza a dibujarse el efecto de fuego @@ -255,6 +254,9 @@ void initSprite() // Inicializa el efecto de fuego void initFire() { + // Intializes random number generator + srand((unsigned) SDL_GetTicks()); + // Inicializa el buffer de fuego for (int y = 0; y < fireScreenHeight; ++y) for (int x = 0; x < fireScreenWidth; ++x) @@ -435,13 +437,17 @@ void updateFire() const int w = fireScreenWidth; const int h = fireScreenHeight; for (int x = 0; x < w; ++x) - fire[h - 1][x] = abs(32768 + rand()) % 256; + //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 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) / 129; + //fire[y][x] = std::min(255,(int)fire[y][x]); + //fire[y][x] = std::max(0,(int)fire[y][x]); + } }