diff --git a/lib/game/components/bonus_word.dart b/lib/game/components/bonus_word.dart index 03f64a11..cc6391e8 100644 --- a/lib/game/components/bonus_word.dart +++ b/lib/game/components/bonus_word.dart @@ -36,31 +36,39 @@ class BonusWord extends Component with BlocComponent { for (var i = 0; i < letters.length; i++) { final letter = letters[i]; - letter.add( - SequenceEffect( - [ - ColorEffect( - i.isOdd ? BonusLetter._activeColor : BonusLetter._disableColor, - const Offset(0, 1), - EffectController(duration: 0.25), - ), - ColorEffect( - i.isOdd ? BonusLetter._disableColor : BonusLetter._activeColor, - const Offset(0, 1), - EffectController(duration: 0.25), - ), - ], - repeatCount: 4, - )..onFinishCallback = () { - letter.add( + letter + ..isEnabled = false + ..add( + SequenceEffect( + [ ColorEffect( - BonusLetter._disableColor, + i.isOdd + ? BonusLetter._activeColor + : BonusLetter._disableColor, const Offset(0, 1), EffectController(duration: 0.25), ), - ); - }, - ); + ColorEffect( + i.isOdd + ? BonusLetter._disableColor + : BonusLetter._activeColor, + const Offset(0, 1), + EffectController(duration: 0.25), + ), + ], + repeatCount: 4, + )..onFinishCallback = () { + letter + ..isEnabled = true + ..add( + ColorEffect( + BonusLetter._disableColor, + const Offset(0, 1), + EffectController(duration: 0.25), + ), + ); + }, + ); } } } @@ -107,6 +115,13 @@ class BonusLetter extends BodyComponent final String _letter; final int _index; + /// Indicates if a [BonusLetter] can be activated on [Ball] contact. + /// + /// It is disabled whilst animating and enabled again once the animation + /// completes. The animation is triggered when [GameBonus.word] is + /// awarded. + bool isEnabled = true; + @override Future onLoad() async { await super.onLoad(); @@ -172,6 +187,8 @@ class BonusLetterBallContactCallback extends ContactCallback { @override void begin(Ball ball, BonusLetter bonusLetter, Contact contact) { - bonusLetter.activate(); + if (bonusLetter.isEnabled) { + bonusLetter.activate(); + } } } diff --git a/test/game/components/bonus_word_test.dart b/test/game/components/bonus_word_test.dart index a9af305e..47a7e257 100644 --- a/test/game/components/bonus_word_test.dart +++ b/test/game/components/bonus_word_test.dart @@ -300,12 +300,26 @@ void main() { test('calls ball.activate', () { final ball = MockBall(); final bonusLetter = MockBonusLetter(); - final contactCallback = BonusLetterBallContactCallback(); + + when(() => bonusLetter.isEnabled).thenReturn(true); + contactCallback.begin(ball, bonusLetter, MockContact()); verify(bonusLetter.activate).called(1); }); + + test("doesn't call ball.activate when letter is disabled", () { + final ball = MockBall(); + final bonusLetter = MockBonusLetter(); + final contactCallback = BonusLetterBallContactCallback(); + + when(() => bonusLetter.isEnabled).thenReturn(false); + + contactCallback.begin(ball, bonusLetter, MockContact()); + + verifyNever(bonusLetter.activate); + }); }); }); }