|
@@ -42,6 +42,17 @@ void Ball::initialize(b2World *world, float radius)
|
|
body->CreateFixture(&fixtureDef);
|
|
body->CreateFixture(&fixtureDef);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void Ball::update()
|
|
|
|
+{
|
|
|
|
+ float x = body->GetPosition().x * SCALE_F;
|
|
|
|
+ if (x < -BALL_RADIUS) {
|
|
|
|
+ reset();
|
|
|
|
+ }
|
|
|
|
+ if (x > FIELD_SIZE.x + BALL_RADIUS) {
|
|
|
|
+ reset();
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
void Ball::draw(sf::RenderTarget *target)
|
|
void Ball::draw(sf::RenderTarget *target)
|
|
{
|
|
{
|
|
ballCircle.setPosition(getPosition());
|
|
ballCircle.setPosition(getPosition());
|
|
@@ -74,6 +85,14 @@ float Ball::getRotation()
|
|
return RAD_TO_DEG * body->GetAngle();
|
|
return RAD_TO_DEG * body->GetAngle();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void Ball::reset()
|
|
|
|
+{
|
|
|
|
+ setPosition(FIELD_SIZE / 2.0f);
|
|
|
|
+ setRotation(0);
|
|
|
|
+ body->SetLinearVelocity(b2Vec2(0, 0));
|
|
|
|
+ body->SetAngularVelocity(0);
|
|
|
|
+}
|
|
|
|
+
|
|
sf::Packet &operator <<(sf::Packet &packet, Ball &ball)
|
|
sf::Packet &operator <<(sf::Packet &packet, Ball &ball)
|
|
{
|
|
{
|
|
sf::Vector2f ballPosition = ball.getPosition();
|
|
sf::Vector2f ballPosition = ball.getPosition();
|