feat: reshape `Baseboards` (#85)

* refactor: removed findNested extensions (#77)

* refactor: baseboard shape and position

* chore: remove unused asset

* test: update fixture test

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.7 KiB

@ -5,7 +5,7 @@ import 'package:pinball/game/game.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
/// {@template baseboard} /// {@template baseboard}
/// Straight, angled board piece to corral the [Ball] towards the [Flipper]s. /// Wing-shaped board piece to corral the [Ball] towards the [Flipper]s.
/// {@endtemplate} /// {@endtemplate}
class Baseboard extends BodyComponent with InitialPosition { class Baseboard extends BodyComponent with InitialPosition {
/// {@macro baseboard} /// {@macro baseboard}
@ -13,41 +13,68 @@ class Baseboard extends BodyComponent with InitialPosition {
required BoardSide side, required BoardSide side,
}) : _side = side; }) : _side = side;
/// The width of the [Baseboard]. /// The size of the [Baseboard].
static const width = 10.0; static final size = Vector2(24.2, 13.5);
/// The height of the [Baseboard].
static const height = 2.0;
/// Whether the [Baseboard] is on the left or right side of the board. /// Whether the [Baseboard] is on the left or right side of the board.
final BoardSide _side; final BoardSide _side;
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final fixturesDef = <FixtureDef>[]; final fixturesDef = <FixtureDef>[];
final direction = _side.direction;
final arcsAngle = -1.11 * direction;
const arcsRotation = math.pi / 2.08;
final topCircleShape = CircleShape()..radius = 0.7;
topCircleShape.position.setValues(11.39 * direction, 6.05);
final topCircleFixtureDef = FixtureDef(topCircleShape);
fixturesDef.add(topCircleFixtureDef);
final innerEdgeShape = EdgeShape()
..set(
Vector2(10.86 * direction, 6.45),
Vector2(6.96 * direction, 0.25),
);
final innerEdgeShapeFixtureDef = FixtureDef(innerEdgeShape);
fixturesDef.add(innerEdgeShapeFixtureDef);
final outerEdgeShape = EdgeShape()
..set(
Vector2(11.96 * direction, 5.85),
Vector2(5.48 * direction, -4.85),
);
final outerEdgeShapeFixtureDef = FixtureDef(outerEdgeShape);
fixturesDef.add(outerEdgeShapeFixtureDef);
final upperArcFixtureDefs = Pathway.arc(
center: Vector2(1.76 * direction, 3.25),
width: 0,
radius: 6.1,
angle: arcsAngle,
rotation: arcsRotation,
singleWall: true,
).createFixtureDefs();
fixturesDef.addAll(upperArcFixtureDefs);
final lowerArcFixtureDefs = Pathway.arc(
center: Vector2(1.85 * direction, -2.15),
width: 0,
radius: 4.5,
angle: arcsAngle,
rotation: arcsRotation,
singleWall: true,
).createFixtureDefs();
fixturesDef.addAll(lowerArcFixtureDefs);
final circleShape1 = CircleShape()..radius = Baseboard.height / 2; final bottomRectangle = PolygonShape()
circleShape1.position.setValues( ..setAsBox(
-(Baseboard.width / 2) + circleShape1.radius, 7,
0, 2,
); Vector2(-5.14 * direction, -4.75),
final circle1FixtureDef = FixtureDef(circleShape1); 0,
fixturesDef.add(circle1FixtureDef);
final circleShape2 = CircleShape()..radius = Baseboard.height / 2;
circleShape2.position.setValues(
(Baseboard.width / 2) - circleShape2.radius,
0,
);
final circle2FixtureDef = FixtureDef(circleShape2);
fixturesDef.add(circle2FixtureDef);
final rectangle = PolygonShape()
..setAsBoxXY(
(Baseboard.width - Baseboard.height) / 2,
Baseboard.height / 2,
); );
final rectangleFixtureDef = FixtureDef(rectangle); final bottomRectangleFixtureDef = FixtureDef(bottomRectangle);
fixturesDef.add(rectangleFixtureDef); fixturesDef.add(bottomRectangleFixtureDef);
return fixturesDef; return fixturesDef;
} }
@ -56,7 +83,7 @@ class Baseboard extends BodyComponent with InitialPosition {
Body createBody() { Body createBody() {
// TODO(allisonryan0002): share sweeping angle with flipper when components // TODO(allisonryan0002): share sweeping angle with flipper when components
// are grouped. // are grouped.
const angle = math.pi / 7; const angle = math.pi / 5;
final bodyDef = BodyDef() final bodyDef = BodyDef()
..position = initialPosition ..position = initialPosition

@ -134,8 +134,8 @@ class _BottomGroupSide extends Component {
final baseboard = Baseboard(side: _side) final baseboard = Baseboard(side: _side)
..initialPosition = _position + ..initialPosition = _position +
Vector2( Vector2(
(Flipper.size.x * direction) - direction, (Baseboard.size.x / 1.6 * direction),
Flipper.size.y, Baseboard.size.y - 2,
); );
final kicker = Kicker( final kicker = Kicker(
side: _side, side: _side,

@ -17,8 +17,6 @@ class $AssetsImagesComponentsGen {
AssetGenImage get flipper => AssetGenImage get flipper =>
const AssetGenImage('assets/images/components/flipper.png'); const AssetGenImage('assets/images/components/flipper.png');
AssetGenImage get sauce =>
const AssetGenImage('assets/images/components/sauce.png');
$AssetsImagesComponentsSpaceshipGen get spaceship => $AssetsImagesComponentsSpaceshipGen get spaceship =>
const $AssetsImagesComponentsSpaceshipGen(); const $AssetsImagesComponentsSpaceshipGen();
} }

@ -61,14 +61,14 @@ void main() {
group('fixtures', () { group('fixtures', () {
flameTester.test( flameTester.test(
'has three', 'has six',
(game) async { (game) async {
final baseboard = Baseboard( final baseboard = Baseboard(
side: BoardSide.left, side: BoardSide.left,
); );
await game.ensureAdd(baseboard); await game.ensureAdd(baseboard);
expect(baseboard.body.fixtures.length, equals(3)); expect(baseboard.body.fixtures.length, equals(6));
}, },
); );
}); });

Loading…
Cancel
Save