From 556e6502f15cb58be57c7c89f54597868038fac1 Mon Sep 17 00:00:00 2001 From: Allison Ryan Date: Mon, 11 Apr 2022 13:54:11 -0500 Subject: [PATCH] feat: prevent going back into launch ramp --- lib/game/components/controlled_ball.dart | 1 + lib/game/components/plunger.dart | 7 ++- .../lib/src/components/launch_ramp.dart | 46 ++++++++++++++----- .../lib/src/components/layer.dart | 2 +- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/lib/game/components/controlled_ball.dart b/lib/game/components/controlled_ball.dart index 51ab9905..470fac81 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 = LaunchRamp.ballPriorityInsideRamp; + layer = Layer.launcher; } /// {@template bonus_ball} diff --git a/lib/game/components/plunger.dart b/lib/game/components/plunger.dart index b8c079b5..77749067 100644 --- a/lib/game/components/plunger.dart +++ b/lib/game/components/plunger.dart @@ -10,13 +10,16 @@ import 'package:pinball_components/pinball_components.dart' hide Assets; /// /// [Plunger] ignores gravity so the player controls its downward [_pull]. /// {@endtemplate} -class Plunger extends BodyComponent with KeyboardHandler, InitialPosition { +class Plunger extends BodyComponent + with KeyboardHandler, 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; diff --git a/packages/pinball_components/lib/src/components/launch_ramp.dart b/packages/pinball_components/lib/src/components/launch_ramp.dart index 407319d2..147d8262 100644 --- a/packages/pinball_components/lib/src/components/launch_ramp.dart +++ b/packages/pinball_components/lib/src/components/launch_ramp.dart @@ -20,20 +20,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, ]); } } @@ -143,13 +144,10 @@ 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: LaunchRamp.ballPriorityInsideRamp + 1) { - layer = Layer.launcher; - } + : super(priority: LaunchRamp.ballPriorityInsideRamp + 1); List _createFixtureDefs() { final fixturesDef = []; @@ -219,6 +217,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]. @@ -230,10 +248,14 @@ class _LaunchRampExit extends RampOpening { }) : _rotation = rotation, super( insideLayer: Layer.launcher, + outsideLayer: Layer.board, orientation: RampOrientation.down, insidePriority: LaunchRamp.ballPriorityInsideRamp, 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 10477eff..3a0c423c 100644 --- a/packages/pinball_components/lib/src/components/layer.dart +++ b/packages/pinball_components/lib/src/components/layer.dart @@ -89,7 +89,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: