diff --git a/lib/game/components/controlled_ball.dart b/lib/game/components/controlled_ball.dart index 7a94f96b..d4f37bc7 100644 --- a/lib/game/components/controlled_ball.dart +++ b/lib/game/components/controlled_ball.dart @@ -19,6 +19,7 @@ class ControlledBall extends Ball with Controls { }) : super(baseColor: theme.characterTheme.ballColor) { controller = BallController(this); priority = Ball.launchRampPriority; + layer = Layer.launcher; } /// {@template bonus_ball} diff --git a/lib/game/pinball_game.dart b/lib/game/pinball_game.dart index cad2eac5..98083269 100644 --- a/lib/game/pinball_game.dart +++ b/lib/game/pinball_game.dart @@ -172,7 +172,7 @@ class DebugPinballGame extends PinballGame with TapDetector { anchor: Anchor.center, ) ..position = Vector2(0, -7.8) - ..priority = -2; + ..priority = -4; await add(spriteComponent); } diff --git a/packages/pinball_components/lib/src/components/ball.dart b/packages/pinball_components/lib/src/components/ball.dart index 71719a0e..b8c8e231 100644 --- a/packages/pinball_components/lib/src/components/ball.dart +++ b/packages/pinball_components/lib/src/components/ball.dart @@ -35,7 +35,7 @@ class Ball extends BodyComponent static const int spaceshipRailPriority = 2; /// Render priority for the [Ball] while it's on the [LaunchRamp]. - static const int launchRampPriority = 0; + static const int launchRampPriority = -2; /// The size of the [Ball]. static final Vector2 size = Vector2.all(4.13); diff --git a/packages/pinball_components/lib/src/components/boundaries.dart b/packages/pinball_components/lib/src/components/boundaries.dart index 16c0f7b7..e5aab5af 100644 --- a/packages/pinball_components/lib/src/components/boundaries.dart +++ b/packages/pinball_components/lib/src/components/boundaries.dart @@ -13,7 +13,7 @@ class Boundaries extends Forge2DBlueprint { final bottomBoundary = _BottomBoundary(); final outerBoundary = _OuterBoundary(); - addAll([bottomBoundary, outerBoundary]); + addAll([outerBoundary, bottomBoundary]); } } @@ -23,7 +23,7 @@ class Boundaries extends Forge2DBlueprint { /// {@endtemplate bottom_boundary} class _BottomBoundary extends BodyComponent with InitialPosition { /// {@macro bottom_boundary} - _BottomBoundary() : super(priority: 2); + _BottomBoundary() : super(priority: 1); List _createFixtureDefs() { final fixturesDefs = []; @@ -88,7 +88,7 @@ class _BottomBoundarySpriteComponent extends SpriteComponent with HasGameRef { /// {@endtemplate outer_boundary} class _OuterBoundary extends BodyComponent with InitialPosition { /// {@macro outer_boundary} - _OuterBoundary() : super(priority: -1); + _OuterBoundary() : super(priority: Ball.launchRampPriority - 1); List _createFixtureDefs() { final fixturesDefs = []; diff --git a/packages/pinball_components/lib/src/components/dino_walls.dart b/packages/pinball_components/lib/src/components/dino_walls.dart index dc5b7a26..aec4c7aa 100644 --- a/packages/pinball_components/lib/src/components/dino_walls.dart +++ b/packages/pinball_components/lib/src/components/dino_walls.dart @@ -124,7 +124,7 @@ class _DinoTopWallSpriteComponent extends SpriteComponent with HasGameRef { /// {@endtemplate} class _DinoBottomWall extends BodyComponent with InitialPosition { ///{@macro dino_top_wall} - _DinoBottomWall() : super(priority: 1); + _DinoBottomWall(); List _createFixtureDefs() { final fixturesDef = []; diff --git a/packages/pinball_components/lib/src/components/launch_ramp.dart b/packages/pinball_components/lib/src/components/launch_ramp.dart index 02ac742a..e92e1124 100644 --- a/packages/pinball_components/lib/src/components/launch_ramp.dart +++ b/packages/pinball_components/lib/src/components/launch_ramp.dart @@ -17,20 +17,21 @@ class LaunchRamp extends Forge2DBlueprint { RampOpeningBallContactCallback<_LaunchRampExit>(), ]); - final launchRampBase = _LaunchRampBase()..layer = Layer.launcher; + final launchRampBase = _LaunchRampBase(); - final launchRampForegroundRailing = _LaunchRampForegroundRailing() - ..layer = Layer.launcher; + final launchRampForegroundRailing = _LaunchRampForegroundRailing(); final launchRampExit = _LaunchRampExit(rotation: math.pi / 2) - ..initialPosition = Vector2(1.8, 34.2) - ..layer = Layer.opening - ..renderBody = false; + ..initialPosition = Vector2(0.6, 34); + + final launchRampCloseWall = _LaunchRampCloseWall() + ..initialPosition = Vector2(4, 66.5); addAll([ launchRampBase, launchRampForegroundRailing, launchRampExit, + launchRampCloseWall, ]); } } @@ -40,10 +41,7 @@ class LaunchRamp extends Forge2DBlueprint { /// {@endtemplate} class _LaunchRampBase extends BodyComponent with InitialPosition, Layered { /// {@macro launch_ramp_base} - _LaunchRampBase() - : super( - priority: Ball.launchRampPriority - 1, - ) { + _LaunchRampBase() : super(priority: Ball.launchRampPriority - 1) { layer = Layer.launcher; } @@ -143,15 +141,9 @@ class _LaunchRampBaseSpriteComponent extends SpriteComponent with HasGameRef { /// Foreground railing for the [_LaunchRampBase] to render in front of the /// [Ball]. /// {@endtemplate} -class _LaunchRampForegroundRailing extends BodyComponent - with InitialPosition, Layered { +class _LaunchRampForegroundRailing extends BodyComponent with InitialPosition { /// {@macro launch_ramp_foreground_railing} - _LaunchRampForegroundRailing() - : super( - priority: Ball.launchRampPriority + 1, - ) { - layer = Layer.launcher; - } + _LaunchRampForegroundRailing() : super(priority: Ball.launchRampPriority + 1); List _createFixtureDefs() { final fixturesDef = []; @@ -221,6 +213,26 @@ class _LaunchRampForegroundRailingSpriteComponent extends SpriteComponent } } +class _LaunchRampCloseWall extends BodyComponent with InitialPosition, Layered { + _LaunchRampCloseWall() { + layer = Layer.board; + renderBody = false; + } + + @override + Body createBody() { + final shape = EdgeShape()..set(Vector2.zero(), Vector2(0, 4)); + + final fixtureDef = FixtureDef(shape); + + final bodyDef = BodyDef() + ..userData = this + ..position = initialPosition; + + return world.createBody(bodyDef)..createFixture(fixtureDef); + } +} + /// {@template launch_ramp_exit} /// [RampOpening] with [Layer.launcher] to filter [Ball]s exiting the /// [LaunchRamp]. @@ -232,9 +244,14 @@ class _LaunchRampExit extends RampOpening { }) : _rotation = rotation, super( insideLayer: Layer.launcher, + outsideLayer: Layer.board, orientation: RampOrientation.down, insidePriority: Ball.launchRampPriority, - ); + outsidePriority: 0, + ) { + layer = Layer.launcher; + renderBody = false; + } final double _rotation; diff --git a/packages/pinball_components/lib/src/components/layer.dart b/packages/pinball_components/lib/src/components/layer.dart index 6f027d4c..9b20ecf2 100644 --- a/packages/pinball_components/lib/src/components/layer.dart +++ b/packages/pinball_components/lib/src/components/layer.dart @@ -88,7 +88,7 @@ extension LayerMaskBits on Layer { case Layer.spaceshipEntranceRamp: return 0x0002; case Layer.launcher: - return 0x0005; + return 0x0008; case Layer.spaceship: return 0x000A; case Layer.spaceshipExitRail: diff --git a/packages/pinball_components/lib/src/components/plunger.dart b/packages/pinball_components/lib/src/components/plunger.dart index 7e0ba5ba..19a29300 100644 --- a/packages/pinball_components/lib/src/components/plunger.dart +++ b/packages/pinball_components/lib/src/components/plunger.dart @@ -8,13 +8,15 @@ import 'package:pinball_components/pinball_components.dart'; /// /// [Plunger] ignores gravity so the player controls its downward [pull]. /// {@endtemplate} -class Plunger extends BodyComponent with InitialPosition { +class Plunger extends BodyComponent with InitialPosition, Layered { /// {@macro plunger} Plunger({ required this.compressionDistance, // TODO(ruimiguel): set to priority +1 over LaunchRamp once all priorities // are fixed. - }) : super(priority: 0); + }) : super(priority: 0) { + layer = Layer.launcher; + } /// Distance the plunger can lower. final double compressionDistance;