Skip to content

Commit

Permalink
Fix breakout example bug - ball flying out when collide paddle and wa…
Browse files Browse the repository at this point in the history
…ll at the same time (#685)

Fix breakout bug - ball flying out when collide paddle and wall
  • Loading branch information
liufuyang authored Oct 15, 2020
1 parent 90ea5b1 commit 9db8ae7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions examples/game/breakout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct Scoreboard {
enum Collider {
Solid,
Scorable,
Paddle,
}

fn setup(
Expand All @@ -53,7 +54,7 @@ fn setup(
..Default::default()
})
.with(Paddle { speed: 500.0 })
.with(Collider::Solid)
.with(Collider::Paddle)
// ball
.spawn(SpriteComponents {
material: materials.add(Color::rgb(1.0, 0.5, 0.5).into()),
Expand Down Expand Up @@ -240,7 +241,10 @@ fn ball_collision_system(
*velocity.y_mut() = -velocity.y();
}

break;
// break if this collide is on a solid, otherwise continue check whether a solid is also in collision
if let Collider::Solid = *collider {
break;
}
}
}
}
Expand Down

0 comments on commit 9db8ae7

Please sign in to comment.