refactor: moved static param and made other private on ramps

pull/87/head
RuiAlonso 4 years ago
parent a17eaa8b66
commit 46e04dc5f8

@ -11,12 +11,6 @@ import 'package:pinball_components/pinball_components.dart';
/// A [Blueprint] which creates the [JetpackRamp]. /// A [Blueprint] which creates the [JetpackRamp].
class Jetpack extends Forge2DBlueprint { class Jetpack extends Forge2DBlueprint {
/// Width between walls of the pathway.
static const width = 5.0;
/// Size for the radius of the external wall pathway.
static const externalRadius = 18.0;
@override @override
void build(_) { void build(_) {
final position = Vector2( final position = Vector2(
@ -63,12 +57,18 @@ class JetpackRamp extends BodyComponent with InitialPosition, Layered {
..style = PaintingStyle.stroke; ..style = PaintingStyle.stroke;
} }
/// Size for the radius of the external wall pathway.
static const _externalRadius = 18.0;
/// Width between walls of the pathway.
static const width = 5.0;
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final fixturesDef = <FixtureDef>[]; final fixturesDef = <FixtureDef>[];
final externalCurveShape = ArcShape( final externalCurveShape = ArcShape(
center: initialPosition, center: initialPosition,
arcRadius: Jetpack.externalRadius, arcRadius: _externalRadius,
angle: math.pi, angle: math.pi,
rotation: math.pi, rotation: math.pi,
); );
@ -76,7 +76,7 @@ class JetpackRamp extends BodyComponent with InitialPosition, Layered {
fixturesDef.add(externalFixtureDef); fixturesDef.add(externalFixtureDef);
final internalCurveShape = externalCurveShape.copyWith( final internalCurveShape = externalCurveShape.copyWith(
arcRadius: Jetpack.externalRadius - Jetpack.width, arcRadius: _externalRadius - width,
); );
final internalFixtureDef = FixtureDef(internalCurveShape); final internalFixtureDef = FixtureDef(internalCurveShape);
fixturesDef.add(internalFixtureDef); fixturesDef.add(internalFixtureDef);
@ -115,7 +115,7 @@ class _JetpackRampOpening extends RampOpening {
final double _rotation; final double _rotation;
static final Vector2 _size = Vector2(Jetpack.width / 3, .1); static final Vector2 _size = Vector2(JetpackRamp.width / 3, .1);
@override @override
Shape get shape => PolygonShape() Shape get shape => PolygonShape()

@ -11,12 +11,6 @@ import 'package:pinball_components/pinball_components.dart';
/// A [Blueprint] which creates the [LauncherRamp]. /// A [Blueprint] which creates the [LauncherRamp].
class Launcher extends Forge2DBlueprint { class Launcher extends Forge2DBlueprint {
/// Width between walls of the pathway.
static const width = 5.0;
/// Size for the radius of the external wall pathway.
static const externalRadius = 16.3;
@override @override
void build(_) { void build(_) {
final position = Vector2( final position = Vector2(
@ -60,6 +54,12 @@ class LauncherRamp extends BodyComponent with InitialPosition, Layered {
..style = PaintingStyle.stroke; ..style = PaintingStyle.stroke;
} }
/// Width between walls of the pathway.
static const width = 5.0;
/// Size for the radius of the external wall pathway.
static const _externalRadius = 16.3;
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final fixturesDef = <FixtureDef>[]; final fixturesDef = <FixtureDef>[];
@ -76,15 +76,15 @@ class LauncherRamp extends BodyComponent with InitialPosition, Layered {
final internalStraightShape = EdgeShape() final internalStraightShape = EdgeShape()
..set( ..set(
startPosition - Vector2(Launcher.width, 0), startPosition - Vector2(width, 0),
endPosition - Vector2(Launcher.width, 0), endPosition - Vector2(width, 0),
); );
final internalStraightFixtureDef = FixtureDef(internalStraightShape); final internalStraightFixtureDef = FixtureDef(internalStraightShape);
fixturesDef.add(internalStraightFixtureDef); fixturesDef.add(internalStraightFixtureDef);
final externalCurveShape = ArcShape( final externalCurveShape = ArcShape(
center: initialPosition + Vector2(-28.2, 132), center: initialPosition + Vector2(-28.2, 132),
arcRadius: Launcher.externalRadius, arcRadius: _externalRadius,
angle: math.pi / 2, angle: math.pi / 2,
rotation: 3 * math.pi / 2, rotation: 3 * math.pi / 2,
); );
@ -92,7 +92,7 @@ class LauncherRamp extends BodyComponent with InitialPosition, Layered {
fixturesDef.add(externalCurveFixtureDef); fixturesDef.add(externalCurveFixtureDef);
final internalCurveShape = externalCurveShape.copyWith( final internalCurveShape = externalCurveShape.copyWith(
arcRadius: Launcher.externalRadius - Launcher.width, arcRadius: _externalRadius - width,
); );
final internalCurveFixtureDef = FixtureDef(internalCurveShape); final internalCurveFixtureDef = FixtureDef(internalCurveShape);
fixturesDef.add(internalCurveFixtureDef); fixturesDef.add(internalCurveFixtureDef);
@ -129,7 +129,7 @@ class _LauncherRampOpening extends RampOpening {
final double _rotation; final double _rotation;
static final Vector2 _size = Vector2(Launcher.width / 3, .1); static final Vector2 _size = Vector2(LauncherRamp.width / 3, .1);
@override @override
Shape get shape => PolygonShape() Shape get shape => PolygonShape()

Loading…
Cancel
Save