diff --git a/lib/game/components/sling_shot.dart b/lib/game/components/sling_shot.dart index b00ce4ca..13154aa0 100644 --- a/lib/game/components/sling_shot.dart +++ b/lib/game/components/sling_shot.dart @@ -42,7 +42,7 @@ class SlingShot extends BodyComponent with InitialPosition { final upperCircle = CircleShape()..radius = 1.45; upperCircle.position.setValues(0, -upperCircle.radius / 2); - final upperCircleFixtureDef = FixtureDef(upperCircle); + final upperCircleFixtureDef = FixtureDef(upperCircle)..friction = 0; fixturesDefs.add(upperCircleFixtureDef); final lowerCircle = CircleShape()..radius = 1.45; @@ -50,7 +50,7 @@ class SlingShot extends BodyComponent with InitialPosition { size.x * -direction, -size.y, ); - final lowerCircleFixtureDef = FixtureDef(lowerCircle); + final lowerCircleFixtureDef = FixtureDef(lowerCircle)..friction = 0; fixturesDefs.add(lowerCircleFixtureDef); final wallFacingEdge = EdgeShape() @@ -63,7 +63,7 @@ class SlingShot extends BodyComponent with InitialPosition { // TODO(alestiago): Use values from design. Vector2(2.0 * direction, -size.y + 2), ); - final wallFacingLineFixtureDef = FixtureDef(wallFacingEdge); + final wallFacingLineFixtureDef = FixtureDef(wallFacingEdge)..friction = 0; fixturesDefs.add(wallFacingLineFixtureDef); final bottomEdge = EdgeShape() @@ -75,7 +75,7 @@ class SlingShot extends BodyComponent with InitialPosition { -lowerCircle.radius * math.sin(quarterPi), ), ); - final bottomLineFixtureDef = FixtureDef(bottomEdge); + final bottomLineFixtureDef = FixtureDef(bottomEdge)..friction = 0; fixturesDefs.add(bottomLineFixtureDef); final kickerEdge = EdgeShape() diff --git a/test/game/components/sling_shot_test.dart b/test/game/components/sling_shot_test.dart index e7c796a1..1567f08d 100644 --- a/test/game/components/sling_shot_test.dart +++ b/test/game/components/sling_shot_test.dart @@ -7,6 +7,7 @@ import 'package:pinball/game/game.dart'; void main() { group('SlingShot', () { + // TODO(alestiago): Include golden tests for left and right. final flameTester = FlameTester(Forge2DGame.new); flameTester.test( @@ -21,135 +22,48 @@ void main() { }, ); - group('body', () { - flameTester.test( - 'is static', - (game) async { - final slingShot = SlingShot( - side: BoardSide.left, - ); - await game.ensureAdd(slingShot); - - expect(slingShot.body.bodyType, equals(BodyType.static)); - }, - ); - }); - - group('first fixture', () { - flameTester.test( - 'exists', - (game) async { - final slingShot = SlingShot( - side: BoardSide.left, - ); - await game.ensureAdd(slingShot); - - expect(slingShot.body.fixtures[0], isA()); - }, - ); - - flameTester.test( - 'shape is triangular', - (game) async { - final slingShot = SlingShot( - side: BoardSide.left, - ); - await game.ensureAdd(slingShot); - - final fixture = slingShot.body.fixtures[0]; - expect(fixture.shape.shapeType, equals(ShapeType.polygon)); - expect((fixture.shape as PolygonShape).vertices.length, equals(3)); - }, - ); - - flameTester.test( - 'triangular shapes are different ' - 'when side is left or right', - (game) async { - final leftSlingShot = SlingShot( - side: BoardSide.left, - ); - final rightSlingShot = SlingShot( - side: BoardSide.right, - ); - - await game.ensureAdd(leftSlingShot); - await game.ensureAdd(rightSlingShot); - - final rightShape = - rightSlingShot.body.fixtures[0].shape as PolygonShape; - final leftShape = - leftSlingShot.body.fixtures[0].shape as PolygonShape; - - expect(rightShape.vertices, isNot(equals(leftShape.vertices))); - }, - ); - - flameTester.test( - 'has no friction', - (game) async { - final slingShot = SlingShot( - side: BoardSide.left, - ); - await game.ensureAdd(slingShot); - - final fixture = slingShot.body.fixtures[0]; - expect(fixture.friction, equals(0)); - }, - ); - }); - - group('second fixture', () { - flameTester.test( - 'exists', - (game) async { - final slingShot = SlingShot( - side: BoardSide.left, - ); - await game.ensureAdd(slingShot); - - expect(slingShot.body.fixtures[1], isA()); - }, - ); - - flameTester.test( - 'shape is edge', - (game) async { - final slingShot = SlingShot( - side: BoardSide.left, - ); - await game.ensureAdd(slingShot); + flameTester.test( + 'bdoy is static', + (game) async { + final slingShot = SlingShot( + side: BoardSide.left, + ); + await game.ensureAdd(slingShot); - final fixture = slingShot.body.fixtures[1]; - expect(fixture.shape.shapeType, equals(ShapeType.edge)); - }, - ); + expect(slingShot.body.bodyType, equals(BodyType.static)); + }, + ); - flameTester.test( - 'has restitution', - (game) async { - final slingShot = SlingShot( - side: BoardSide.left, - ); - await game.ensureAdd(slingShot); + flameTester.test( + 'has restitution', + (game) async { + final slingShot = SlingShot( + side: BoardSide.left, + ); + await game.ensureAdd(slingShot); - final fixture = slingShot.body.fixtures[1]; - expect(fixture.restitution, greaterThan(0)); - }, - ); + final totalRestitution = slingShot.body.fixtures.fold( + 0, + (total, fixture) => total + fixture.restitution, + ); + expect(totalRestitution, greaterThan(0)); + }, + ); - flameTester.test( - 'has no friction', - (game) async { - final slingShot = SlingShot( - side: BoardSide.left, - ); - await game.ensureAdd(slingShot); + flameTester.test( + 'has no friction', + (game) async { + final slingShot = SlingShot( + side: BoardSide.left, + ); + await game.ensureAdd(slingShot); - final fixture = slingShot.body.fixtures[1]; - expect(fixture.friction, equals(0)); - }, - ); - }); + final totalFriction = slingShot.body.fixtures.fold( + 0, + (total, fixture) => total + fixture.friction, + ); + expect(totalFriction, equals(0)); + }, + ); }); }