From cca948ee0b08ede53282d3f1bf4f66be27b558db Mon Sep 17 00:00:00 2001 From: RuiAlonso Date: Mon, 21 Mar 2022 15:46:48 +0100 Subject: [PATCH] refactor: improve layer and ramp to allow connection between different layers outside from board --- lib/game/components/layer.dart | 5 +++++ lib/game/components/ramp_opening.dart | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/game/components/layer.dart b/lib/game/components/layer.dart index d5df0698..3cc0471f 100644 --- a/lib/game/components/layer.dart +++ b/lib/game/components/layer.dart @@ -55,6 +55,9 @@ enum Layer { /// Collide only with Launcher group elements. launcher, + + /// Collide only with Spaceship group elements. + spaceship, } /// {@template layer_mask_bits} @@ -81,6 +84,8 @@ extension LayerMaskBits on Layer { return 0x0002; case Layer.launcher: return 0x0005; + case Layer.spaceship: + return 0x000A; } } } diff --git a/lib/game/components/ramp_opening.dart b/lib/game/components/ramp_opening.dart index 4ff8f8c9..2d8454dd 100644 --- a/lib/game/components/ramp_opening.dart +++ b/lib/game/components/ramp_opening.dart @@ -27,15 +27,21 @@ abstract class RampOpening extends BodyComponent with InitialPosition, Layered { /// {@macro ramp_opening} RampOpening({ required Layer pathwayLayer, + Layer? outsideLayer, required this.orientation, - }) : _pathwayLayer = pathwayLayer { + }) : _pathwayLayer = pathwayLayer, + _outsideLayer = outsideLayer ?? Layer.board { layer = Layer.board; } final Layer _pathwayLayer; + final Layer _outsideLayer; /// Mask of category bits for collision inside [Pathway]. Layer get pathwayLayer => _pathwayLayer; + /// Mask of category bits for collision outside [Pathway]. + Layer get outsideLayer => _outsideLayer; + /// The [Shape] of the [RampOpening]. Shape get shape; @@ -85,7 +91,7 @@ class RampOpeningBallContactCallback @override void end(Ball ball, Opening opening, Contact _) { if (!_ballsInside.contains(ball)) { - ball.layer = Layer.board; + ball.layer = opening.outsideLayer; } else { // TODO(ruimiguel): change this code. Check what happens with ball that // slightly touch Opening and goes out again. With InitialPosition change @@ -97,7 +103,7 @@ class RampOpeningBallContactCallback ball.body.linearVelocity.y > 0); if (isBallOutsideOpening) { - ball.layer = Layer.board; + ball.layer = opening.outsideLayer; _ballsInside.remove(ball); } }