void Ball::update(sf::Time& delta, sf::FloatRect& p1, sf::FloatRect& p2)
{
// Obtenemos los cuatro laterales de la bola
float left = this->getPosition().x - this->getOrigin().x;
float right = this->getPosition().x + this->getOrigin().x;
float top = this->getPosition().y - this->getOrigin().y;
float bottom = this->getPosition().y + this->getOrigin().y;
// Comprobamos si choca contra las paredes
if (left <= 0 && speed.x < 0)
{
this->speed.x *= -1;
this->sound.play();
}
if (right >= WIDTH && speed.x > 0)
{
this->speed.x *= -1;
this->sound.play();
}
if ((top <= 0 && speed.y < 0) || (bottom >= HEIGHT && speed.y > 0))
{
this->speed.y *= -1;
this->sound.play();
}
// Por último comprobamos si ha chocado contra las palas
if (this->getGlobalBounds().intersects(p1) || this->getGlobalBounds().intersects(p2))
{
this->speed.x *= -1;
this->sound.play();
}
// Movemos la bola multiplicando la velocidad por el tiempo pasado
this->move(delta.asSeconds() * this->speed.x, delta.asSeconds() * this->speed.y);
}