From 1e7088175110cf8dbfcd644485c230d731405908 Mon Sep 17 00:00:00 2001 From: Alejandro Santiago Date: Sat, 7 May 2022 21:08:29 +0100 Subject: [PATCH] fix: made Flippers start from bottom position (#392) --- .../components/game_bloc_status_listener.dart | 7 ++- .../behaviors/flipper_jointing_behavior.dart | 51 ++----------------- 2 files changed, 10 insertions(+), 48 deletions(-) diff --git a/lib/game/components/game_bloc_status_listener.dart b/lib/game/components/game_bloc_status_listener.dart index 84627eb0..cf2f75b3 100644 --- a/lib/game/components/game_bloc_status_listener.dart +++ b/lib/game/components/game_bloc_status_listener.dart @@ -45,8 +45,11 @@ class GameBlocStatusListener extends Component } } - void _addFlipperKeyControls(Flipper flipper) => - flipper.add(FlipperKeyControllingBehavior()); + void _addFlipperKeyControls(Flipper flipper) { + flipper + ..add(FlipperKeyControllingBehavior()) + ..moveDown(); + } void _removeFlipperKeyControls(Flipper flipper) => flipper .descendants() diff --git a/packages/pinball_components/lib/src/components/flipper/behaviors/flipper_jointing_behavior.dart b/packages/pinball_components/lib/src/components/flipper/behaviors/flipper_jointing_behavior.dart index c0574f6c..eb29c181 100644 --- a/packages/pinball_components/lib/src/components/flipper/behaviors/flipper_jointing_behavior.dart +++ b/packages/pinball_components/lib/src/components/flipper/behaviors/flipper_jointing_behavior.dart @@ -6,8 +6,6 @@ import 'package:pinball_flame/pinball_flame.dart'; /// Joints the [Flipper] to allow pivoting around one end. class FlipperJointingBehavior extends Component with ParentIsA, HasGameRef { - late final RevoluteJoint _joint; - @override Future onLoad() async { await super.onLoad(); @@ -19,15 +17,7 @@ class FlipperJointingBehavior extends Component flipper: parent, anchor: anchor, ); - _joint = _FlipperJoint(jointDef); - parent.world.createJoint(_joint); - } - - @override - void onMount() { - gameRef.ready().whenComplete( - () => parent.body.joints.whereType<_FlipperJoint>().first.unlock(), - ); + parent.world.createJoint(RevoluteJoint(jointDef)); } } @@ -58,46 +48,15 @@ class _FlipperAnchorRevoluteJointDef extends RevoluteJointDef { _FlipperAnchorRevoluteJointDef({ required Flipper flipper, required _FlipperAnchor anchor, - }) : side = flipper.side { - enableLimit = true; + }) { initialize( flipper.body, anchor.body, flipper.body.position + anchor.body.position, ); - } - - final BoardSide side; -} -/// {@template flipper_joint} -/// [RevoluteJoint] that controls the pivoting motion of a [Flipper]. -/// {@endtemplate} -class _FlipperJoint extends RevoluteJoint { - /// {@macro flipper_joint} - _FlipperJoint(_FlipperAnchorRevoluteJointDef def) - : side = def.side, - super(def) { - lock(); - } - - /// Half the angle of the arc motion. - static const _halfSweepingAngle = 0.611; - - final BoardSide side; - - /// Locks the [Flipper] to its resting position. - /// - /// The joint is locked when initialized in order to force the [Flipper] - /// at its resting position. - void lock() { - final angle = _halfSweepingAngle * side.direction; - setLimits(angle, angle); - } - - /// Unlocks the [Flipper] from its resting position. - void unlock() { - const angle = _halfSweepingAngle; - setLimits(-angle, angle); + enableLimit = true; + upperAngle = 0.611; + lowerAngle = -upperAngle; } }