diff --git a/lib/game/components/controlled_spaceship_ramp.dart b/lib/game/components/controlled_spaceship_ramp.dart index 495f7a1f..6aa83371 100644 --- a/lib/game/components/controlled_spaceship_ramp.dart +++ b/lib/game/components/controlled_spaceship_ramp.dart @@ -54,15 +54,16 @@ class SpaceshipRampController int _hitsCounter = 0; + /// When a [Ball] shot the [SpaceshipRamp] it achieve improvements for the + /// current game, like multipliers or score. void shot() { _hitsCounter++; component._spaceshipRamp.progress(); - // TODO(ruimiguel): Ramp shot gameRef.read().add(const Scored(points: 5000)); - // TODO(ruimiguel): increase score multiplier at GameBloc. + // TODO(ruimiguel): increase here multiplier at GameBloc. if (_hitsCounter % _oneMillionPointsTarget == 0) { // TODO(ruimiguel): One million by bonus?? @@ -78,8 +79,14 @@ class SpaceshipRampController } } +/// Used to know when a [Ball] gets into the [SpaceshipRamp] against every ball +/// that crosses the opening. +@visibleForTesting enum SpaceshipRampSensorType { + /// Sensor at the entrance of the opening. door, + + /// Sensor inside the [SpaceshipRamp]. inside, } @@ -87,6 +94,7 @@ enum SpaceshipRampSensorType { /// Small sensor body used to detect when a ball has entered the /// [SpaceshipRamp]. /// {@endtemplate} +@visibleForTesting class SpaceshipRampSensor extends BodyComponent with InitialPosition, Layered { /// {@macro spaceship_ramp_sensor} SpaceshipRampSensor({required this.type}) : super() { @@ -94,6 +102,7 @@ class SpaceshipRampSensor extends BodyComponent with InitialPosition, Layered { renderBody = false; } + /// Type for the sensor, to know if it's the one at the door or inside ramp. final SpaceshipRampSensorType type; @override diff --git a/packages/pinball_components/lib/src/components/spaceship_ramp.dart b/packages/pinball_components/lib/src/components/spaceship_ramp.dart index 30211251..f8cee7ac 100644 --- a/packages/pinball_components/lib/src/components/spaceship_ramp.dart +++ b/packages/pinball_components/lib/src/components/spaceship_ramp.dart @@ -34,7 +34,7 @@ class SpaceshipRamp extends Blueprint { _SpaceshipRampForegroundRailing(), _SpaceshipRampBase()..initialPosition = Vector2(1.7, -20), _SpaceshipRampBackgroundRailingSpriteComponent(), - _SpaceshipRampArrowSpriteComponent(), + SpaceshipRampArrowSpriteComponent(), ], ); @@ -42,7 +42,7 @@ class SpaceshipRamp extends Blueprint { /// /// If the current state is the last one it cycles back to the initial state. void progress() => components - .whereType<_SpaceshipRampArrowSpriteComponent>() + .whereType() .first .progress(); } @@ -203,11 +203,12 @@ class _SpaceshipRampBackgroundRampSpriteComponent extends SpriteComponent /// /// Lights progressively whenever a [Ball] gets into [SpaceshipRamp]. /// {@endtemplate} -class _SpaceshipRampArrowSpriteComponent +@visibleForTesting +class SpaceshipRampArrowSpriteComponent extends SpriteGroupComponent with HasGameRef { /// {@macro spaceship_ramp_arrow_sprite_component} - _SpaceshipRampArrowSpriteComponent() + SpaceshipRampArrowSpriteComponent() : super( anchor: Anchor.center, position: Vector2(-3.9, -56.5), diff --git a/test/game/components/controlled_spaceship_ramp_test.dart b/test/game/components/controlled_spaceship_ramp_test.dart index 03f2baba..e35c570b 100644 --- a/test/game/components/controlled_spaceship_ramp_test.dart +++ b/test/game/components/controlled_spaceship_ramp_test.dart @@ -1,6 +1,7 @@ // ignore_for_file: cascade_invocations import 'package:bloc_test/bloc_test.dart'; +import 'package:flame/components.dart'; import 'package:flame_test/flame_test.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -39,7 +40,7 @@ void main() { group('loads', () { flameTester.test( - 'a SpaceshipRamp', + 'four SpriteComponent (two rails, main and opening)', (game) async { final controlledSpaceshipRamp = ControlledSpaceshipRamp(); await game.ensureAdd(controlledSpaceshipRamp); @@ -47,7 +48,23 @@ void main() { expect( controlledSpaceshipRamp .descendants() - .whereType() + .whereType() + .length, + equals(4), + ); + }, + ); + + flameTester.test( + 'a SpaceshipRampArrowSpriteComponent', + (game) async { + final controlledSpaceshipRamp = ControlledSpaceshipRamp(); + await game.ensureAdd(controlledSpaceshipRamp); + + expect( + controlledSpaceshipRamp + .descendants() + .whereType() .length, equals(1), );