feat: made RoundBumper use InitialPosition

pull/50/head
alestiago 4 years ago
parent b3a05cb054
commit de2b73247a

@ -4,19 +4,14 @@ import 'package:pinball/game/game.dart';
/// {@template round_bumper} /// {@template round_bumper}
/// Circular body that repels a [Ball] on contact, increasing the score. /// Circular body that repels a [Ball] on contact, increasing the score.
/// {@endtemplate} /// {@endtemplate}
class RoundBumper extends BodyComponent with ScorePoints { class RoundBumper extends BodyComponent with ScorePoints, InitialPosition {
/// {@macro round_bumper} /// {@macro round_bumper}
RoundBumper({ RoundBumper({
required Vector2 position,
required double radius, required double radius,
required int points, required int points,
}) : _position = position, }) : _radius = radius,
_radius = radius,
_points = points; _points = points;
/// The position of the [RoundBumper] body.
final Vector2 _position;
/// The radius of the [RoundBumper]. /// The radius of the [RoundBumper].
final double _radius; final double _radius;
@ -33,7 +28,7 @@ class RoundBumper extends BodyComponent with ScorePoints {
final fixtureDef = FixtureDef(shape)..restitution = 1; final fixtureDef = FixtureDef(shape)..restitution = 1;
final bodyDef = BodyDef() final bodyDef = BodyDef()
..position = _position ..position = initialPosition
..type = BodyType.static; ..type = BodyType.static;
return world.createBody(bodyDef)..createFixture(fixtureDef); return world.createBody(bodyDef)..createFixture(fixtureDef);

@ -18,10 +18,9 @@ void main() {
(game) async { (game) async {
await game.ready(); await game.ready();
final roundBumper = RoundBumper( final roundBumper = RoundBumper(
position: Vector2.zero(),
radius: radius, radius: radius,
points: points, points: points,
); )..initialPosition = Vector2.zero();
await game.ensureAdd(roundBumper); await game.ensureAdd(roundBumper);
expect(game.contains(roundBumper), isTrue); expect(game.contains(roundBumper), isTrue);
@ -32,10 +31,9 @@ void main() {
'has points', 'has points',
(game) async { (game) async {
final roundBumper = RoundBumper( final roundBumper = RoundBumper(
position: Vector2.zero(),
radius: radius, radius: radius,
points: points, points: points,
); )..initialPosition = Vector2.zero();
await game.ensureAdd(roundBumper); await game.ensureAdd(roundBumper);
expect(roundBumper.points, equals(points)); expect(roundBumper.points, equals(points));
@ -48,10 +46,9 @@ void main() {
(game) async { (game) async {
final position = Vector2.all(10); final position = Vector2.all(10);
final roundBumper = RoundBumper( final roundBumper = RoundBumper(
position: position,
radius: radius, radius: radius,
points: points, points: points,
); )..initialPosition = position;
await game.ensureAdd(roundBumper); await game.ensureAdd(roundBumper);
game.contains(roundBumper); game.contains(roundBumper);
@ -63,10 +60,9 @@ void main() {
'is static', 'is static',
(game) async { (game) async {
final roundBumper = RoundBumper( final roundBumper = RoundBumper(
position: Vector2.zero(),
radius: radius, radius: radius,
points: points, points: points,
); )..initialPosition = Vector2.zero();
await game.ensureAdd(roundBumper); await game.ensureAdd(roundBumper);
expect(roundBumper.body.bodyType, equals(BodyType.static)); expect(roundBumper.body.bodyType, equals(BodyType.static));
@ -79,10 +75,9 @@ void main() {
'exists', 'exists',
(game) async { (game) async {
final roundBumper = RoundBumper( final roundBumper = RoundBumper(
position: Vector2.zero(),
radius: radius, radius: radius,
points: points, points: points,
); )..initialPosition = Vector2.zero();
await game.ensureAdd(roundBumper); await game.ensureAdd(roundBumper);
expect(roundBumper.body.fixtures[0], isA<Fixture>()); expect(roundBumper.body.fixtures[0], isA<Fixture>());
@ -93,10 +88,9 @@ void main() {
'has restitution', 'has restitution',
(game) async { (game) async {
final roundBumper = RoundBumper( final roundBumper = RoundBumper(
position: Vector2.zero(),
radius: radius, radius: radius,
points: points, points: points,
); )..initialPosition = Vector2.zero();
await game.ensureAdd(roundBumper); await game.ensureAdd(roundBumper);
final fixture = roundBumper.body.fixtures[0]; final fixture = roundBumper.body.fixtures[0];
@ -108,10 +102,9 @@ void main() {
'shape is circular', 'shape is circular',
(game) async { (game) async {
final roundBumper = RoundBumper( final roundBumper = RoundBumper(
position: Vector2.zero(),
radius: radius, radius: radius,
points: points, points: points,
); )..initialPosition = Vector2.zero();
await game.ensureAdd(roundBumper); await game.ensureAdd(roundBumper);
final fixture = roundBumper.body.fixtures[0]; final fixture = roundBumper.body.fixtures[0];

Loading…
Cancel
Save