diff --git a/packages/pinball_components/lib/src/components/ball.dart b/packages/pinball_components/lib/src/components/ball.dart index f6078cf7..0f537e2b 100644 --- a/packages/pinball_components/lib/src/components/ball.dart +++ b/packages/pinball_components/lib/src/components/ball.dart @@ -104,10 +104,10 @@ class Ball extends BodyComponent const maxShrinkAmount = BoardDimensions.perspectiveShrinkFactor; final adjustedYPosition = body.position.y + (boardHeight / 2); - final adjustedHeight = (1 / (1 - maxShrinkAmount)) * boardHeight; - final scaleFactor = - ((boardHeight - adjustedYPosition) / adjustedHeight) + maxShrinkAmount; + final scaleFactor = ((boardHeight - adjustedYPosition) / + BoardDimensions.shrinkAdjustedHeight) + + maxShrinkAmount; body.fixtures.first.shape.radius = (size.x / 2) * scaleFactor; _spriteComponent.scale = Vector2.all(scaleFactor); diff --git a/packages/pinball_components/lib/src/components/board_dimensions.dart b/packages/pinball_components/lib/src/components/board_dimensions.dart index 34f00091..4911adc6 100644 --- a/packages/pinball_components/lib/src/components/board_dimensions.dart +++ b/packages/pinball_components/lib/src/components/board_dimensions.dart @@ -21,4 +21,8 @@ class BoardDimensions { /// Factor the board shrinks by from the closest point to the farthest. static const perspectiveShrinkFactor = 0.63; + + /// Board height based on the [perspectiveShrinkFactor]. + static final shrinkAdjustedHeight = + (1 / (1 - perspectiveShrinkFactor)) * size.y; } diff --git a/packages/pinball_components/test/src/components/board_dimensions_test.dart b/packages/pinball_components/test/src/components/board_dimensions_test.dart index 2529cac1..afd4a2d8 100644 --- a/packages/pinball_components/test/src/components/board_dimensions_test.dart +++ b/packages/pinball_components/test/src/components/board_dimensions_test.dart @@ -19,5 +19,9 @@ void main() { test('has perspectiveShrinkFactor', () { expect(BoardDimensions.perspectiveShrinkFactor, equals(0.63)); }); + + test('has shrinkAdjustedHeight', () { + expect(BoardDimensions.shrinkAdjustedHeight, isNotNull); + }); }); }