From e13cff3de341cfae413b1f05a3454bd6c0fb8a17 Mon Sep 17 00:00:00 2001 From: Fuyang Liu Date: Thu, 15 Oct 2020 17:16:59 +0200 Subject: [PATCH 1/2] Fix breakout bug - ball flighlying out when colide paddle and wall --- examples/game/breakout.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/game/breakout.rs b/examples/game/breakout.rs index 4d32fa6762820..54bdacf161fa7 100644 --- a/examples/game/breakout.rs +++ b/examples/game/breakout.rs @@ -33,6 +33,7 @@ struct Scoreboard { enum Collider { Solid, Scorable, + Paddle, } fn setup( @@ -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()), @@ -240,7 +241,13 @@ 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 + match *collider { + Collider::Solid => { + break; + } + _ => {} + } } } } From 9314fc98f966ab00eaebc2ae2fe1025335860f69 Mon Sep 17 00:00:00 2001 From: Fuyang Liu Date: Thu, 15 Oct 2020 23:05:08 +0200 Subject: [PATCH 2/2] Minor fixup - address PR input --- examples/game/breakout.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/game/breakout.rs b/examples/game/breakout.rs index 54bdacf161fa7..c1ea6c3d018e5 100644 --- a/examples/game/breakout.rs +++ b/examples/game/breakout.rs @@ -242,11 +242,8 @@ fn ball_collision_system( } // break if this collide is on a solid, otherwise continue check whether a solid is also in collision - match *collider { - Collider::Solid => { - break; - } - _ => {} + if let Collider::Solid = *collider { + break; } } }