canviat abs per fabs

This commit is contained in:
2025-03-24 13:44:46 +01:00
parent e2e3b7c779
commit 29b18e30b5
7 changed files with 54 additions and 35 deletions
+6 -3
View File
@@ -1,5 +1,8 @@
#include "ball.h"
#include "defines.h"
#include <stdlib.h> // for rand
#include <cmath> // for fabs
#include "defines.h" // for BALL_SIZE, Color, SCREEN_HEIGHT, GRAVITY_FORCE
class Texture;
// Constructor
Ball::Ball(float x, float vx, float vy, Color color, std::shared_ptr<Texture> texture)
@@ -62,7 +65,7 @@ void Ball::update()
{
pos_.y = SCREEN_HEIGHT - pos_.h;
vy_ = -vy_ * loss_;
if (abs(vy_) < 0.1f)
if (std::fabs(vy_) < 0.1f)
{
vy_ = 0.0f;
on_floor_ = true;
@@ -73,7 +76,7 @@ void Ball::update()
if (on_floor_)
{
vx_ = vx_ * 0.97f;
if (abs(vx_) < 0.1f)
if (std::fabs(vx_) < 0.1f)
{
vx_ = 0.0f;
stopped_ = true;