refactor: modified jetpack ramp to use shapes and blueprint

pull/87/head
RuiAlonso 4 years ago
parent a701d99e9a
commit 2629fdac41

@ -10,10 +10,14 @@ import 'package:pinball/flame/blueprint.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball_components/pinball_components.dart';
/// {@template jetpack_ramp}
/// Represents the upper left blue ramp of the [Board].
/// {@endtemplate}
/// A [Blueprint] which creates the [JetpackRamp].
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
void build(_) {
final position = Vector2(
@ -33,9 +37,8 @@ class Jetpack extends Forge2DBlueprint {
..layer = Layer.jetpack;
final _curve = JetpackRamp()
..initialPosition = position
..initialPosition = position + Vector2(5, -20.2)
..layer = Layer.jetpack;
final _rightOpening = _JetpackRampOpening(
rotation: math.pi,
)
@ -50,6 +53,9 @@ class Jetpack extends Forge2DBlueprint {
}
}
/// {@template jetpack_ramp}
/// Represents the upper left blue ramp of the [Board].
/// {@endtemplate}
class JetpackRamp extends BodyComponent with InitialPosition, Layered {
JetpackRamp() : super(priority: 2) {
layer = Layer.jetpack;
@ -58,23 +64,37 @@ class JetpackRamp extends BodyComponent with InitialPosition, Layered {
..style = PaintingStyle.stroke;
}
@override
Body createBody() {
final curveShape = ArcShape(
List<FixtureDef> _createFixtureDefs() {
final fixturesDef = <FixtureDef>[];
final externalCurveShape = ArcShape(
center: initialPosition,
arcRadius: 18,
arcRadius: Jetpack.externalRadius,
angle: math.pi,
rotation: math.pi,
);
final externalFixtureDef = FixtureDef(externalCurveShape);
fixturesDef.add(externalFixtureDef);
final internalCurveShape = externalCurveShape.copyWith(
arcRadius: Jetpack.externalRadius - Jetpack.width,
);
final internalFixtureDef = FixtureDef(internalCurveShape);
fixturesDef.add(internalFixtureDef);
return fixturesDef;
}
@override
Body createBody() {
final bodyDef = BodyDef()
..userData = this
..position = initialPosition;
return world.createBody(bodyDef)
..createFixture(
FixtureDef(curveShape),
);
final body = world.createBody(bodyDef);
_createFixtureDefs().forEach(body.createFixture);
return body;
}
}
@ -96,9 +116,7 @@ class _JetpackRampOpening extends RampOpening {
final double _rotation;
// TODO(ruialonso): Avoid magic number 3, should be propotional to
// [JetpackRamp].
static final Vector2 _size = Vector2(3, .1);
static final Vector2 _size = Vector2(Jetpack.width / 3, .1);
@override
Shape get shape => PolygonShape()

Loading…
Cancel
Save