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

@ -27,7 +27,7 @@ class PinballGame extends Forge2DGame
await _addGameBoundaries(); await _addGameBoundaries();
unawaited(_addFlippers()); unawaited(_addFlippers());
await _addBaseboards(); unawaited(_addBaseboards());
unawaited(_addPlunger()); unawaited(_addPlunger());
// Corner wall above plunger so the ball deflects into the rest of the // 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', () { group('body', () {
flameTester.test( flameTester.test(
'positions correctly', '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( flameTester.test(
'Plunger has only one Plunger', 'Plunger has only one Plunger',
(game) async { (game) async {

Loading…
Cancel
Save