diff --git a/lib/game/behaviors/camera_focusing_behavior.dart b/lib/game/behaviors/camera_focusing_behavior.dart index 1d454f02..70d363df 100644 --- a/lib/game/behaviors/camera_focusing_behavior.dart +++ b/lib/game/behaviors/camera_focusing_behavior.dart @@ -1,5 +1,3 @@ -import 'dart:math'; - import 'package:flame/components.dart'; import 'package:flame/game.dart'; import 'package:flame_bloc/flame_bloc.dart'; @@ -30,7 +28,7 @@ class CameraFocusingBehavior extends Component GameStatus? _activeFocus; - final _previousSize = Vector2.zero(); + final Vector2 _previousSize = Vector2.zero(); @override bool listenWhen(GameState? previousState, GameState newState) { @@ -43,30 +41,25 @@ class CameraFocusingBehavior extends Component @override void onGameResize(Vector2 size) { super.onGameResize(size); - if (size == _previousSize) { - return; - } + if (size == _previousSize) return; _previousSize.setFrom(size); - final maxWidth = size.x / 90; - final maxHeight = size.y / 160; - - final scale = min(maxHeight, maxWidth); - - _foci.addAll({ - GameStatus.waiting: _FocusData( - zoom: scale + (maxWidth > maxHeight ? 0.3 : -0.5), - position: Vector2(0, -112), - ), - GameStatus.playing: _FocusData( - zoom: scale + (maxWidth > maxHeight ? 0.5 : -0.2), - position: Vector2(0, -7.8), - ), - GameStatus.gameOver: _FocusData( - zoom: scale + (maxWidth > maxHeight ? 2.8 : 3.3), - position: Vector2(0, -111), - ), - }); + _foci.addAll( + { + GameStatus.waiting: _FocusData( + zoom: size.y / 175, + position: _foci[GameStatus.waiting]?.position ?? Vector2(0, -112), + ), + GameStatus.playing: _FocusData( + zoom: size.y / 165, + position: _foci[GameStatus.playing]?.position ?? Vector2(0, -7.8), + ), + GameStatus.gameOver: _FocusData( + zoom: size.y / 100, + position: _foci[GameStatus.gameOver]?.position ?? Vector2(0, -111), + ), + }, + ); if (_activeFocus != null) { _snap(_activeFocus!); diff --git a/test/game/behaviors/camera_focusing_behavior_test.dart b/test/game/behaviors/camera_focusing_behavior_test.dart index 092f3efe..a856b392 100644 --- a/test/game/behaviors/camera_focusing_behavior_test.dart +++ b/test/game/behaviors/camera_focusing_behavior_test.dart @@ -53,20 +53,6 @@ void main() { }, ); - flameTester.test('sets zoom on resize', (game) async { - final behavior = CameraFocusingBehavior(); - - await game.ensureAdd( - FlameBlocProvider.value( - value: GameBloc(), - children: [behavior], - ), - ); - - game.onGameResize(game.canvasSize * 2); - expect(game.camera.zoom, equals(6.55)); - }); - flameTester.test( 'listenWhen only listens when status changes', (game) async {