refactor: position and dimension google letters (#93)

* refactor: relative positions

* chore: remove unused code

* test: fix failing tests

* refactor: position logic

* refactor: position logic

* chore: clean up bonus word

* refactor: use relative positions

* refactor: await adding letters

* refactor: remove local variable

* chore: remove empty line

Co-authored-by: Alejandro Santiago <dev@alestiago.com>
pull/100/head
Allison Ryan 4 years ago committed by GitHub
parent 1f0a0c2f04
commit db29e5c7b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -73,18 +73,32 @@ class BonusWord extends Component with BlocComponent<GameBloc, GameState> {
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
final letters = GameBloc.bonusWord.split('');
final offsets = [
for (var i = 0; i < letters.length; i++) { Vector2(-12.92, -1.82),
unawaited( Vector2(-8.33, 0.65),
add( Vector2(-2.88, 1.75),
BonusLetter( ];
letter: letters[i], offsets.addAll(
index: i, offsets.reversed
)..initialPosition = _position - Vector2(16 - (i * 6), -30), .map(
), (offset) => Vector2(-offset.x, offset.y),
)
.toList(),
);
assert(offsets.length == GameBloc.bonusWord.length, 'Invalid positions');
final letters = <BonusLetter>[];
for (var i = 0; i < GameBloc.bonusWord.length; i++) {
letters.add(
BonusLetter(
letter: GameBloc.bonusWord[i],
index: i,
)..initialPosition = _position + offsets[i],
); );
} }
await addAll(letters);
} }
} }
@ -103,8 +117,8 @@ class BonusLetter extends BodyComponent<PinballGame>
paint = Paint()..color = _disableColor; paint = Paint()..color = _disableColor;
} }
/// The area size of this [BonusLetter]. /// The size of the [BonusLetter].
static final areaSize = Vector2.all(4); static final size = Vector2.all(3.7);
static const _activeColor = Colors.green; static const _activeColor = Colors.green;
static const _disableColor = Colors.red; static const _disableColor = Colors.red;
@ -136,7 +150,7 @@ class BonusLetter extends BodyComponent<PinballGame>
@override @override
Body createBody() { Body createBody() {
final shape = CircleShape()..radius = areaSize.x / 2; final shape = CircleShape()..radius = size.x / 2;
final fixtureDef = FixtureDef(shape)..isSensor = true; final fixtureDef = FixtureDef(shape)..isSensor = true;

@ -74,8 +74,8 @@ class PinballGame extends Forge2DGame
await add( await add(
BonusWord( BonusWord(
position: Vector2( position: Vector2(
boardBounds.center.dx, boardBounds.center.dx - 3.07,
boardBounds.bottom + 10, boardBounds.center.dy - 2.4,
), ),
), ),
); );

@ -187,7 +187,7 @@ void main() {
final fixture = bonusLetter.body.fixtures[0]; final fixture = bonusLetter.body.fixtures[0];
expect(fixture.shape.shapeType, equals(ShapeType.circle)); expect(fixture.shape.shapeType, equals(ShapeType.circle));
expect(fixture.shape.radius, equals(2)); expect(fixture.shape.radius, equals(1.85));
}, },
); );
}); });

Loading…
Cancel
Save