From bceee15a8ed64c32207250deb751413739cbdaf0 Mon Sep 17 00:00:00 2001 From: alestiago Date: Mon, 7 Mar 2022 14:42:36 +0000 Subject: [PATCH] feat: included right and left constructors --- lib/game/components/flipper.dart | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/game/components/flipper.dart b/lib/game/components/flipper.dart index a5a7024b..bea98a15 100644 --- a/lib/game/components/flipper.dart +++ b/lib/game/components/flipper.dart @@ -12,7 +12,7 @@ import 'package:pinball/game/game.dart'; /// {@endtemplate flipper} class Flipper extends BodyComponent { /// {@macro flipper} - Flipper({ + Flipper._({ required Vector2 position, bool isMirrored = false, }) : _position = position, @@ -24,6 +24,22 @@ class Flipper extends BodyComponent { ..style = PaintingStyle.fill; } + /// {@macro flipper} + Flipper.right({ + required Vector2 position, + }) : this._( + position: position, + isMirrored: true, + ); + + /// {@macro flipper} + Flipper.left({ + required Vector2 position, + }) : this._( + position: position, + isMirrored: false, + ); + static final size = Vector2(12, 2.8); /// The total duration of a full flipper's arc motion. @@ -33,7 +49,7 @@ class Flipper extends BodyComponent { static const _sweepingAnimationDuration = Duration(milliseconds: 100); static double _calculateRequiredSpeed() { - // TODO(alestiago): Modify to be mathematically correct. + // TODO(alestiago): test correctness. const angle = FlipperAnchorRevoluteJointDef._sweepingAngle / 2; final sweepingDistance = (size.x * math.sin(angle)) * 2; final seconds = _sweepingAnimationDuration.inMicroseconds /