yaaaa rebota todo

This commit is contained in:
2024-08-21 12:09:32 +02:00
parent 36cb6154d7
commit cdd6e7bc5d
4 changed files with 18 additions and 19 deletions
+12 -13
View File
@@ -18,6 +18,7 @@ Ball::Ball(float x, float vx, float vy, color_t color, Texture *texture)
g = GRAVITY;
onFloor = false;
stopped = false;
loss = ((rand() % 30) * 0.01f) + 0.6f;
}
// Destructor
@@ -37,16 +38,16 @@ void Ball::update()
return;
}
// Actualiza la posición
x += vx;
y += vy;
// Aplica la gravedad
if (!onFloor)
// Aplica la gravedad a la velocidad
if (!onFloor && (y - SCREEN_HEIGHT) < BALL_SIZE * 2)
{
vy += g;
}
// Actualiza la posición en función de la velocidad
x += vx;
y += vy;
// Comprueba las colisiones con el lateral izquierdo
if (x < 0)
{
@@ -69,13 +70,11 @@ void Ball::update()
}
// Comprueba las colisiones con la parte inferior
// if (y + h > SCREEN_HEIGHT)
if ((y + h > SCREEN_HEIGHT) && (vy > 0))
if (y + h > SCREEN_HEIGHT)
{
// y = SCREEN_HEIGHT - h;
vy = -vy * LOSS;
std::cout << vy << std::endl;
if (abs(vy) < 0.5f)
y = SCREEN_HEIGHT - h;
vy = -vy * loss;
if (abs(vy) < 0.1f)
{
vy = 0.0f;
onFloor = true;
@@ -90,7 +89,7 @@ void Ball::update()
{
vx = 0.0f;
stopped = true;
exit(0);
//exit(0);
}
}