diff --git a/lib/game/components/components.dart b/lib/game/components/components.dart index 9192a77e..d3a76aea 100644 --- a/lib/game/components/components.dart +++ b/lib/game/components/components.dart @@ -16,5 +16,5 @@ export 'ramp_opening.dart'; export 'round_bumper.dart'; export 'score_points.dart'; export 'spaceship.dart'; -export 'spaceship_drop_ramp.dart'; +export 'spaceship_exit_rail.dart'; export 'wall.dart'; diff --git a/lib/game/components/spaceship.dart b/lib/game/components/spaceship.dart index 153f3a93..479a05fd 100644 --- a/lib/game/components/spaceship.dart +++ b/lib/game/components/spaceship.dart @@ -32,7 +32,8 @@ class Spaceship extends Forge2DBlueprint { SpaceshipBridge()..initialPosition = position, SpaceshipBridgeTop()..initialPosition = position + Vector2(0, 5.5), SpaceshipHole( - onExitLayer: Layer.spaceship_drop, + onExitLayer: Layer.spaceshipDrop, + onExitElevation: 2, )..initialPosition = position - Vector2(5, 4), SpaceshipHole()..initialPosition = position - Vector2(-5, 4), SpaceshipWall()..initialPosition = position, @@ -45,6 +46,7 @@ class Spaceship extends Forge2DBlueprint { /// {@endtemplate} class SpaceshipSaucer extends BodyComponent with InitialPosition, Layered { /// {@macro spaceship_saucer} + // TODO(ruimiguel): apply Elevated when PR merged. SpaceshipSaucer() : super(priority: 2) { layer = Layer.spaceship; } @@ -99,6 +101,7 @@ class SpaceshipSaucer extends BodyComponent with InitialPosition, Layered { /// {@endtemplate} class SpaceshipBridgeTop extends BodyComponent with InitialPosition { /// {@macro spaceship_bridge_top} + // TODO(ruimiguel): apply Elevated when PR merged. SpaceshipBridgeTop() : super(priority: 6); @override @@ -134,6 +137,7 @@ class SpaceshipBridgeTop extends BodyComponent with InitialPosition { /// {@endtemplate} class SpaceshipBridge extends BodyComponent with InitialPosition, Layered { /// {@macro spaceship_bridge} + // TODO(ruimiguel): apply Elevated when PR merged. SpaceshipBridge() : super(priority: 3) { layer = Layer.spaceship; } @@ -192,6 +196,10 @@ class SpaceshipEntrance extends RampOpening { layer = Layer.spaceship; } + /// Priority order for [SpaceshipHole] on enter. + // TODO(ruimiguel): apply Elevated when PR merged. + final int onEnterElevation = 3; + @override Shape get shape { const radius = Spaceship.radius * 2; @@ -211,11 +219,11 @@ class SpaceshipEntrance extends RampOpening { /// {@template spaceship_hole} /// A sensor [BodyComponent] responsible for sending the [Ball] -/// back to the board. +/// out from the [Spaceship]. /// {@endtemplate} class SpaceshipHole extends RampOpening { /// {@macro spaceship_hole} - SpaceshipHole({Layer? onExitLayer}) + SpaceshipHole({Layer? onExitLayer, this.onExitElevation = 1}) : super( pathwayLayer: Layer.spaceship, outsideLayer: onExitLayer, @@ -224,6 +232,10 @@ class SpaceshipHole extends RampOpening { layer = Layer.spaceship; } + /// Priority order for [SpaceshipHole] on exit. + // TODO(ruimiguel): apply Elevated when PR merged. + final int onExitElevation; + @override Shape get shape { return CircleShape()..radius = Spaceship.radius / 40; @@ -238,6 +250,7 @@ class SpaceshipHole extends RampOpening { /// {@endtemplate} class SpaceshipWall extends BodyComponent with InitialPosition, Layered { /// {@macro spaceship_wall} + // TODO(ruimiguel): apply Elevated when PR merged SpaceshipWall() : super(priority: 4) { layer = Layer.spaceship; } @@ -299,7 +312,8 @@ class SpaceshipEntranceBallContactCallback @override void begin(SpaceshipEntrance entrance, Ball ball, _) { ball - ..priority = 3 + // TODO(ruimiguel): apply Elevated when PR merged. + ..priority = entrance.onEnterElevation ..gameRef.reorderChildren() ..layer = Layer.spaceship; } @@ -308,14 +322,15 @@ class SpaceshipEntranceBallContactCallback /// [ContactCallback] that handles the contact between the [Ball] /// and a [SpaceshipHole]. /// -/// It resets the [Ball] priority and filter data so it will "be back" on the +/// It sets the [Ball] priority and filter data so it will "be back" on the /// board. class SpaceshipHoleBallContactCallback extends ContactCallback { @override void begin(SpaceshipHole hole, Ball ball, _) { ball - ..priority = 1 + // TODO(ruimiguel): apply Elevated when PR merged. + ..priority = hole.onExitElevation ..gameRef.reorderChildren() ..layer = hole.outsideLayer; } diff --git a/lib/game/components/spaceship_drop_ramp.dart b/lib/game/components/spaceship_exit_rail.dart similarity index 70% rename from lib/game/components/spaceship_drop_ramp.dart rename to lib/game/components/spaceship_exit_rail.dart index 83133345..f9f45587 100644 --- a/lib/game/components/spaceship_drop_ramp.dart +++ b/lib/game/components/spaceship_exit_rail.dart @@ -7,7 +7,7 @@ import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:pinball/flame/blueprint.dart'; import 'package:pinball/game/game.dart'; -class SpaceshipDropRamp extends Forge2DBlueprint { +class SpaceshipExitRail extends Forge2DBlueprint { @override void build() { final position = Vector2( @@ -16,10 +16,10 @@ class SpaceshipDropRamp extends Forge2DBlueprint { ); addAllContactCallback([ - SpaceshipDropHoleBallContactCallback(), + SpaceshipExitHoleBallContactCallback(), ]); - final curvedPath = Pathway.bezierCurve( + final pathway = Pathway.bezierCurve( color: const Color.fromARGB(255, 226, 226, 218), width: 4, rotation: 230 * math.pi / 180, @@ -31,7 +31,7 @@ class SpaceshipDropRamp extends Forge2DBlueprint { ], )..layer = Layer.spaceshipDrop; - final curvedEntrance = Pathway.arc( + final entrance = Pathway.arc( color: const Color.fromARGB(255, 226, 226, 218), center: position, radius: 4, @@ -41,7 +41,7 @@ class SpaceshipDropRamp extends Forge2DBlueprint { singleWall: true, )..layer = Layer.spaceshipDrop; - final curvedExit = Pathway.arc( + final exit = Pathway.arc( color: const Color.fromARGB(255, 226, 226, 218), center: position, radius: 4, @@ -52,21 +52,21 @@ class SpaceshipDropRamp extends Forge2DBlueprint { )..layer = Layer.spaceshipDrop; addAll([ - curvedPath..initialPosition = position, - curvedEntrance..initialPosition = position + Vector2(26.5, -30), - curvedExit..initialPosition = position + Vector2(29, -66.5), - SpaceshipDropHole()..initialPosition = position + Vector2(0, -42), + pathway..initialPosition = position, + entrance..initialPosition = position + Vector2(26.5, -30), + exit..initialPosition = position + Vector2(29, -66.5), + SpaceshipExitHole()..initialPosition = position + Vector2(0, -42), ]); } } -/// {@template spaceship_drop_hole} +/// {@template spaceship_exit_hole} /// A sensor [BodyComponent] responsible for sending the [Ball] /// back to the board. /// {@endtemplate} -class SpaceshipDropHole extends RampOpening { - /// {@macro spaceship_drop_hole} - SpaceshipDropHole() +class SpaceshipExitHole extends RampOpening { + /// {@macro spaceship_exit_hole} + SpaceshipExitHole() : super( pathwayLayer: Layer.spaceshipDrop, orientation: RampOrientation.down, @@ -81,14 +81,14 @@ class SpaceshipDropHole extends RampOpening { } /// [ContactCallback] that handles the contact between the [Ball] -/// and a [SpaceshipDropHole]. +/// and a [SpaceshipExitHole]. /// /// It resets the [Ball] priority and filter data so it will "be back" on the /// board. -class SpaceshipDropHoleBallContactCallback - extends ContactCallback { +class SpaceshipExitHoleBallContactCallback + extends ContactCallback { @override - void begin(SpaceshipDropHole hole, Ball ball, _) { + void begin(SpaceshipExitHole hole, Ball ball, _) { ball ..priority = 1 ..gameRef.reorderChildren() diff --git a/lib/game/pinball_game.dart b/lib/game/pinball_game.dart index 836b7520..442ca718 100644 --- a/lib/game/pinball_game.dart +++ b/lib/game/pinball_game.dart @@ -42,6 +42,7 @@ class PinballGame extends Forge2DGame unawaited(_addBonusWord()); unawaited(_addPaths()); unawaited(addFromBlueprint(Spaceship())); + unawaited(addFromBlueprint(SpaceshipExitRail())); // Fix camera on the center of the board. camera @@ -83,8 +84,6 @@ class PinballGame extends Forge2DGame } Future _addPaths() async { - unawaited(addFromBlueprint(SpaceshipDropRamp())); - final jetpackRamp = JetpackRamp( position: Vector2( PinballGame.boardBounds.left + 40.5, diff --git a/test/game/components/spaceship_drop_ramp_test.dart b/test/game/components/spaceship_exit_rail_test.dart similarity index 84% rename from test/game/components/spaceship_drop_ramp_test.dart rename to test/game/components/spaceship_exit_rail_test.dart index 3802c55b..a77d85d1 100644 --- a/test/game/components/spaceship_drop_ramp_test.dart +++ b/test/game/components/spaceship_exit_rail_test.dart @@ -12,7 +12,7 @@ void main() { late Body body; late PinballGame game; late Ball ball; - late SpaceshipDropHole hole; + late SpaceshipExitHole hole; setUp(() { filterData = MockFilter(); @@ -29,14 +29,14 @@ void main() { when(() => ball.gameRef).thenReturn(game); when(() => ball.body).thenReturn(body); - hole = MockSpaceshipDropHole(); + hole = MockSpaceshipExitHole(); }); - group('SpaceshipDropHoleBallContactCallback', () { + group('SpaceshipExitHoleBallContactCallback', () { test('changes the ball priority on contact', () { when(() => hole.outsideLayer).thenReturn(Layer.board); - SpaceshipDropHoleBallContactCallback().begin( + SpaceshipExitHoleBallContactCallback().begin( hole, ball, MockContact(), @@ -48,7 +48,7 @@ void main() { test('re order the game children', () { when(() => hole.outsideLayer).thenReturn(Layer.board); - SpaceshipDropHoleBallContactCallback().begin( + SpaceshipExitHoleBallContactCallback().begin( hole, ball, MockContact(), diff --git a/test/game/components/spaceship_test.dart b/test/game/components/spaceship_test.dart index 420b0088..f5179925 100644 --- a/test/game/components/spaceship_test.dart +++ b/test/game/components/spaceship_test.dart @@ -36,16 +36,20 @@ void main() { group('SpaceshipEntranceBallContactCallback', () { test('changes the ball priority on contact', () { + when(() => entrance.onEnterElevation).thenReturn(3); + SpaceshipEntranceBallContactCallback().begin( entrance, ball, MockContact(), ); - verify(() => ball.priority = 3).called(1); + verify(() => ball.priority = entrance.onEnterElevation).called(1); }); test('re order the game children', () { + when(() => entrance.onEnterElevation).thenReturn(3); + SpaceshipEntranceBallContactCallback().begin( entrance, ball, @@ -59,6 +63,7 @@ void main() { group('SpaceshipHoleBallContactCallback', () { test('changes the ball priority on contact', () { when(() => hole.outsideLayer).thenReturn(Layer.board); + when(() => hole.onExitElevation).thenReturn(1); SpaceshipHoleBallContactCallback().begin( hole, @@ -66,11 +71,12 @@ void main() { MockContact(), ); - verify(() => ball.priority = 1).called(1); + verify(() => ball.priority = hole.onExitElevation).called(1); }); test('re order the game children', () { when(() => hole.outsideLayer).thenReturn(Layer.board); + when(() => hole.onExitElevation).thenReturn(1); SpaceshipHoleBallContactCallback().begin( hole, diff --git a/test/helpers/mocks.dart b/test/helpers/mocks.dart index 6c807966..10541caa 100644 --- a/test/helpers/mocks.dart +++ b/test/helpers/mocks.dart @@ -60,4 +60,4 @@ class MockSpaceshipEntrance extends Mock implements SpaceshipEntrance {} class MockSpaceshipHole extends Mock implements SpaceshipHole {} -class MockSpaceshipDropHole extends Mock implements SpaceshipDropHole {} +class MockSpaceshipExitHole extends Mock implements SpaceshipExitHole {}