Compare commits

...

2 Commits

2 changed files with 43 additions and 4 deletions

Binary file not shown.

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[])
{
@@ -123,15 +127,51 @@ int main(int argc, char *argv[])
// Actualiza el sprite
if (sprite->getPosX() + sprite->getWidth() > options->gameWidth or sprite->getPosX() < 0)
{
sprite->setVelX(sprite->getVelX() * -1);
sprite->undoMoveX();
int spr_direction = 1;
int spr_force = 1;
if (sprite->getVelX() > 0)
{
spr_direction = -1;
}
if (SDL_GetTicks() % 2 == 0)
{
spr_force = 2;
}
sprite->setVelX(spr_force * spr_direction);
JA_PlaySound(sound);
}
if (sprite->getPosY() + sprite->getHeight() > options->gameHeight or sprite->getPosY() < 0)
{
sprite->setVelY(sprite->getVelY() * -1);
sprite->undoMoveY();
int spr_direction = 1;
int spr_force = 1;
if (sprite->getVelY() > 0)
{
spr_direction = -1;
}
if (SDL_GetTicks() % 2 == 0)
{
spr_force = 2;
}
sprite->setVelY(spr_force * spr_direction);
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
@@ -142,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);
}