canviat abs per fabs
This commit is contained in:
+6
-3
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user