refactor: PR suggestions

pull/34/head
Allison Ryan 4 years ago
parent 516255f503
commit 62cc23e2df

@ -10,8 +10,9 @@ class Baseboard extends BodyComponent {
/// {@macro baseboard}
Baseboard._({
required Vector2 position,
required this.side,
}) : _position = position;
required BoardSide side,
}) : _position = position,
_side = side;
/// A left positioned [Baseboard].
Baseboard.left({
@ -39,7 +40,7 @@ class Baseboard extends BodyComponent {
final Vector2 _position;
/// Whether the [Baseboard] is on the left or right side of the board.
final BoardSide side;
final BoardSide _side;
List<FixtureDef> _createFixtureDefs() {
final fixtures = <FixtureDef>[];
@ -73,12 +74,14 @@ class Baseboard extends BodyComponent {
@override
Body createBody() {
// TODO(allisonryan0002): share sweeping angle with flipper when components
// are grouped.
const angle = math.pi / 7;
final bodyDef = BodyDef()
..position = _position
..type = BodyType.static
..angle = side.isLeft ? -angle : angle;
..angle = _side.isLeft ? -angle : angle;
final body = world.createBody(bodyDef);
_createFixtureDefs().forEach(body.createFixture);

@ -27,7 +27,7 @@ class PinballGame extends Forge2DGame
await _addGameBoundaries();
unawaited(_addFlippers());
await _addBaseboards();
unawaited(_addBaseboards());
unawaited(_addPlunger());
// Corner wall above plunger so the ball deflects into the rest of the

@ -25,16 +25,6 @@ void main() {
},
);
group('constructor', () {
test('sets BoardSide', () {
final leftBaseboard = Baseboard.left(position: Vector2.zero());
expect(leftBaseboard.side, equals(leftBaseboard.side));
final rightBaseboard = Baseboard.right(position: Vector2.zero());
expect(rightBaseboard.side, equals(rightBaseboard.side));
});
});
group('body', () {
flameTester.test(
'positions correctly',

@ -82,6 +82,15 @@ void main() {
);
});
flameTester.test(
'Baseboards has two Baseboards',
(game) async {
await game.ready();
final baseboards = game.children.whereType<Baseboard>().toList();
expect(baseboards.length, 2);
},
);
flameTester.test(
'Plunger has only one Plunger',
(game) async {

Loading…
Cancel
Save