|
|
@ -17,6 +17,8 @@ class Jetpack extends Forge2DBlueprint {
|
|
|
|
/// The [position] where the elements will be created
|
|
|
|
/// The [position] where the elements will be created
|
|
|
|
final Vector2 position;
|
|
|
|
final Vector2 position;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const int ballPriorityInsideRamp = 4;
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
void build(_) {
|
|
|
|
void build(_) {
|
|
|
|
addAllContactCallback([
|
|
|
|
addAllContactCallback([
|
|
|
@ -24,30 +26,28 @@ class Jetpack extends Forge2DBlueprint {
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
final rightOpening = _JetpackRampOpening(
|
|
|
|
final rightOpening = _JetpackRampOpening(
|
|
|
|
|
|
|
|
outsidePriority: 1,
|
|
|
|
rotation: math.pi,
|
|
|
|
rotation: math.pi,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
..initialPosition = position + Vector2(1.7, 19)
|
|
|
|
..initialPosition = position + Vector2(1.7, 19)
|
|
|
|
..layer = Layer.opening;
|
|
|
|
..layer = Layer.opening;
|
|
|
|
final leftOpening = _JetpackRampOpening(
|
|
|
|
final leftOpening = _JetpackRampOpening(
|
|
|
|
outsideLayer: Layer.spaceship,
|
|
|
|
outsideLayer: Layer.spaceship,
|
|
|
|
|
|
|
|
outsidePriority: 4,
|
|
|
|
rotation: math.pi,
|
|
|
|
rotation: math.pi,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
..initialPosition = position + Vector2(-13.7, 19)
|
|
|
|
..initialPosition = position + Vector2(-13.7, 19)
|
|
|
|
..layer = Layer.jetpack;
|
|
|
|
..layer = Layer.jetpack;
|
|
|
|
|
|
|
|
|
|
|
|
final jetpackRamp = JetpackRamp()
|
|
|
|
final jetpackRamp = JetpackRamp()..initialPosition = position;
|
|
|
|
..initialPosition = position
|
|
|
|
|
|
|
|
..layer = Layer.jetpack;
|
|
|
|
final jetpackRampWallFg = _JetpackRampWallFg()..initialPosition = position;
|
|
|
|
|
|
|
|
|
|
|
|
final baseRight = _JetpackBase()
|
|
|
|
final baseRight = _JetpackBase()
|
|
|
|
..initialPosition = position + Vector2(1.7, 20);
|
|
|
|
..initialPosition = position + Vector2(1.7, 20);
|
|
|
|
|
|
|
|
|
|
|
|
addAll([
|
|
|
|
addAll(
|
|
|
|
rightOpening,
|
|
|
|
[rightOpening, leftOpening, jetpackRamp, baseRight, jetpackRampWallFg]);
|
|
|
|
leftOpening,
|
|
|
|
|
|
|
|
jetpackRamp,
|
|
|
|
|
|
|
|
baseRight,
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -55,11 +55,8 @@ class Jetpack extends Forge2DBlueprint {
|
|
|
|
/// Represents the upper left blue ramp of the [Board].
|
|
|
|
/// Represents the upper left blue ramp of the [Board].
|
|
|
|
/// {@endtemplate}
|
|
|
|
/// {@endtemplate}
|
|
|
|
class JetpackRamp extends BodyComponent with InitialPosition, Layered {
|
|
|
|
class JetpackRamp extends BodyComponent with InitialPosition, Layered {
|
|
|
|
JetpackRamp() : super(priority: 3) {
|
|
|
|
JetpackRamp() : super(priority: Jetpack.ballPriorityInsideRamp - 1) {
|
|
|
|
layer = Layer.jetpack;
|
|
|
|
layer = Layer.jetpack;
|
|
|
|
paint = Paint()
|
|
|
|
|
|
|
|
..color = Color.fromARGB(255, 0, 217, 255)
|
|
|
|
|
|
|
|
..style = PaintingStyle.stroke;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Width between walls of the ramp.
|
|
|
|
/// Width between walls of the ramp.
|
|
|
@ -68,33 +65,9 @@ class JetpackRamp extends BodyComponent with InitialPosition, Layered {
|
|
|
|
List<FixtureDef> _createFixtureDefs() {
|
|
|
|
List<FixtureDef> _createFixtureDefs() {
|
|
|
|
final fixturesDef = <FixtureDef>[];
|
|
|
|
final fixturesDef = <FixtureDef>[];
|
|
|
|
|
|
|
|
|
|
|
|
final innerLeftControlPoints = [
|
|
|
|
|
|
|
|
Vector2(-24.73, 38),
|
|
|
|
|
|
|
|
Vector2(-26.3, 65.65),
|
|
|
|
|
|
|
|
Vector2(-13.8, 65.65),
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
final innerLeftCurveShape = BezierCurveShape(
|
|
|
|
|
|
|
|
controlPoints: innerLeftControlPoints,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final innerLeftCurveFixtureDef = FixtureDef(innerLeftCurveShape);
|
|
|
|
|
|
|
|
fixturesDef.add(innerLeftCurveFixtureDef);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final innerRightControlPoints = [
|
|
|
|
|
|
|
|
innerLeftControlPoints.last,
|
|
|
|
|
|
|
|
Vector2(-1, 65.9),
|
|
|
|
|
|
|
|
Vector2(0.1, 39.5),
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
final innerRightCurveShape = BezierCurveShape(
|
|
|
|
|
|
|
|
controlPoints: innerRightControlPoints,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final innerRightCurveFixtureDef = FixtureDef(innerRightCurveShape);
|
|
|
|
|
|
|
|
fixturesDef.add(innerRightCurveFixtureDef);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final outerLeftControlPoints = [
|
|
|
|
final outerLeftControlPoints = [
|
|
|
|
Vector2(-30.95, 38),
|
|
|
|
Vector2(-30.95, 38),
|
|
|
|
Vector2(-33, 71.25),
|
|
|
|
Vector2(-32.5, 71.25),
|
|
|
|
Vector2(-14.2, 71.25),
|
|
|
|
Vector2(-14.2, 71.25),
|
|
|
|
];
|
|
|
|
];
|
|
|
|
final outerLeftCurveShape = BezierCurveShape(
|
|
|
|
final outerLeftCurveShape = BezierCurveShape(
|
|
|
@ -107,7 +80,7 @@ class JetpackRamp extends BodyComponent with InitialPosition, Layered {
|
|
|
|
final outerRightControlPoints = [
|
|
|
|
final outerRightControlPoints = [
|
|
|
|
outerLeftControlPoints.last,
|
|
|
|
outerLeftControlPoints.last,
|
|
|
|
Vector2(4.7, 71.25),
|
|
|
|
Vector2(4.7, 71.25),
|
|
|
|
Vector2(6.3, 40.1),
|
|
|
|
Vector2(6.3, 40),
|
|
|
|
];
|
|
|
|
];
|
|
|
|
final outerRightCurveShape = BezierCurveShape(
|
|
|
|
final outerRightCurveShape = BezierCurveShape(
|
|
|
|
controlPoints: outerRightControlPoints,
|
|
|
|
controlPoints: outerRightControlPoints,
|
|
|
@ -121,6 +94,8 @@ class JetpackRamp extends BodyComponent with InitialPosition, Layered {
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Body createBody() {
|
|
|
|
Body createBody() {
|
|
|
|
|
|
|
|
renderBody = false;
|
|
|
|
|
|
|
|
|
|
|
|
final bodyDef = BodyDef()
|
|
|
|
final bodyDef = BodyDef()
|
|
|
|
..userData = this
|
|
|
|
..userData = this
|
|
|
|
..position = initialPosition;
|
|
|
|
..position = initialPosition;
|
|
|
@ -134,7 +109,7 @@ class JetpackRamp extends BodyComponent with InitialPosition, Layered {
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
await super.onLoad();
|
|
|
|
await super.onLoad();
|
|
|
|
//await _loadBackground();
|
|
|
|
await _loadBackground();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _loadBackground() async {
|
|
|
|
Future<void> _loadBackground() async {
|
|
|
@ -146,9 +121,7 @@ class JetpackRamp extends BodyComponent with InitialPosition, Layered {
|
|
|
|
sprite: spriteRamp,
|
|
|
|
sprite: spriteRamp,
|
|
|
|
size: Vector2(38.1, 33.8),
|
|
|
|
size: Vector2(38.1, 33.8),
|
|
|
|
anchor: Anchor.center,
|
|
|
|
anchor: Anchor.center,
|
|
|
|
)
|
|
|
|
)..position = Vector2(-12.2, -53.5);
|
|
|
|
..position = Vector2(-12.2, -53.5)
|
|
|
|
|
|
|
|
..priority = 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final spriteRailingBg = await gameRef.loadSprite(
|
|
|
|
final spriteRailingBg = await gameRef.loadSprite(
|
|
|
|
Assets.images.components.spaceshipRailingBg.path,
|
|
|
|
Assets.images.components.spaceshipRailingBg.path,
|
|
|
@ -157,10 +130,71 @@ class JetpackRamp extends BodyComponent with InitialPosition, Layered {
|
|
|
|
sprite: spriteRailingBg,
|
|
|
|
sprite: spriteRailingBg,
|
|
|
|
size: Vector2(38.3, 35.1),
|
|
|
|
size: Vector2(38.3, 35.1),
|
|
|
|
anchor: Anchor.center,
|
|
|
|
anchor: Anchor.center,
|
|
|
|
)
|
|
|
|
)..position = spriteRampComponent.position + Vector2(0, -1);
|
|
|
|
..position = spriteRampComponent.position + Vector2(0, -1)
|
|
|
|
|
|
|
|
..priority = 3;
|
|
|
|
await addAll([
|
|
|
|
|
|
|
|
spriteRailingBgComponent,
|
|
|
|
|
|
|
|
spriteRampComponent,
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _JetpackRampWallFg extends BodyComponent with InitialPosition, Layered {
|
|
|
|
|
|
|
|
_JetpackRampWallFg() : super(priority: Jetpack.ballPriorityInsideRamp + 1) {
|
|
|
|
|
|
|
|
layer = Layer.jetpack;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<FixtureDef> _createFixtureDefs() {
|
|
|
|
|
|
|
|
final fixturesDef = <FixtureDef>[];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final innerLeftControlPoints = [
|
|
|
|
|
|
|
|
Vector2(-24.5, 38),
|
|
|
|
|
|
|
|
Vector2(-26.3, 64),
|
|
|
|
|
|
|
|
Vector2(-13.8, 64.5),
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
final innerLeftCurveShape = BezierCurveShape(
|
|
|
|
|
|
|
|
controlPoints: innerLeftControlPoints,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final innerLeftCurveFixtureDef = FixtureDef(innerLeftCurveShape);
|
|
|
|
|
|
|
|
fixturesDef.add(innerLeftCurveFixtureDef);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final innerRightControlPoints = [
|
|
|
|
|
|
|
|
innerLeftControlPoints.last,
|
|
|
|
|
|
|
|
Vector2(-1, 64.5),
|
|
|
|
|
|
|
|
Vector2(0.1, 39.5),
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
final innerRightCurveShape = BezierCurveShape(
|
|
|
|
|
|
|
|
controlPoints: innerRightControlPoints,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final innerRightCurveFixtureDef = FixtureDef(innerRightCurveShape);
|
|
|
|
|
|
|
|
fixturesDef.add(innerRightCurveFixtureDef);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return fixturesDef;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
Body createBody() {
|
|
|
|
|
|
|
|
renderBody = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final bodyDef = BodyDef()
|
|
|
|
|
|
|
|
..userData = this
|
|
|
|
|
|
|
|
..position = initialPosition;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final body = world.createBody(bodyDef);
|
|
|
|
|
|
|
|
_createFixtureDefs().forEach(body.createFixture);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return body;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
|
|
|
|
await super.onLoad();
|
|
|
|
|
|
|
|
await _loadBackground();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _loadBackground() async {
|
|
|
|
final spriteRailingFg = await gameRef.loadSprite(
|
|
|
|
final spriteRailingFg = await gameRef.loadSprite(
|
|
|
|
Assets.images.components.spaceshipRailingFg.path,
|
|
|
|
Assets.images.components.spaceshipRailingFg.path,
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -168,12 +202,8 @@ class JetpackRamp extends BodyComponent with InitialPosition, Layered {
|
|
|
|
sprite: spriteRailingFg,
|
|
|
|
sprite: spriteRailingFg,
|
|
|
|
size: Vector2(26.1, 28.3),
|
|
|
|
size: Vector2(26.1, 28.3),
|
|
|
|
anchor: Anchor.center,
|
|
|
|
anchor: Anchor.center,
|
|
|
|
)
|
|
|
|
)..position = Vector2(-12.2, -52.5);
|
|
|
|
..position = spriteRampComponent.position + Vector2(0, 1)
|
|
|
|
|
|
|
|
..priority = 5;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await add(spriteRailingBgComponent);
|
|
|
|
|
|
|
|
await add(spriteRampComponent);
|
|
|
|
|
|
|
|
await add(spriteRailingFgComponent);
|
|
|
|
await add(spriteRailingFgComponent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -187,12 +217,15 @@ class _JetpackBase extends BodyComponent with InitialPosition, Layered {
|
|
|
|
Body createBody() {
|
|
|
|
Body createBody() {
|
|
|
|
renderBody = false;
|
|
|
|
renderBody = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const baseWidth = 6;
|
|
|
|
final baseShape = BezierCurveShape(
|
|
|
|
final baseShape = BezierCurveShape(
|
|
|
|
controlPoints: [
|
|
|
|
controlPoints: [
|
|
|
|
Vector2(initialPosition.x - 3, initialPosition.y),
|
|
|
|
Vector2(initialPosition.x - baseWidth / 2, initialPosition.y),
|
|
|
|
Vector2(initialPosition.x - 3, initialPosition.y) + Vector2(2, 2),
|
|
|
|
Vector2(initialPosition.x - baseWidth / 2, initialPosition.y) +
|
|
|
|
Vector2(initialPosition.x + 3, initialPosition.y) + Vector2(-2, 2),
|
|
|
|
Vector2(2, 2),
|
|
|
|
Vector2(initialPosition.x + 3, initialPosition.y)
|
|
|
|
Vector2(initialPosition.x + baseWidth / 2, initialPosition.y) +
|
|
|
|
|
|
|
|
Vector2(-2, 2),
|
|
|
|
|
|
|
|
Vector2(initialPosition.x + baseWidth / 2, initialPosition.y)
|
|
|
|
],
|
|
|
|
],
|
|
|
|
);
|
|
|
|
);
|
|
|
|
final fixtureDef = FixtureDef(baseShape);
|
|
|
|
final fixtureDef = FixtureDef(baseShape);
|
|
|
@ -213,13 +246,15 @@ class _JetpackRampOpening extends RampOpening {
|
|
|
|
/// {@macro jetpack_ramp_opening}
|
|
|
|
/// {@macro jetpack_ramp_opening}
|
|
|
|
_JetpackRampOpening({
|
|
|
|
_JetpackRampOpening({
|
|
|
|
Layer? outsideLayer,
|
|
|
|
Layer? outsideLayer,
|
|
|
|
|
|
|
|
int? outsidePriority,
|
|
|
|
required double rotation,
|
|
|
|
required double rotation,
|
|
|
|
}) : _rotation = rotation,
|
|
|
|
}) : _rotation = rotation,
|
|
|
|
super(
|
|
|
|
super(
|
|
|
|
pathwayLayer: Layer.jetpack,
|
|
|
|
pathwayLayer: Layer.jetpack,
|
|
|
|
outsideLayer: outsideLayer,
|
|
|
|
outsideLayer: outsideLayer,
|
|
|
|
orientation: RampOrientation.down,
|
|
|
|
orientation: RampOrientation.down,
|
|
|
|
pathwayPriority: 4,
|
|
|
|
pathwayPriority: Jetpack.ballPriorityInsideRamp,
|
|
|
|
|
|
|
|
outsidePriority: outsidePriority,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
final double _rotation;
|
|
|
|
final double _rotation;
|
|
|
|