fix: modified rampopening for priority changes

pull/126/head
RuiAlonso 4 years ago
parent 022adb5f8e
commit 2095e90f8a

@ -124,6 +124,7 @@ class _LauncherRampOpening extends RampOpening {
super( super(
pathwayLayer: Layer.launcher, pathwayLayer: Layer.launcher,
orientation: RampOrientation.down, orientation: RampOrientation.down,
pathwayPriority: 4,
); );
final double _rotation; final double _rotation;

@ -171,6 +171,7 @@ class SpaceshipExitRailEnd extends RampOpening {
: super( : super(
pathwayLayer: Layer.spaceshipExitRail, pathwayLayer: Layer.spaceshipExitRail,
orientation: RampOrientation.down, orientation: RampOrientation.down,
pathwayPriority: 3,
) { ) {
layer = Layer.spaceshipExitRail; layer = Layer.spaceshipExitRail;
} }

@ -27,12 +27,18 @@ abstract class RampOpening extends BodyComponent with InitialPosition, Layered {
/// {@macro ramp_opening} /// {@macro ramp_opening}
RampOpening({ RampOpening({
required Layer pathwayLayer, required Layer pathwayLayer,
required int pathwayPriority,
Layer? outsideLayer, Layer? outsideLayer,
int? outsidePriority,
required this.orientation, required this.orientation,
}) : _pathwayLayer = pathwayLayer, }) : _pathwayLayer = pathwayLayer,
_outsideLayer = outsideLayer ?? Layer.board { _outsideLayer = outsideLayer ?? Layer.board,
_pathwayPriority = pathwayPriority,
_outsidePriority = outsidePriority ?? 1 {
layer = Layer.board; layer = Layer.board;
} }
final int _pathwayPriority;
final int _outsidePriority;
final Layer _pathwayLayer; final Layer _pathwayLayer;
final Layer _outsideLayer; final Layer _outsideLayer;
@ -42,6 +48,12 @@ abstract class RampOpening extends BodyComponent with InitialPosition, Layered {
/// Mask of category bits for collision outside pathway. /// Mask of category bits for collision outside pathway.
Layer get outsideLayer => _outsideLayer; Layer get outsideLayer => _outsideLayer;
/// Mask of category bits for collision outside pathway.
int get pathwayPriority => _pathwayPriority;
/// Mask of category bits for collision outside pathway.
int get outsidePriority => _outsidePriority;
/// The [Shape] of the [RampOpening]. /// The [Shape] of the [RampOpening].
Shape get shape; Shape get shape;
@ -82,7 +94,9 @@ class RampOpeningBallContactCallback<Opening extends RampOpening>
if (!_ballsInside.contains(ball)) { if (!_ballsInside.contains(ball)) {
layer = opening.pathwayLayer; layer = opening.pathwayLayer;
_ballsInside.add(ball); _ballsInside.add(ball);
ball.layer = layer; ball
..layer = layer
..priority = opening.pathwayPriority;
} else { } else {
_ballsInside.remove(ball); _ballsInside.remove(ball);
} }
@ -103,7 +117,9 @@ class RampOpeningBallContactCallback<Opening extends RampOpening>
ball.body.linearVelocity.y > 0); ball.body.linearVelocity.y > 0);
if (isBallOutsideOpening) { if (isBallOutsideOpening) {
ball.layer = opening.outsideLayer; ball
..layer = opening.outsideLayer
..priority = opening.outsidePriority;
_ballsInside.remove(ball); _ballsInside.remove(ball);
} }
} }

@ -149,14 +149,11 @@ class SpaceshipEntrance extends RampOpening {
: super( : super(
pathwayLayer: Layer.spaceship, pathwayLayer: Layer.spaceship,
orientation: RampOrientation.up, orientation: RampOrientation.up,
pathwayPriority: 4,
) { ) {
layer = Layer.spaceship; layer = Layer.spaceship;
} }
/// Priority order for [SpaceshipHole] on enter.
// TODO(ruimiguel): apply Elevated when PR merged.
final int onEnterElevation = 4;
@override @override
Shape get shape { Shape get shape {
renderBody = false; renderBody = false;
@ -186,6 +183,8 @@ class SpaceshipHole extends RampOpening {
pathwayLayer: Layer.spaceship, pathwayLayer: Layer.spaceship,
outsideLayer: onExitLayer, outsideLayer: onExitLayer,
orientation: RampOrientation.up, orientation: RampOrientation.up,
pathwayPriority: 4,
outsidePriority: onExitElevation,
) { ) {
layer = Layer.spaceship; layer = Layer.spaceship;
} }
@ -269,8 +268,7 @@ class SpaceshipEntranceBallContactCallback
@override @override
void begin(SpaceshipEntrance entrance, Ball ball, _) { void begin(SpaceshipEntrance entrance, Ball ball, _) {
ball ball
// TODO(ruimiguel): apply Elevated when PR merged. ..priority = entrance.pathwayPriority
..priority = entrance.onEnterElevation
..gameRef.reorderChildren() ..gameRef.reorderChildren()
..layer = Layer.spaceship; ..layer = Layer.spaceship;
} }
@ -287,7 +285,7 @@ class SpaceshipHoleBallContactCallback
void begin(SpaceshipHole hole, Ball ball, _) { void begin(SpaceshipHole hole, Ball ball, _) {
ball ball
// TODO(ruimiguel): apply Elevated when PR merged. // TODO(ruimiguel): apply Elevated when PR merged.
..priority = hole.onExitElevation ..priority = hole.outsidePriority
..gameRef.reorderChildren() ..gameRef.reorderChildren()
..layer = hole.outsideLayer; ..layer = hole.outsideLayer;
} }

Loading…
Cancel
Save