diff --git a/lib/game/components/board.dart b/lib/game/components/board.dart index 80db1711..674c3e43 100644 --- a/lib/game/components/board.dart +++ b/lib/game/components/board.dart @@ -6,7 +6,6 @@ import 'package:pinball/game/game.dart'; /// /// The bottom [Component]s are the [Flipper]s and the [Baseboard]s. /// {@endtemplate} -// TODO(alestiago): Add [SlingShot] once provided. // TODO(alestiago): Consider renaming once entire Board is defined. class BottomGroup extends Component { /// {@macro bottom_group} @@ -70,7 +69,15 @@ class _BottomGroupSide extends Component { Flipper.height, ), ); + final slingShot = SlingShot( + side: _side, + position: _position + + Vector2( + (Flipper.width) * direction, + Flipper.height + SlingShot.size.y, + ), + ); - await addAll([flipper, baseboard]); + await addAll([flipper, baseboard, slingShot]); } } diff --git a/lib/game/components/sling_shot.dart b/lib/game/components/sling_shot.dart index dacf1ee5..0791cf4f 100644 --- a/lib/game/components/sling_shot.dart +++ b/lib/game/components/sling_shot.dart @@ -33,18 +33,19 @@ class SlingShot extends BodyComponent { /// left. final BoardSide _side; + /// The size of the [SlingShot] body. + // TODO(alestiago): Use size from PositionedBodyComponent instead, + // once a sprite is given. + static final Vector2 size = Vector2(6, 8); + List _createFixtureDefs() { final fixtures = []; - // TODO(alestiago): Use size from PositionedBodyComponent instead, - // once a sprite is given. - final size = Vector2(10, 10); - // TODO(alestiago): This magic number can be deduced by specifying the // angle and using polar coordinate system to place the bottom right // vertex. // Something as: y = -size.y * math.cos(angle) - const additionalIncrement = 2; + const additionalIncrement = 3; final triangleVertices = _side.isLeft ? [ Vector2(0, 0), @@ -78,7 +79,7 @@ class SlingShot extends BodyComponent { ); // TODO(alestiago): Play with restitution value once game is bundled. final kickerFixtureDef = FixtureDef(kicker) - ..restitution = 20.0 + ..restitution = 10.0 ..friction = 0; fixtures.add(kickerFixtureDef); diff --git a/lib/game/components/wall.dart b/lib/game/components/wall.dart index c433365c..017f8c4d 100644 --- a/lib/game/components/wall.dart +++ b/lib/game/components/wall.dart @@ -26,7 +26,7 @@ class Wall extends BodyComponent { final fixtureDef = FixtureDef(shape) ..restitution = 0.1 - ..friction = 0.3; + ..friction = 0; final bodyDef = BodyDef() ..userData = this diff --git a/test/game/components/board_test.dart b/test/game/components/board_test.dart index eaa916c3..34a628a8 100644 --- a/test/game/components/board_test.dart +++ b/test/game/components/board_test.dart @@ -45,10 +45,10 @@ void main() { await game.ready(); await game.ensureAdd(bottomGroup); - final leftFlippers = bottomGroup.findNestedChildren( + final rightFlippers = bottomGroup.findNestedChildren( condition: (flipper) => flipper.side.isRight, ); - expect(leftFlippers.length, equals(1)); + expect(rightFlippers.length, equals(1)); }, ); @@ -59,8 +59,20 @@ void main() { await game.ready(); await game.ensureAdd(bottomGroup); - final leftFlippers = bottomGroup.findNestedChildren(); - expect(leftFlippers.length, equals(2)); + final baseboards = bottomGroup.findNestedChildren(); + expect(baseboards.length, equals(2)); + }, + ); + + flameTester.test( + 'has two SlingShots', + (game) async { + final bottomGroup = BottomGroup(position: Vector2.zero(), spacing: 0); + await game.ready(); + await game.ensureAdd(bottomGroup); + + final slingShots = bottomGroup.findNestedChildren(); + expect(slingShots.length, equals(2)); }, ); }); diff --git a/test/game/components/wall_test.dart b/test/game/components/wall_test.dart index 774cd675..53d387fa 100644 --- a/test/game/components/wall_test.dart +++ b/test/game/components/wall_test.dart @@ -106,7 +106,7 @@ void main() { ); flameTester.test( - 'has friction', + 'has no friction', (game) async { final wall = Wall( start: Vector2.zero(), @@ -115,7 +115,7 @@ void main() { await game.ensureAdd(wall); final fixture = wall.body.fixtures[0]; - expect(fixture.friction, greaterThan(0)); + expect(fixture.friction, equals(0)); }, ); });