refactor: use joint specific anchor

pull/25/head
Allison Ryan 4 years ago
parent 0ec0bf82af
commit 6cbda5bac3

@ -218,7 +218,7 @@ class FlipperAnchorRevoluteJointDef extends RevoluteJointDef {
/// {@macro flipper_anchor_revolute_joint_def}
FlipperAnchorRevoluteJointDef({
required Flipper flipper,
required Anchor anchor,
required FlipperAnchor anchor,
}) {
initialize(
flipper.body,

@ -99,11 +99,8 @@ class PlungerAnchorPrismaticJointDef extends PrismaticJointDef {
/// {@macro plunger_anchor_prismatic_joint_def}
PlungerAnchorPrismaticJointDef({
required Plunger plunger,
required Anchor anchor,
}) : assert(
anchor.body.position.y < plunger.body.position.y,
'Anchor must be below the Plunger',
) {
required PlungerAnchor anchor,
}) {
initialize(
plunger.body,
anchor.body,

@ -37,6 +37,7 @@ class Wall extends BodyComponent {
}
}
/// Create top, left, and right [Wall]s for the game board.
List<Wall> createBoundaries(Forge2DGame game) {
final topLeft = Vector2.zero();
final bottomRight = game.screenToWorld(game.camera.viewport.effectiveSize);

@ -126,7 +126,7 @@ class PinballGame extends Forge2DGame
}
Future<void> _addPlunger() async {
late Anchor plungerAnchor;
late PlungerAnchor plungerAnchor;
await add(
plunger = Plunger(

@ -182,7 +182,6 @@ void main() {
group('PlungerAnchorPrismaticJointDef', () {
late GameBloc gameBloc;
late Plunger plunger;
late Anchor anchor;
setUp(() {
gameBloc = MockGameBloc();
@ -192,7 +191,6 @@ void main() {
initialState: const GameState.initial(),
);
plunger = Plunger(position: Vector2.zero());
anchor = Anchor(position: Vector2(0, -1));
});
final flameTester = flameBlocTester(
@ -201,45 +199,13 @@ void main() {
},
);
flameTester.test(
'throws AssertionError '
'when anchor is above plunger',
(game) async {
final anchor = Anchor(position: Vector2(0, 1));
await game.ensureAddAll([plunger, anchor]);
expect(
() => PlungerAnchorPrismaticJointDef(
plunger: plunger,
anchor: anchor,
),
throwsAssertionError,
);
},
);
flameTester.test(
'throws AssertionError '
'when anchor is in same position as plunger',
(game) async {
final anchor = Anchor(position: Vector2.zero());
await game.ensureAddAll([plunger, anchor]);
expect(
() => PlungerAnchorPrismaticJointDef(
plunger: plunger,
anchor: anchor,
),
throwsAssertionError,
);
},
);
group('initializes with', () {
flameTester.test(
'plunger body as bodyA',
(game) async {
await game.ensureAddAll([plunger, anchor]);
await game.ensureAdd(plunger);
final anchor = PlungerAnchor(plunger: plunger);
await game.ensureAdd(anchor);
final jointDef = PlungerAnchorPrismaticJointDef(
plunger: plunger,
@ -253,7 +219,9 @@ void main() {
flameTester.test(
'anchor body as bodyB',
(game) async {
await game.ensureAddAll([plunger, anchor]);
await game.ensureAdd(plunger);
final anchor = PlungerAnchor(plunger: plunger);
await game.ensureAdd(anchor);
final jointDef = PlungerAnchorPrismaticJointDef(
plunger: plunger,
@ -268,7 +236,9 @@ void main() {
flameTester.test(
'limits enabled',
(game) async {
await game.ensureAddAll([plunger, anchor]);
await game.ensureAdd(plunger);
final anchor = PlungerAnchor(plunger: plunger);
await game.ensureAdd(anchor);
final jointDef = PlungerAnchorPrismaticJointDef(
plunger: plunger,
@ -283,7 +253,9 @@ void main() {
flameTester.test(
'lower translation limit as negative infinity',
(game) async {
await game.ensureAddAll([plunger, anchor]);
await game.ensureAdd(plunger);
final anchor = PlungerAnchor(plunger: plunger);
await game.ensureAdd(anchor);
final jointDef = PlungerAnchorPrismaticJointDef(
plunger: plunger,
@ -298,7 +270,9 @@ void main() {
flameTester.test(
'connected body collison enabled',
(game) async {
await game.ensureAddAll([plunger, anchor]);
await game.ensureAdd(plunger);
final anchor = PlungerAnchor(plunger: plunger);
await game.ensureAdd(anchor);
final jointDef = PlungerAnchorPrismaticJointDef(
plunger: plunger,
@ -315,7 +289,9 @@ void main() {
flameTester.widgetTest(
'plunger cannot go below anchor',
(game, tester) async {
await game.ensureAddAll([plunger, anchor]);
await game.ensureAdd(plunger);
final anchor = PlungerAnchor(plunger: plunger);
await game.ensureAdd(anchor);
// Giving anchor a shape for the plunger to collide with.
anchor.body.createFixtureFromShape(PolygonShape()..setAsBoxXY(2, 1));
@ -337,7 +313,9 @@ void main() {
flameTester.widgetTest(
'plunger cannot excessively exceed starting position',
(game, tester) async {
await game.ensureAddAll([plunger, anchor]);
await game.ensureAdd(plunger);
final anchor = PlungerAnchor(plunger: plunger);
await game.ensureAdd(anchor);
final jointDef = PlungerAnchorPrismaticJointDef(
plunger: plunger,

Loading…
Cancel
Save