void update() { shape.move(velocity); if(left() < 0) velocity.x = ballVelocity; else if(right() > windowWidth) velocity.x = -ballVelocity; if(top() < 0) velocity.y = ballVelocity; else if (bottom() > windowHeight) velocity.y = -ballVelocity; }
//Обновляем координаты void update(){ Vector2f step = {0,0}; float testik = test.angle * 3.14159265358979323846 / 180; step.x = 0.32f * cos(testik); step.y = 0.32f * sin(testik); step.y += 0.0015f * time; shape.move(step); time += 0.1; }
void update() { shape.move(velocity); // We need to keep the ball "inside the screen". // If it's leaving toward the left, we need to set // horizontal velocity to a positive value (towards the right). if(left() < 0) velocity.x = ballVelocity; // Otherwise, if it's leaving towards the right, we need to // set horizontal velocity to a negative value (towards the left). else if(right() > windowWidth) velocity.x = -ballVelocity; // The same idea can be applied for top/bottom collisions. if(top() < 0) velocity.y = ballVelocity; else if(bottom() > windowHeight) velocity.y = -ballVelocity; }
// Let's "update" the ball: move its shape // by the current velocity. void update() { shape.move(velocity); }