refactor: store adjusted height

pull/113/head
Allison Ryan 4 years ago
parent c5df602b71
commit e90e26608d

@ -104,10 +104,10 @@ class Ball<T extends Forge2DGame> extends BodyComponent<T>
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);

@ -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;
}

@ -19,5 +19,9 @@ void main() {
test('has perspectiveShrinkFactor', () {
expect(BoardDimensions.perspectiveShrinkFactor, equals(0.63));
});
test('has shrinkAdjustedHeight', () {
expect(BoardDimensions.shrinkAdjustedHeight, isNotNull);
});
});
}

Loading…
Cancel
Save