refactor: fix crazy rendering

pull/229/head
Allison Ryan 3 years ago
parent 1fa393c262
commit 97ded4a3a1

@ -58,7 +58,7 @@ class PinballGame extends Forge2DGame
await addFromBlueprint(SparkyFireZone()); await addFromBlueprint(SparkyFireZone());
unawaited(addFromBlueprint(Slingshots())); unawaited(addFromBlueprint(Slingshots()));
unawaited(addFromBlueprint(DinoWalls())); unawaited(addFromBlueprint(DinoWalls()));
await add(ChromeDino()..initialPosition = Vector2(24.2, -14.1)); await add(ChromeDino()..initialPosition = Vector2(12.3, -7.1));
unawaited(_addBonusWord()); unawaited(_addBonusWord());
unawaited(addFromBlueprint(SpaceshipRamp())); unawaited(addFromBlueprint(SpaceshipRamp()));
unawaited( unawaited(

@ -22,7 +22,8 @@ class ChromeDino extends BodyComponent with InitialPosition {
/// Anchors the [ChromeDino] to the [RevoluteJoint] that controls its arc /// Anchors the [ChromeDino] to the [RevoluteJoint] that controls its arc
/// motion. /// motion.
Future<_ChromeDinoJoint> _anchorToJoint() async { Future<_ChromeDinoJoint> _anchorToJoint() async {
final anchor = _ChromeDinoAnchor(); final anchor = _ChromeDinoAnchor()
..initialPosition = initialPosition + Vector2(9, -4);
await add(anchor); await add(anchor);
final jointDef = _ChromeDinoAnchorRevoluteJointDef( final jointDef = _ChromeDinoAnchorRevoluteJointDef(
@ -46,19 +47,18 @@ class ChromeDino extends BodyComponent with InitialPosition {
repeat: true, repeat: true,
), ),
); );
joint._swivel();
} }
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final fixtureDefs = <FixtureDef>[]; final fixtureDefs = <FixtureDef>[];
// TODO(allisonryan0002): Update this to match sprite. // TODO(allisonryan0002): Update this shape to better match sprite.
final box = PolygonShape() final box = PolygonShape()
..setAsBox( ..setAsBox(
size.x / 2, size.x / 2,
size.y / 2, size.y / 2,
initialPosition + Vector2(-4, 2), initialPosition + Vector2(-4, 2),
-0.1143, -_ChromeDinoJoint._halfSweepingAngle,
); );
final fixtureDef = FixtureDef(box, density: 1); final fixtureDef = FixtureDef(box, density: 1);
fixtureDefs.add(fixtureDef); 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]. /// [JointAnchor] positioned at the back of the [ChromeDino].
/// {@endtemplate} /// {@endtemplate}
class _ChromeDinoAnchor extends JointAnchor { class _ChromeDinoAnchor extends JointAnchor {
/// {@macro flipper_anchor} /// {@macro chrome_dino_anchor}
_ChromeDinoAnchor() { _ChromeDinoAnchor();
initialPosition = Vector2(9, -4);
}
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
const spriteAngle = 0.1143;
await super.onLoad(); await super.onLoad();
await addAll([ await addAll([
_ChromeDinoMouthSprite()..angle = spriteAngle, _ChromeDinoMouthSprite(),
_ChromeDinoHeadSprite()..angle = spriteAngle, _ChromeDinoHeadSprite(),
]); ]);
} }
} }
@ -116,7 +113,7 @@ class _ChromeDinoAnchorRevoluteJointDef extends RevoluteJointDef {
chromeDino.body.position + anchor.body.position, chromeDino.body.position + anchor.body.position,
); );
enableLimit = true; enableLimit = true;
const angle = 0.1143; const angle = _ChromeDinoJoint._halfSweepingAngle;
lowerAngle = -angle; lowerAngle = -angle;
upperAngle = angle; upperAngle = angle;
@ -130,7 +127,7 @@ class _ChromeDinoJoint extends RevoluteJoint {
_ChromeDinoJoint(_ChromeDinoAnchorRevoluteJointDef def) : super(def); _ChromeDinoJoint(_ChromeDinoAnchorRevoluteJointDef def) : super(def);
/// Half the angle of the arc motion. /// Half the angle of the arc motion.
// static const _halfSweepingAngle = 0.1143; static const _halfSweepingAngle = 0.1143;
/// Sweeps the [ChromeDino] up and down repeatedly. /// Sweeps the [ChromeDino] up and down repeatedly.
void _swivel() { void _swivel() {
@ -142,6 +139,7 @@ class _ChromeDinoMouthSprite extends SpriteAnimationComponent with HasGameRef {
_ChromeDinoMouthSprite() _ChromeDinoMouthSprite()
: super( : super(
anchor: Anchor(Anchor.center.x + 0.47, Anchor.center.y - 0.29), anchor: Anchor(Anchor.center.x + 0.47, Anchor.center.y - 0.29),
angle: _ChromeDinoJoint._halfSweepingAngle,
); );
@override @override
@ -165,7 +163,7 @@ class _ChromeDinoMouthSprite extends SpriteAnimationComponent with HasGameRef {
stepTime: 1 / 24, stepTime: 1 / 24,
textureSize: textureSize, 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() _ChromeDinoHeadSprite()
: super( : super(
anchor: Anchor(Anchor.center.x + 0.47, Anchor.center.y - 0.29), anchor: Anchor(Anchor.center.x + 0.47, Anchor.center.y - 0.29),
angle: _ChromeDinoJoint._halfSweepingAngle,
); );
@override @override
@ -196,6 +195,6 @@ class _ChromeDinoHeadSprite extends SpriteAnimationComponent with HasGameRef {
stepTime: 1 / 24, stepTime: 1 / 24,
textureSize: textureSize, textureSize: textureSize,
); );
animation = SpriteAnimation.fromFrameData(image, data)..currentIndex = 95; animation = SpriteAnimation.fromFrameData(image, data)..currentIndex = 45;
} }
} }

Loading…
Cancel
Save