diff --git a/lib/game/components/flipper.dart b/lib/game/components/flipper.dart index 2f36023a..f3f4fafe 100644 --- a/lib/game/components/flipper.dart +++ b/lib/game/components/flipper.dart @@ -40,8 +40,11 @@ class Flipper extends BodyComponent { isMirrored: false, ); - // TODO(alestiago): Use width and height. - static final size = Vector2(12, 2.8); + /// The width of the [Flipper]. + static const width = 12.0; + + /// The height of the [Flipper]. + static const height = 2.8; /// The total duration of a full flipper's arc motion. /// @@ -54,7 +57,7 @@ class Flipper extends BodyComponent { static double _calculateSpeed() { // TODO(alestiago): test correctness. const angle = FlipperAnchorRevoluteJointDef._sweepingAngle / 2; - final sweepingDistance = (size.x * math.sin(angle)) * 2; + final sweepingDistance = (width * math.sin(angle)) * 2; final seconds = _sweepingAnimationDuration.inMicroseconds / Duration.microsecondsPerSecond; @@ -94,39 +97,39 @@ class Flipper extends BodyComponent { List _createFixtureDefs() { final fixtures = []; - final bigRadius = size.y / 2; + const bigRadius = height / 2; final bigCircleShape = CircleShape() ..radius = bigRadius ..position.setValues( - _isMirrored ? size.x - bigRadius : bigRadius, + _isMirrored ? width - bigRadius : bigRadius, -bigRadius, ); final bigCircleFixtureDef = FixtureDef(bigCircleShape); fixtures.add(bigCircleFixtureDef); - final smallRadius = bigRadius / 2; + const smallRadius = bigRadius / 2; final smallCircleShape = CircleShape() ..radius = smallRadius ..position.setValues( - _isMirrored ? smallRadius : size.x - smallRadius, + _isMirrored ? smallRadius : width - smallRadius, -2 * smallRadius, ); final smallCircleFixtureDef = FixtureDef(smallCircleShape); fixtures.add(smallCircleFixtureDef); - final inclineSpace = (size.y - (2 * smallRadius)) / 2; + const inclineSpace = (height - (2 * smallRadius)) / 2; final trapeziumVertices = _isMirrored ? [ Vector2(smallRadius, -inclineSpace), - Vector2(size.x - bigRadius, 0), - Vector2(size.x - bigRadius, -size.y), - Vector2(smallRadius, -size.y + inclineSpace), + Vector2(width - bigRadius, 0), + Vector2(width - bigRadius, -height), + Vector2(smallRadius, -height + inclineSpace), ] : [ Vector2(bigCircleShape.radius, 0), - Vector2(size.x - smallCircleShape.radius, -inclineSpace), - Vector2(size.x - smallCircleShape.radius, -size.y + inclineSpace), - Vector2(bigCircleShape.radius, -size.y), + Vector2(width - smallCircleShape.radius, -inclineSpace), + Vector2(width - smallCircleShape.radius, -height + inclineSpace), + Vector2(bigCircleShape.radius, -height), ]; final trapezium = PolygonShape()..set(trapeziumVertices); final trapeziumFixtureDef = FixtureDef(trapezium) diff --git a/lib/game/pinball_game.dart b/lib/game/pinball_game.dart index 3af9d1f5..37df3c8c 100644 --- a/lib/game/pinball_game.dart +++ b/lib/game/pinball_game.dart @@ -37,7 +37,7 @@ class PinballGame extends Forge2DGame with FlameBloc, KeyboardEvents { await add( _leftFlipper = Flipper.left( position: Vector2( - (center.x - (Flipper.size.x / 2)) - (flipperSpace / 2), + (center.x - (Flipper.width / 2)) - (flipperSpace / 2), center.y, ), ), @@ -45,7 +45,7 @@ class PinballGame extends Forge2DGame with FlameBloc, KeyboardEvents { final leftFlipperAnchor = Anchor( position: Vector2( _leftFlipper.body.position.x, - _leftFlipper.body.position.y - Flipper.size.y / 2, + _leftFlipper.body.position.y - Flipper.height / 2, ), ); await add(leftFlipperAnchor); @@ -61,15 +61,15 @@ class PinballGame extends Forge2DGame with FlameBloc, KeyboardEvents { await add( _rightFlipper = Flipper.right( position: Vector2( - (center.x + (Flipper.size.x / 2)) + (flipperSpace / 2), + (center.x + (Flipper.width / 2)) + (flipperSpace / 2), center.y, ), ), ); final rightFlipperAnchor = Anchor( position: Vector2( - _rightFlipper.body.position.x + Flipper.size.x, - _rightFlipper.body.position.y - Flipper.size.y / 2, + _rightFlipper.body.position.x + Flipper.width, + _rightFlipper.body.position.y - Flipper.height / 2, ), ); await add(rightFlipperAnchor);