Demo: añadido efecto al degradado
This commit is contained in:
21
main.cpp
21
main.cpp
@@ -20,6 +20,10 @@ SDL_Renderer *renderer;
|
|||||||
int ticks = 0;
|
int ticks = 0;
|
||||||
int ticksSpeed = 15;
|
int ticksSpeed = 15;
|
||||||
int counter = 0;
|
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[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@@ -154,6 +158,20 @@ int main(int argc, char *argv[])
|
|||||||
JA_PlaySound(sound);
|
JA_PlaySound(sound);
|
||||||
}
|
}
|
||||||
sprite->update();
|
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
|
// Dibuja en pantalla
|
||||||
@@ -164,12 +182,11 @@ int main(int argc, char *argv[])
|
|||||||
const int gradLastLine = options->gameHeight;
|
const int gradLastLine = options->gameHeight;
|
||||||
const int gradNumLines = gradLastLine - gradFirstLine;
|
const int gradNumLines = gradLastLine - gradFirstLine;
|
||||||
const int gradColorFrom = 0;
|
const int gradColorFrom = 0;
|
||||||
const int gradColorTo = 192;
|
|
||||||
|
|
||||||
for (int i = gradFirstLine; i < gradLastLine; ++i)
|
for (int i = gradFirstLine; i < gradLastLine; ++i)
|
||||||
{
|
{
|
||||||
float step = ((float)(i - gradFirstLine) / gradNumLines);
|
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_SetRenderDrawColor(renderer, color, 0x00, 0x00, 0xFF);
|
||||||
SDL_RenderDrawLine(renderer, 0, i, options->gameWidth, i);
|
SDL_RenderDrawLine(renderer, 0, i, options->gameWidth, i);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user