refactor: used size instead of width and height (#69)

pull/71/head
Alejandro Santiago 2 years ago committed by GitHub
parent aa1a2d7674
commit 5b355ff406
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -94,7 +94,7 @@ class _BottomGroup extends Component {
@override
Future<void> onLoad() async {
final spacing = this.spacing + Flipper.width / 2;
final spacing = this.spacing + Flipper.size.x / 2;
final rightSide = _BottomGroupSide(
side: BoardSide.right,
position: position + Vector2(spacing, 0),
@ -135,15 +135,15 @@ class _BottomGroupSide extends Component {
final baseboard = Baseboard(side: _side)
..initialPosition = _position +
Vector2(
(Flipper.width * direction) - direction,
Flipper.height,
(Flipper.size.x * direction) - direction,
Flipper.size.y,
);
final slingShot = SlingShot(
side: _side,
)..initialPosition = _position +
Vector2(
(Flipper.width) * direction,
Flipper.height + SlingShot.size.y,
(Flipper.size.x) * direction,
Flipper.size.y + SlingShot.size.y,
);
await addAll([flipper, baseboard, slingShot]);

@ -58,11 +58,8 @@ class Flipper extends BodyComponent with KeyboardHandler, InitialPosition {
/// Sprite is preloaded by [PinballGameAssetsX].
static const spritePath = 'components/flipper.png';
/// The width of the [Flipper].
static const width = 12.0;
/// The height of the [Flipper].
static const height = 2.8;
/// The size of the [Flipper].
static final size = Vector2(12, 2.8);
/// The speed required to move the [Flipper] to its highest position.
///
@ -97,7 +94,7 @@ class Flipper extends BodyComponent with KeyboardHandler, InitialPosition {
final sprite = await gameRef.loadSprite(spritePath);
final spriteComponent = SpriteComponent(
sprite: sprite,
size: Vector2(width, height),
size: size,
anchor: Anchor.center,
);
@ -134,21 +131,21 @@ class Flipper extends BodyComponent with KeyboardHandler, InitialPosition {
final fixturesDef = <FixtureDef>[];
final isLeft = side.isLeft;
final bigCircleShape = CircleShape()..radius = height / 2;
final bigCircleShape = CircleShape()..radius = 1.75;
bigCircleShape.position.setValues(
isLeft
? -(width / 2) + bigCircleShape.radius
: (width / 2) - bigCircleShape.radius,
? -(size.x / 2) + bigCircleShape.radius
: (size.x / 2) - bigCircleShape.radius,
0,
);
final bigCircleFixtureDef = FixtureDef(bigCircleShape);
fixturesDef.add(bigCircleFixtureDef);
final smallCircleShape = CircleShape()..radius = bigCircleShape.radius / 2;
final smallCircleShape = CircleShape()..radius = 0.9;
smallCircleShape.position.setValues(
isLeft
? (width / 2) - smallCircleShape.radius
: -(width / 2) + smallCircleShape.radius,
? (size.x / 2) - smallCircleShape.radius
: -(size.x / 2) + smallCircleShape.radius,
0,
);
final smallCircleFixtureDef = FixtureDef(smallCircleShape);
@ -227,8 +224,8 @@ class FlipperAnchor extends JointAnchor {
}) {
initialPosition = Vector2(
flipper.side.isLeft
? flipper.body.position.x - Flipper.width / 2
: flipper.body.position.x + Flipper.width / 2,
? flipper.body.position.x - Flipper.size.x / 2
: flipper.body.position.x + Flipper.size.x / 2,
flipper.body.position.y,
);
}

@ -282,7 +282,7 @@ void main() {
final flipperAnchor = FlipperAnchor(flipper: flipper);
await game.ensureAdd(flipperAnchor);
expect(flipperAnchor.body.position.x, equals(-Flipper.width / 2));
expect(flipperAnchor.body.position.x, equals(-Flipper.size.x / 2));
},
);
@ -297,7 +297,7 @@ void main() {
final flipperAnchor = FlipperAnchor(flipper: flipper);
await game.ensureAdd(flipperAnchor);
expect(flipperAnchor.body.position.x, equals(Flipper.width / 2));
expect(flipperAnchor.body.position.x, equals(Flipper.size.x / 2));
},
);
});

Loading…
Cancel
Save