refactor: rampopening with layered mixin

pull/40/head
RuiAlonso 4 years ago
parent 0c240f12de
commit 8d408da582

@ -47,11 +47,15 @@ class JetpackRamp extends Component with HasGameRef<PinballGame> {
final leftOpening = JetpackRampOpening(
orientation: RampOrientation.down,
rotation: radians(15),
)..initialPosition = position + Vector2(-11, 1);
)
..initialPosition = position + Vector2(-11, 1)
..layer = Layer.opening;
final rightOpening = JetpackRampOpening(
orientation: RampOrientation.down,
rotation: radians(-9),
)..initialPosition = position + Vector2(20.5, 3.4);
)
..initialPosition = position + Vector2(20.5, 3.4)
..layer = Layer.opening;
await addAll([
curvePath,
@ -74,7 +78,6 @@ class JetpackRampOpening extends RampOpening {
_orientation = orientation,
super(
pathwayLayer: Layer.jetpack,
openingLayer: Layer.opening,
);
/// Orientation of entrance/exit of [JetpackRamp] where

@ -52,10 +52,14 @@ class LauncherRamp extends Component with HasGameRef<PinballGame> {
final leftOpening = LauncherRampOpening(
orientation: RampOrientation.down,
rotation: radians(13),
)..initialPosition = position + Vector2(-46.5, -8.5);
)
..initialPosition = position + Vector2(-46.5, -8.5)
..layer = Layer.opening;
final rightOpening = LauncherRampOpening(
orientation: RampOrientation.down,
)..initialPosition = position + Vector2(4, 0);
)
..initialPosition = position + Vector2(4, 0)
..layer = Layer.opening;
await addAll([
straightPath,
@ -79,7 +83,6 @@ class LauncherRampOpening extends RampOpening {
_orientation = orientation,
super(
pathwayLayer: Layer.launcher,
openingLayer: Layer.opening,
);
/// Orientation of entrance/exit of [LauncherRamp] where

@ -21,20 +21,15 @@ enum RampOrientation {
/// through this opening. By default openings are [Layer.board] that
/// means opening are at ground level, not over board.
/// {@endtemplate}
abstract class RampOpening extends BodyComponent with InitialPosition {
abstract class RampOpening extends BodyComponent with InitialPosition, Layered {
/// {@macro ramp_opening}
RampOpening({
required Layer pathwayLayer,
Layer? openingLayer,
}) : _pathwayLayer = pathwayLayer,
_openingLayer = openingLayer ?? Layer.board;
final Layer _openingLayer;
}) : _pathwayLayer = pathwayLayer {
layer = Layer.board;
}
final Layer _pathwayLayer;
/// Mask of category bits for collision with [RampOpening].
Layer get openingLayer => _openingLayer;
/// Mask of category bits for collision inside [Pathway].
Layer get pathwayLayer => _pathwayLayer;
@ -48,9 +43,7 @@ abstract class RampOpening extends BodyComponent with InitialPosition {
@override
Body createBody() {
final fixtureDef = FixtureDef(shape)
..isSensor = true
..filter.categoryBits = _openingLayer.maskBits;
final fixtureDef = FixtureDef(shape)..isSensor = true;
final bodyDef = BodyDef()
..userData = this

Loading…
Cancel
Save