feat: group Slingshots (#48)

* feat: removed Wall friction

* feat: included SlingShot

* feat: adjusted SlingShot size

* feat: included tests

* refactor: fixed tests
pull/53/head
Alejandro Santiago 4 years ago committed by GitHub
parent 7a8f808822
commit 1d30278ee4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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]);
}
}

@ -33,18 +33,19 @@ class SlingShot extends BodyComponent {
/// left.
final BoardSide _side;
List<FixtureDef> _createFixtureDefs() {
final fixtures = <FixtureDef>[];
/// The size of the [SlingShot] body.
// TODO(alestiago): Use size from PositionedBodyComponent instead,
// once a sprite is given.
final size = Vector2(10, 10);
static final Vector2 size = Vector2(6, 8);
List<FixtureDef> _createFixtureDefs() {
final fixtures = <FixtureDef>[];
// 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);

@ -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

@ -45,10 +45,10 @@ void main() {
await game.ready();
await game.ensureAdd(bottomGroup);
final leftFlippers = bottomGroup.findNestedChildren<Flipper>(
final rightFlippers = bottomGroup.findNestedChildren<Flipper>(
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<Baseboard>();
expect(leftFlippers.length, equals(2));
final baseboards = bottomGroup.findNestedChildren<Baseboard>();
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<SlingShot>();
expect(slingShots.length, equals(2));
},
);
});

@ -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));
},
);
});

Loading…
Cancel
Save