Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

The ball bounces #65

Open
TheoPannetier opened this issue Feb 14, 2024 · 1 comment
Open

The ball bounces #65

TheoPannetier opened this issue Feb 14, 2024 · 1 comment
Assignees

Comments

@TheoPannetier
Copy link
Contributor

TheoPannetier commented Feb 14, 2024

The ball should bounce. For now, a simple bouncing mechanism would simply be:

  • if the ball would meet the ground while falling, it bounces back up by the remaining falling distance
 // issue 65 - The ball bounces
  // Before solving this test, make sure that solution for issue_15 has been merged here
  {
    ball b;
    const double bounce_speed = 1.0;

    // If the ball is high enough, it simply drops
    const double initial_y = 1.2; // that is, higher than the drop rate
    b.set_y(initial_y);
    b.drop(bounce_speed);
    const double y_first_bounce = y_high - bounce_speed
    assert(b.get_y() == y_first_bounce);

    // If the ball would touch the ground, it bounces by the remaining distance
    b.drop(bounce_speed);
    const double y_second_bounce = abs(y_first_bounce - bounce_speed);
    assert(b.get_y == y_second_bounce);
  }
@OggyOggelito
Copy link
Contributor

Saw right away there were some missing. But added it now.

OggyOggelito added a commit that referenced this issue Mar 6, 2024
OggyOggelito added a commit that referenced this issue Mar 6, 2024
OggyOggelito added a commit that referenced this issue Mar 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants