From de2b73247ab3677069159157e18db3baaf6641b9 Mon Sep 17 00:00:00 2001 From: alestiago Date: Wed, 16 Mar 2022 12:39:45 +0000 Subject: [PATCH] feat: made RoundBumper use InitialPosition --- lib/game/components/round_bumper.dart | 11 +++-------- test/game/components/round_bumper_test.dart | 21 +++++++-------------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/lib/game/components/round_bumper.dart b/lib/game/components/round_bumper.dart index 753ed15b..eb3715ec 100644 --- a/lib/game/components/round_bumper.dart +++ b/lib/game/components/round_bumper.dart @@ -4,19 +4,14 @@ import 'package:pinball/game/game.dart'; /// {@template round_bumper} /// Circular body that repels a [Ball] on contact, increasing the score. /// {@endtemplate} -class RoundBumper extends BodyComponent with ScorePoints { +class RoundBumper extends BodyComponent with ScorePoints, InitialPosition { /// {@macro round_bumper} RoundBumper({ - required Vector2 position, required double radius, required int points, - }) : _position = position, - _radius = radius, + }) : _radius = radius, _points = points; - /// The position of the [RoundBumper] body. - final Vector2 _position; - /// The radius of the [RoundBumper]. final double _radius; @@ -33,7 +28,7 @@ class RoundBumper extends BodyComponent with ScorePoints { final fixtureDef = FixtureDef(shape)..restitution = 1; final bodyDef = BodyDef() - ..position = _position + ..position = initialPosition ..type = BodyType.static; return world.createBody(bodyDef)..createFixture(fixtureDef); diff --git a/test/game/components/round_bumper_test.dart b/test/game/components/round_bumper_test.dart index c780dd0b..ac2d56b7 100644 --- a/test/game/components/round_bumper_test.dart +++ b/test/game/components/round_bumper_test.dart @@ -18,10 +18,9 @@ void main() { (game) async { await game.ready(); final roundBumper = RoundBumper( - position: Vector2.zero(), radius: radius, points: points, - ); + )..initialPosition = Vector2.zero(); await game.ensureAdd(roundBumper); expect(game.contains(roundBumper), isTrue); @@ -32,10 +31,9 @@ void main() { 'has points', (game) async { final roundBumper = RoundBumper( - position: Vector2.zero(), radius: radius, points: points, - ); + )..initialPosition = Vector2.zero(); await game.ensureAdd(roundBumper); expect(roundBumper.points, equals(points)); @@ -48,10 +46,9 @@ void main() { (game) async { final position = Vector2.all(10); final roundBumper = RoundBumper( - position: position, radius: radius, points: points, - ); + )..initialPosition = position; await game.ensureAdd(roundBumper); game.contains(roundBumper); @@ -63,10 +60,9 @@ void main() { 'is static', (game) async { final roundBumper = RoundBumper( - position: Vector2.zero(), radius: radius, points: points, - ); + )..initialPosition = Vector2.zero(); await game.ensureAdd(roundBumper); expect(roundBumper.body.bodyType, equals(BodyType.static)); @@ -79,10 +75,9 @@ void main() { 'exists', (game) async { final roundBumper = RoundBumper( - position: Vector2.zero(), radius: radius, points: points, - ); + )..initialPosition = Vector2.zero(); await game.ensureAdd(roundBumper); expect(roundBumper.body.fixtures[0], isA()); @@ -93,10 +88,9 @@ void main() { 'has restitution', (game) async { final roundBumper = RoundBumper( - position: Vector2.zero(), radius: radius, points: points, - ); + )..initialPosition = Vector2.zero(); await game.ensureAdd(roundBumper); final fixture = roundBumper.body.fixtures[0]; @@ -108,10 +102,9 @@ void main() { 'shape is circular', (game) async { final roundBumper = RoundBumper( - position: Vector2.zero(), radius: radius, points: points, - ); + )..initialPosition = Vector2.zero(); await game.ensureAdd(roundBumper); final fixture = roundBumper.body.fixtures[0];