|
|
@ -9,14 +9,12 @@ import 'package:pinball/game/game.dart';
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// [BodyComponent]s such as a Ball can collide and move along a [Pathway].
|
|
|
|
/// [BodyComponent]s such as a Ball can collide and move along a [Pathway].
|
|
|
|
/// {@endtemplate}
|
|
|
|
/// {@endtemplate}
|
|
|
|
class Pathway extends BodyComponent with InitialPosition {
|
|
|
|
class Pathway extends BodyComponent with InitialPosition, Layered {
|
|
|
|
Pathway._({
|
|
|
|
Pathway._({
|
|
|
|
// TODO(ruialonso): remove color when assets added.
|
|
|
|
// TODO(ruialonso): remove color when assets added.
|
|
|
|
Color? color,
|
|
|
|
Color? color,
|
|
|
|
required List<List<Vector2>> paths,
|
|
|
|
required List<List<Vector2>> paths,
|
|
|
|
Layer? layer,
|
|
|
|
}) : _paths = paths {
|
|
|
|
}) : _paths = paths,
|
|
|
|
|
|
|
|
_layer = layer {
|
|
|
|
|
|
|
|
paint = Paint()
|
|
|
|
paint = Paint()
|
|
|
|
..color = color ?? const Color.fromARGB(0, 0, 0, 0)
|
|
|
|
..color = color ?? const Color.fromARGB(0, 0, 0, 0)
|
|
|
|
..style = PaintingStyle.stroke;
|
|
|
|
..style = PaintingStyle.stroke;
|
|
|
@ -35,7 +33,6 @@ class Pathway extends BodyComponent with InitialPosition {
|
|
|
|
required double width,
|
|
|
|
required double width,
|
|
|
|
double rotation = 0,
|
|
|
|
double rotation = 0,
|
|
|
|
bool singleWall = false,
|
|
|
|
bool singleWall = false,
|
|
|
|
Layer? layer,
|
|
|
|
|
|
|
|
}) {
|
|
|
|
}) {
|
|
|
|
final paths = <List<Vector2>>[];
|
|
|
|
final paths = <List<Vector2>>[];
|
|
|
|
|
|
|
|
|
|
|
@ -57,7 +54,6 @@ class Pathway extends BodyComponent with InitialPosition {
|
|
|
|
return Pathway._(
|
|
|
|
return Pathway._(
|
|
|
|
color: color,
|
|
|
|
color: color,
|
|
|
|
paths: paths,
|
|
|
|
paths: paths,
|
|
|
|
layer: layer,
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -81,7 +77,6 @@ class Pathway extends BodyComponent with InitialPosition {
|
|
|
|
required double angle,
|
|
|
|
required double angle,
|
|
|
|
double rotation = 0,
|
|
|
|
double rotation = 0,
|
|
|
|
bool singleWall = false,
|
|
|
|
bool singleWall = false,
|
|
|
|
Layer? layer,
|
|
|
|
|
|
|
|
}) {
|
|
|
|
}) {
|
|
|
|
final paths = <List<Vector2>>[];
|
|
|
|
final paths = <List<Vector2>>[];
|
|
|
|
|
|
|
|
|
|
|
@ -107,7 +102,6 @@ class Pathway extends BodyComponent with InitialPosition {
|
|
|
|
return Pathway._(
|
|
|
|
return Pathway._(
|
|
|
|
color: color,
|
|
|
|
color: color,
|
|
|
|
paths: paths,
|
|
|
|
paths: paths,
|
|
|
|
layer: layer,
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -126,7 +120,6 @@ class Pathway extends BodyComponent with InitialPosition {
|
|
|
|
required double width,
|
|
|
|
required double width,
|
|
|
|
double rotation = 0,
|
|
|
|
double rotation = 0,
|
|
|
|
bool singleWall = false,
|
|
|
|
bool singleWall = false,
|
|
|
|
Layer? layer,
|
|
|
|
|
|
|
|
}) {
|
|
|
|
}) {
|
|
|
|
final paths = <List<Vector2>>[];
|
|
|
|
final paths = <List<Vector2>>[];
|
|
|
|
|
|
|
|
|
|
|
@ -148,28 +141,31 @@ class Pathway extends BodyComponent with InitialPosition {
|
|
|
|
return Pathway._(
|
|
|
|
return Pathway._(
|
|
|
|
color: color,
|
|
|
|
color: color,
|
|
|
|
paths: paths,
|
|
|
|
paths: paths,
|
|
|
|
layer: layer,
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
final List<List<Vector2>> _paths;
|
|
|
|
final List<List<Vector2>> _paths;
|
|
|
|
Layer? _layer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
List<FixtureDef> _createFixtureDefs() {
|
|
|
|
Body createBody() {
|
|
|
|
final fixturesDef = <FixtureDef>[];
|
|
|
|
final bodyDef = BodyDef()..position = initialPosition;
|
|
|
|
|
|
|
|
final body = world.createBody(bodyDef);
|
|
|
|
|
|
|
|
for (final path in _paths) {
|
|
|
|
for (final path in _paths) {
|
|
|
|
final chain = ChainShape()
|
|
|
|
final chain = ChainShape()
|
|
|
|
..createChain(
|
|
|
|
..createChain(
|
|
|
|
path.map(gameRef.screenToWorld).toList(),
|
|
|
|
path.map(gameRef.screenToWorld).toList(),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
final fixtureDef = FixtureDef(chain);
|
|
|
|
fixturesDef.add(FixtureDef(chain));
|
|
|
|
|
|
|
|
|
|
|
|
body.createFixture(fixtureDef).filterData.categoryBits =
|
|
|
|
|
|
|
|
_layer?.maskBits ?? Layer.board.maskBits;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return fixturesDef;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
Body createBody() {
|
|
|
|
|
|
|
|
final bodyDef = BodyDef()..position = initialPosition;
|
|
|
|
|
|
|
|
final body = world.createBody(bodyDef);
|
|
|
|
|
|
|
|
_createFixtureDefs().forEach(body.createFixture);
|
|
|
|
|
|
|
|
|
|
|
|
return body;
|
|
|
|
return body;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|