demo: fire effect arreglado bug en la creación de la primera linea del efecto
This commit is contained in:
10
main.cpp
10
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]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user