From 9ffcb5c91bb1a2e993130b866da35c692555756e Mon Sep 17 00:00:00 2001 From: alestiago Date: Wed, 16 Mar 2022 13:03:00 +0000 Subject: [PATCH] feat: made BonusWord use InitialPosition --- lib/game/components/bonus_word.dart | 12 ++++-------- test/game/components/bonus_word_test.dart | 18 ++++++------------ 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/lib/game/components/bonus_word.dart b/lib/game/components/bonus_word.dart index 49a1da1d..378240b5 100644 --- a/lib/game/components/bonus_word.dart +++ b/lib/game/components/bonus_word.dart @@ -74,10 +74,9 @@ class BonusWord extends Component with BlocComponent { unawaited( add( BonusLetter( - position: _position - Vector2(16 - (i * 6), -30), letter: letters[i], index: i, - ), + )..initialPosition = _position - Vector2(16 - (i * 6), -30), ), ); } @@ -89,14 +88,12 @@ class BonusWord extends Component with BlocComponent { /// which will activate its letter after contact with a [Ball]. /// {@endtemplate} class BonusLetter extends BodyComponent - with BlocComponent { + with BlocComponent, InitialPosition { /// {@macro bonus_letter} BonusLetter({ - required Vector2 position, required String letter, required int index, - }) : _position = position, - _letter = letter, + }) : _letter = letter, _index = index { paint = Paint()..color = _disableColor; } @@ -107,7 +104,6 @@ class BonusLetter extends BodyComponent static const _activeColor = Colors.green; static const _disableColor = Colors.red; - final Vector2 _position; final String _letter; final int _index; @@ -134,7 +130,7 @@ class BonusLetter extends BodyComponent final bodyDef = BodyDef() ..userData = this - ..position = _position + ..position = initialPosition ..type = BodyType.static; return world.createBody(bodyDef)..createFixture(fixtureDef); diff --git a/test/game/components/bonus_word_test.dart b/test/game/components/bonus_word_test.dart index b45bd61a..6f8cd015 100644 --- a/test/game/components/bonus_word_test.dart +++ b/test/game/components/bonus_word_test.dart @@ -123,10 +123,9 @@ void main() { 'loads correctly', (game) async { final bonusLetter = BonusLetter( - position: Vector2.zero(), letter: 'G', index: 0, - ); + )..initialPosition = Vector2.zero(); await game.ensureAdd(bonusLetter); await game.ready(); @@ -140,10 +139,9 @@ void main() { (game) async { final position = Vector2.all(10); final bonusLetter = BonusLetter( - position: position, letter: 'G', index: 0, - ); + )..initialPosition = position; await game.ensureAdd(bonusLetter); game.contains(bonusLetter); @@ -155,10 +153,9 @@ void main() { 'is static', (game) async { final bonusLetter = BonusLetter( - position: Vector2.zero(), letter: 'G', index: 0, - ); + )..initialPosition = Vector2.zero(); await game.ensureAdd(bonusLetter); expect(bonusLetter.body.bodyType, equals(BodyType.static)); @@ -171,10 +168,9 @@ void main() { 'exists', (game) async { final bonusLetter = BonusLetter( - position: Vector2.zero(), letter: 'G', index: 0, - ); + )..initialPosition = Vector2.zero(); await game.ensureAdd(bonusLetter); expect(bonusLetter.body.fixtures[0], isA()); @@ -185,10 +181,9 @@ void main() { 'is sensor', (game) async { final bonusLetter = BonusLetter( - position: Vector2.zero(), letter: 'G', index: 0, - ); + )..initialPosition = Vector2.zero(); await game.ensureAdd(bonusLetter); final fixture = bonusLetter.body.fixtures[0]; @@ -200,10 +195,9 @@ void main() { 'shape is circular', (game) async { final bonusLetter = BonusLetter( - position: Vector2.zero(), letter: 'G', index: 0, - ); + )..initialPosition = Vector2.zero(); await game.ensureAdd(bonusLetter); final fixture = bonusLetter.body.fixtures[0];