diff --git a/lib/game/components/dino_desert/dino_desert.dart b/lib/game/components/dino_desert/dino_desert.dart index 1d7b9072..561466fb 100644 --- a/lib/game/components/dino_desert/dino_desert.dart +++ b/lib/game/components/dino_desert/dino_desert.dart @@ -42,7 +42,7 @@ class _BarrierBehindDino extends BodyComponent { Body createBody() { final shape = EdgeShape() ..set( - Vector2(25.3, -14.2), + Vector2(24.2, -14.8), Vector2(25.3, -7.7), ); diff --git a/lib/game/pinball_game.dart b/lib/game/pinball_game.dart index 23769756..2b003207 100644 --- a/lib/game/pinball_game.dart +++ b/lib/game/pinball_game.dart @@ -155,12 +155,11 @@ class PinballGame extends PinballForge2DGame @override void onTapDown(int pointerId, TapDownInfo info) { - if (info.raw.kind == PointerDeviceKind.touch) { + if (info.raw.kind == PointerDeviceKind.touch && + _gameBloc.state.status.isPlaying) { final rocket = descendants().whereType().first; final bounds = rocket.topLeftPosition & rocket.size; - // NOTE: As long as Flame does not have https://github.com/flame-engine/flame/issues/1586 - // we need to check it at the highest level manually. final tappedRocket = bounds.contains(info.eventPosition.game.toOffset()); if (tappedRocket) { descendants() diff --git a/packages/pinball_audio/lib/src/pinball_audio.dart b/packages/pinball_audio/lib/src/pinball_audio.dart index 4ff0055d..8764df69 100644 --- a/packages/pinball_audio/lib/src/pinball_audio.dart +++ b/packages/pinball_audio/lib/src/pinball_audio.dart @@ -289,10 +289,11 @@ class PinballAudioPlayer { playSingleAudio: _playSingleAudio, path: Assets.sfx.sparky, ), - PinballAudio.dino: _SimplePlayAudio( + PinballAudio.dino: _ThrottledAudio( preCacheSingleAudio: _preCacheSingleAudio, playSingleAudio: _playSingleAudio, path: Assets.sfx.dino, + duration: const Duration(seconds: 6), ), PinballAudio.dash: _SimplePlayAudio( preCacheSingleAudio: _preCacheSingleAudio, diff --git a/packages/pinball_audio/test/src/pinball_audio_test.dart b/packages/pinball_audio/test/src/pinball_audio_test.dart index eeea3f1b..64b5c00d 100644 --- a/packages/pinball_audio/test/src/pinball_audio_test.dart +++ b/packages/pinball_audio/test/src/pinball_audio_test.dart @@ -399,6 +399,32 @@ void main() { ), ).called(1); }); + + test('only plays the sound again after 6 seconds', () async { + final clock = _MockClock(); + await withClock(clock, () async { + when(clock.now).thenReturn(DateTime(2022)); + await Future.wait( + audioPlayer.load().map((loadableBuilder) => loadableBuilder()), + ); + audioPlayer + ..play(PinballAudio.dino) + ..play(PinballAudio.dino); + + verify( + () => playSingleAudio + .onCall('packages/pinball_audio/${Assets.sfx.dino}'), + ).called(1); + + when(clock.now).thenReturn(DateTime(2022, 1, 1, 1, 6)); + audioPlayer.play(PinballAudio.dino); + + verify( + () => playSingleAudio + .onCall('packages/pinball_audio/${Assets.sfx.dino}'), + ).called(1); + }); + }); }); group('android', () { diff --git a/test/game/pinball_game_test.dart b/test/game/pinball_game_test.dart index b44295ed..92608a1d 100644 --- a/test/game/pinball_game_test.dart +++ b/test/game/pinball_game_test.dart @@ -246,9 +246,61 @@ void main() { }); group('flipper control', () { + flameTester.test('tap control only works if game is playing', + (game) async { + await game.ready(); + + final gameBloc = game + .descendants() + .whereType>() + .first + .bloc; + + final eventPosition = _MockEventPosition(); + when(() => eventPosition.game).thenReturn(Vector2.zero()); + when(() => eventPosition.widget).thenReturn(Vector2.zero()); + + final raw = _MockTapDownDetails(); + when(() => raw.kind).thenReturn(PointerDeviceKind.touch); + + final tapDownEvent = _MockTapDownInfo(); + when(() => tapDownEvent.eventPosition).thenReturn(eventPosition); + when(() => tapDownEvent.raw).thenReturn(raw); + + final flipperBloc = game + .descendants() + .whereType() + .where((flipper) => flipper.side == BoardSide.left) + .single + .descendants() + .whereType>() + .first + .bloc; + + gameBloc.emit(gameBloc.state.copyWith(status: GameStatus.gameOver)); + + game.onTapDown(0, tapDownEvent); + await Future.delayed(Duration.zero); + expect(flipperBloc.state, FlipperState.movingDown); + + gameBloc.emit(gameBloc.state.copyWith(status: GameStatus.playing)); + + game.onTapDown(0, tapDownEvent); + await Future.delayed(Duration.zero); + expect(flipperBloc.state, FlipperState.movingUp); + }); + flameTester.test('tap down moves left flipper up', (game) async { await game.ready(); + final gameBloc = game + .descendants() + .whereType>() + .first + .bloc; + + gameBloc.emit(gameBloc.state.copyWith(status: GameStatus.playing)); + final eventPosition = _MockEventPosition(); when(() => eventPosition.game).thenReturn(Vector2.zero()); when(() => eventPosition.widget).thenReturn(Vector2.zero()); @@ -278,6 +330,14 @@ void main() { flameTester.test('tap down moves right flipper up', (game) async { await game.ready(); + final gameBloc = game + .descendants() + .whereType>() + .first + .bloc; + + gameBloc.emit(gameBloc.state.copyWith(status: GameStatus.playing)); + final eventPosition = _MockEventPosition(); when(() => eventPosition.game).thenReturn(Vector2.zero()); when(() => eventPosition.widget).thenReturn(game.canvasSize); @@ -307,6 +367,14 @@ void main() { flameTester.test('tap up moves flipper down', (game) async { await game.ready(); + final gameBloc = game + .descendants() + .whereType>() + .first + .bloc; + + gameBloc.emit(gameBloc.state.copyWith(status: GameStatus.playing)); + final eventPosition = _MockEventPosition(); when(() => eventPosition.game).thenReturn(Vector2.zero()); when(() => eventPosition.widget).thenReturn(Vector2.zero()); @@ -332,6 +400,14 @@ void main() { flameTester.test('tap cancel moves flipper down', (game) async { await game.ready(); + final gameBloc = game + .descendants() + .whereType>() + .first + .bloc; + + gameBloc.emit(gameBloc.state.copyWith(status: GameStatus.playing)); + final eventPosition = _MockEventPosition(); when(() => eventPosition.game).thenReturn(Vector2.zero()); when(() => eventPosition.widget).thenReturn(Vector2.zero()); @@ -363,6 +439,14 @@ void main() { (game) async { await game.ready(); + final gameBloc = game + .descendants() + .whereType>() + .first + .bloc; + + gameBloc.emit(gameBloc.state.copyWith(status: GameStatus.playing)); + final raw = _MockTapDownDetails(); when(() => raw.kind).thenReturn(PointerDeviceKind.touch); @@ -416,6 +500,14 @@ void main() { flameTester.test('plunger control tap down emits plunging', (game) async { await game.ready(); + final gameBloc = game + .descendants() + .whereType>() + .first + .bloc; + + gameBloc.emit(gameBloc.state.copyWith(status: GameStatus.playing)); + final eventPosition = _MockEventPosition(); when(() => eventPosition.game).thenReturn(Vector2(40, 60));