Demo: añadido efecto al degradado

This commit is contained in:
2023-05-07 11:19:35 +02:00
parent 5da4ece581
commit 8bcd3e6068

View File

@@ -20,6 +20,10 @@ SDL_Renderer *renderer;
int ticks = 0;
int ticksSpeed = 15;
int counter = 0;
int gradColorMin = 64; // Minimo color más alto del degradado
int gradColorMax = 192; // Minimo color más alto del degradado
int gradCurrentColor = 192; // Color actual más alto del degradado
int gradBreathDirection = 0; // Indica si gradCurrentColor crece o decrece
int main(int argc, char *argv[])
{
@@ -154,6 +158,20 @@ int main(int argc, char *argv[])
JA_PlaySound(sound);
}
sprite->update();
// Actualiza el degradado
//if (counter % 4 == 0)
{
gradBreathDirection == 0 ? gradCurrentColor-- : gradCurrentColor++;
if (gradCurrentColor == gradColorMin)
{
gradBreathDirection = 1;
}
if (gradCurrentColor == gradColorMax)
{
gradBreathDirection = 0;
}
}
}
// Dibuja en pantalla
@@ -164,12 +182,11 @@ int main(int argc, char *argv[])
const int gradLastLine = options->gameHeight;
const int gradNumLines = gradLastLine - gradFirstLine;
const int gradColorFrom = 0;
const int gradColorTo = 192;
for (int i = gradFirstLine; i < gradLastLine; ++i)
{
float step = ((float)(i - gradFirstLine) / gradNumLines);
int color = gradColorFrom + ((gradColorTo - gradColorFrom) * step);
int color = gradColorFrom + ((gradCurrentColor - gradColorFrom) * step);
SDL_SetRenderDrawColor(renderer, color, 0x00, 0x00, 0xFF);
SDL_RenderDrawLine(renderer, 0, i, options->gameWidth, i);
}