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

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

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

Loading…
Cancel
Save