diff --git a/lib/game/components/board.dart b/lib/game/components/board.dart index f7b80bd8..6107048e 100644 --- a/lib/game/components/board.dart +++ b/lib/game/components/board.dart @@ -94,7 +94,7 @@ class _BottomGroup extends Component { @override Future onLoad() async { - final spacing = this.spacing + Flipper.width / 2; + final spacing = this.spacing + Flipper.size.x / 2; final rightSide = _BottomGroupSide( side: BoardSide.right, position: position + Vector2(spacing, 0), @@ -135,15 +135,15 @@ class _BottomGroupSide extends Component { final baseboard = Baseboard(side: _side) ..initialPosition = _position + Vector2( - (Flipper.width * direction) - direction, - Flipper.height, + (Flipper.size.x * direction) - direction, + Flipper.size.y, ); final slingShot = SlingShot( side: _side, )..initialPosition = _position + Vector2( - (Flipper.width) * direction, - Flipper.height + SlingShot.size.y, + (Flipper.size.x) * direction, + Flipper.size.y + SlingShot.size.y, ); await addAll([flipper, baseboard, slingShot]); diff --git a/lib/game/components/flipper.dart b/lib/game/components/flipper.dart index 77238acd..c4f18389 100644 --- a/lib/game/components/flipper.dart +++ b/lib/game/components/flipper.dart @@ -58,11 +58,8 @@ class Flipper extends BodyComponent with KeyboardHandler, InitialPosition { /// Sprite is preloaded by [PinballGameAssetsX]. static const spritePath = 'components/flipper.png'; - /// The width of the [Flipper]. - static const width = 12.0; - - /// The height of the [Flipper]. - static const height = 2.8; + /// The size of the [Flipper]. + static final size = Vector2(12, 2.8); /// The speed required to move the [Flipper] to its highest position. /// @@ -97,7 +94,7 @@ class Flipper extends BodyComponent with KeyboardHandler, InitialPosition { final sprite = await gameRef.loadSprite(spritePath); final spriteComponent = SpriteComponent( sprite: sprite, - size: Vector2(width, height), + size: size, anchor: Anchor.center, ); @@ -134,21 +131,21 @@ class Flipper extends BodyComponent with KeyboardHandler, InitialPosition { final fixturesDef = []; final isLeft = side.isLeft; - final bigCircleShape = CircleShape()..radius = height / 2; + final bigCircleShape = CircleShape()..radius = 1.75; bigCircleShape.position.setValues( isLeft - ? -(width / 2) + bigCircleShape.radius - : (width / 2) - bigCircleShape.radius, + ? -(size.x / 2) + bigCircleShape.radius + : (size.x / 2) - bigCircleShape.radius, 0, ); final bigCircleFixtureDef = FixtureDef(bigCircleShape); fixturesDef.add(bigCircleFixtureDef); - final smallCircleShape = CircleShape()..radius = bigCircleShape.radius / 2; + final smallCircleShape = CircleShape()..radius = 0.9; smallCircleShape.position.setValues( isLeft - ? (width / 2) - smallCircleShape.radius - : -(width / 2) + smallCircleShape.radius, + ? (size.x / 2) - smallCircleShape.radius + : -(size.x / 2) + smallCircleShape.radius, 0, ); final smallCircleFixtureDef = FixtureDef(smallCircleShape); @@ -227,8 +224,8 @@ class FlipperAnchor extends JointAnchor { }) { initialPosition = Vector2( flipper.side.isLeft - ? flipper.body.position.x - Flipper.width / 2 - : flipper.body.position.x + Flipper.width / 2, + ? flipper.body.position.x - Flipper.size.x / 2 + : flipper.body.position.x + Flipper.size.x / 2, flipper.body.position.y, ); } diff --git a/test/game/components/flipper_test.dart b/test/game/components/flipper_test.dart index e6e9ba23..64d2f77b 100644 --- a/test/game/components/flipper_test.dart +++ b/test/game/components/flipper_test.dart @@ -282,7 +282,7 @@ void main() { final flipperAnchor = FlipperAnchor(flipper: flipper); await game.ensureAdd(flipperAnchor); - expect(flipperAnchor.body.position.x, equals(-Flipper.width / 2)); + expect(flipperAnchor.body.position.x, equals(-Flipper.size.x / 2)); }, ); @@ -297,7 +297,7 @@ void main() { final flipperAnchor = FlipperAnchor(flipper: flipper); await game.ensureAdd(flipperAnchor); - expect(flipperAnchor.body.position.x, equals(Flipper.width / 2)); + expect(flipperAnchor.body.position.x, equals(Flipper.size.x / 2)); }, ); });