From 97ded4a3a1733429f0849a56080005cf5a8f88d0 Mon Sep 17 00:00:00 2001 From: Allison Ryan Date: Mon, 25 Apr 2022 12:37:08 -0500 Subject: [PATCH] refactor: fix crazy rendering --- lib/game/pinball_game.dart | 2 +- .../lib/src/components/chrome_dino.dart | 31 +++++++++---------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/game/pinball_game.dart b/lib/game/pinball_game.dart index 603991a7..2bb000c5 100644 --- a/lib/game/pinball_game.dart +++ b/lib/game/pinball_game.dart @@ -58,7 +58,7 @@ class PinballGame extends Forge2DGame await addFromBlueprint(SparkyFireZone()); unawaited(addFromBlueprint(Slingshots())); unawaited(addFromBlueprint(DinoWalls())); - await add(ChromeDino()..initialPosition = Vector2(24.2, -14.1)); + await add(ChromeDino()..initialPosition = Vector2(12.3, -7.1)); unawaited(_addBonusWord()); unawaited(addFromBlueprint(SpaceshipRamp())); unawaited( diff --git a/packages/pinball_components/lib/src/components/chrome_dino.dart b/packages/pinball_components/lib/src/components/chrome_dino.dart index 337cb2df..4b14e673 100644 --- a/packages/pinball_components/lib/src/components/chrome_dino.dart +++ b/packages/pinball_components/lib/src/components/chrome_dino.dart @@ -22,7 +22,8 @@ class ChromeDino extends BodyComponent with InitialPosition { /// Anchors the [ChromeDino] to the [RevoluteJoint] that controls its arc /// motion. Future<_ChromeDinoJoint> _anchorToJoint() async { - final anchor = _ChromeDinoAnchor(); + final anchor = _ChromeDinoAnchor() + ..initialPosition = initialPosition + Vector2(9, -4); await add(anchor); final jointDef = _ChromeDinoAnchorRevoluteJointDef( @@ -46,19 +47,18 @@ class ChromeDino extends BodyComponent with InitialPosition { repeat: true, ), ); - joint._swivel(); } List _createFixtureDefs() { final fixtureDefs = []; - // TODO(allisonryan0002): Update this to match sprite. + // TODO(allisonryan0002): Update this shape to better match sprite. final box = PolygonShape() ..setAsBox( size.x / 2, size.y / 2, initialPosition + Vector2(-4, 2), - -0.1143, + -_ChromeDinoJoint._halfSweepingAngle, ); final fixtureDef = FixtureDef(box, density: 1); fixtureDefs.add(fixtureDef); @@ -81,22 +81,19 @@ class ChromeDino extends BodyComponent with InitialPosition { } } -/// {@template flipper_anchor} +/// {@template chrome_dino_anchor} /// [JointAnchor] positioned at the back of the [ChromeDino]. /// {@endtemplate} class _ChromeDinoAnchor extends JointAnchor { - /// {@macro flipper_anchor} - _ChromeDinoAnchor() { - initialPosition = Vector2(9, -4); - } + /// {@macro chrome_dino_anchor} + _ChromeDinoAnchor(); @override Future onLoad() async { - const spriteAngle = 0.1143; await super.onLoad(); await addAll([ - _ChromeDinoMouthSprite()..angle = spriteAngle, - _ChromeDinoHeadSprite()..angle = spriteAngle, + _ChromeDinoMouthSprite(), + _ChromeDinoHeadSprite(), ]); } } @@ -116,7 +113,7 @@ class _ChromeDinoAnchorRevoluteJointDef extends RevoluteJointDef { chromeDino.body.position + anchor.body.position, ); enableLimit = true; - const angle = 0.1143; + const angle = _ChromeDinoJoint._halfSweepingAngle; lowerAngle = -angle; upperAngle = angle; @@ -130,7 +127,7 @@ class _ChromeDinoJoint extends RevoluteJoint { _ChromeDinoJoint(_ChromeDinoAnchorRevoluteJointDef def) : super(def); /// Half the angle of the arc motion. - // static const _halfSweepingAngle = 0.1143; + static const _halfSweepingAngle = 0.1143; /// Sweeps the [ChromeDino] up and down repeatedly. void _swivel() { @@ -142,6 +139,7 @@ class _ChromeDinoMouthSprite extends SpriteAnimationComponent with HasGameRef { _ChromeDinoMouthSprite() : super( anchor: Anchor(Anchor.center.x + 0.47, Anchor.center.y - 0.29), + angle: _ChromeDinoJoint._halfSweepingAngle, ); @override @@ -165,7 +163,7 @@ class _ChromeDinoMouthSprite extends SpriteAnimationComponent with HasGameRef { stepTime: 1 / 24, textureSize: textureSize, ); - animation = SpriteAnimation.fromFrameData(image, data)..currentIndex = 95; + animation = SpriteAnimation.fromFrameData(image, data)..currentIndex = 45; } } @@ -173,6 +171,7 @@ class _ChromeDinoHeadSprite extends SpriteAnimationComponent with HasGameRef { _ChromeDinoHeadSprite() : super( anchor: Anchor(Anchor.center.x + 0.47, Anchor.center.y - 0.29), + angle: _ChromeDinoJoint._halfSweepingAngle, ); @override @@ -196,6 +195,6 @@ class _ChromeDinoHeadSprite extends SpriteAnimationComponent with HasGameRef { stepTime: 1 / 24, textureSize: textureSize, ); - animation = SpriteAnimation.fromFrameData(image, data)..currentIndex = 95; + animation = SpriteAnimation.fromFrameData(image, data)..currentIndex = 45; } }