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

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

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

Loading…
Cancel
Save