|
|
@ -1,22 +1,24 @@
|
|
|
|
// ignore_for_file: public_member_api_docs, avoid_renaming_method_parameters
|
|
|
|
// ignore_for_file: public_member_api_docs, avoid_renaming_method_parameters
|
|
|
|
|
|
|
|
|
|
|
|
import 'dart:math' as math;
|
|
|
|
import 'dart:math' as math;
|
|
|
|
|
|
|
|
import 'dart:ui';
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:flame/extensions.dart';
|
|
|
|
import 'package:flame/components.dart';
|
|
|
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
|
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:pinball/game/game.dart';
|
|
|
|
import 'package:pinball/game/game.dart';
|
|
|
|
import 'package:pinball_components/pinball_components.dart';
|
|
|
|
import 'package:pinball/gen/assets.gen.dart';
|
|
|
|
|
|
|
|
import 'package:pinball_components/pinball_components.dart' hide Assets;
|
|
|
|
|
|
|
|
|
|
|
|
/// A [Blueprint] which creates the [JetpackRamp].
|
|
|
|
/// A [Blueprint] which creates the [JetpackRamp].
|
|
|
|
class Jetpack extends Forge2DBlueprint {
|
|
|
|
class Jetpack extends Forge2DBlueprint {
|
|
|
|
|
|
|
|
/// {@macro spaceship}
|
|
|
|
|
|
|
|
Jetpack({required this.position});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// The [position] where the elements will be created
|
|
|
|
|
|
|
|
final Vector2 position;
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
void build(_) {
|
|
|
|
void build(_) {
|
|
|
|
final position = Vector2(
|
|
|
|
|
|
|
|
PinballGame.boardBounds.left + 40.5,
|
|
|
|
|
|
|
|
PinballGame.boardBounds.top - 31.5,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addAllContactCallback([
|
|
|
|
addAllContactCallback([
|
|
|
|
RampOpeningBallContactCallback<_JetpackRampOpening>(),
|
|
|
|
RampOpeningBallContactCallback<_JetpackRampOpening>(),
|
|
|
|
]);
|
|
|
|
]);
|
|
|
@ -24,23 +26,27 @@ class Jetpack extends Forge2DBlueprint {
|
|
|
|
final rightOpening = _JetpackRampOpening(
|
|
|
|
final rightOpening = _JetpackRampOpening(
|
|
|
|
rotation: math.pi,
|
|
|
|
rotation: math.pi,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
..initialPosition = position + Vector2(12.9, -20)
|
|
|
|
..initialPosition = position + Vector2(1.7, 19)
|
|
|
|
..layer = Layer.opening;
|
|
|
|
..layer = Layer.opening;
|
|
|
|
final leftOpening = _JetpackRampOpening(
|
|
|
|
final leftOpening = _JetpackRampOpening(
|
|
|
|
outsideLayer: Layer.spaceship,
|
|
|
|
outsideLayer: Layer.spaceship,
|
|
|
|
rotation: math.pi,
|
|
|
|
rotation: math.pi,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
..initialPosition = position + Vector2(-2.5, -20)
|
|
|
|
..initialPosition = position + Vector2(-13.7, 19)
|
|
|
|
..layer = Layer.jetpack;
|
|
|
|
..layer = Layer.jetpack;
|
|
|
|
|
|
|
|
|
|
|
|
final jetpackRamp = JetpackRamp()
|
|
|
|
final jetpackRamp = JetpackRamp()
|
|
|
|
..initialPosition = position + Vector2(5, -20.2)
|
|
|
|
..initialPosition = position
|
|
|
|
..layer = Layer.jetpack;
|
|
|
|
..layer = Layer.jetpack;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final baseRight = _JetpackBase()
|
|
|
|
|
|
|
|
..initialPosition = position + Vector2(1.7, 20);
|
|
|
|
|
|
|
|
|
|
|
|
addAll([
|
|
|
|
addAll([
|
|
|
|
rightOpening,
|
|
|
|
rightOpening,
|
|
|
|
leftOpening,
|
|
|
|
leftOpening,
|
|
|
|
jetpackRamp,
|
|
|
|
jetpackRamp,
|
|
|
|
|
|
|
|
baseRight,
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -49,36 +55,66 @@ 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: 2) {
|
|
|
|
JetpackRamp() : super(priority: 3) {
|
|
|
|
layer = Layer.jetpack;
|
|
|
|
layer = Layer.jetpack;
|
|
|
|
paint = Paint()
|
|
|
|
paint = Paint()
|
|
|
|
..color = const Color.fromARGB(255, 8, 218, 241)
|
|
|
|
..color = Color.fromARGB(255, 0, 217, 255)
|
|
|
|
..style = PaintingStyle.stroke;
|
|
|
|
..style = PaintingStyle.stroke;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Radius of the external arc.
|
|
|
|
|
|
|
|
static const _externalRadius = 18.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Width between walls of the ramp.
|
|
|
|
/// Width between walls of the ramp.
|
|
|
|
static const width = 5.0;
|
|
|
|
static const width = 5.0;
|
|
|
|
|
|
|
|
|
|
|
|
List<FixtureDef> _createFixtureDefs() {
|
|
|
|
List<FixtureDef> _createFixtureDefs() {
|
|
|
|
final fixturesDef = <FixtureDef>[];
|
|
|
|
final fixturesDef = <FixtureDef>[];
|
|
|
|
|
|
|
|
|
|
|
|
final externalCurveShape = ArcShape(
|
|
|
|
final innerLeftControlPoints = [
|
|
|
|
center: initialPosition,
|
|
|
|
Vector2(-24.73, 38),
|
|
|
|
arcRadius: _externalRadius,
|
|
|
|
Vector2(-26.3, 65.65),
|
|
|
|
angle: math.pi,
|
|
|
|
Vector2(-13.8, 65.65),
|
|
|
|
rotation: math.pi,
|
|
|
|
];
|
|
|
|
|
|
|
|
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 = [
|
|
|
|
|
|
|
|
Vector2(-30.95, 38),
|
|
|
|
|
|
|
|
Vector2(-33, 71.25),
|
|
|
|
|
|
|
|
Vector2(-14.2, 71.25),
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
final outerLeftCurveShape = BezierCurveShape(
|
|
|
|
|
|
|
|
controlPoints: outerLeftControlPoints,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
final externalFixtureDef = FixtureDef(externalCurveShape);
|
|
|
|
|
|
|
|
fixturesDef.add(externalFixtureDef);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final internalCurveShape = externalCurveShape.copyWith(
|
|
|
|
final outerLeftCurveFixtureDef = FixtureDef(outerLeftCurveShape);
|
|
|
|
arcRadius: _externalRadius - width,
|
|
|
|
fixturesDef.add(outerLeftCurveFixtureDef);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final outerRightControlPoints = [
|
|
|
|
|
|
|
|
outerLeftControlPoints.last,
|
|
|
|
|
|
|
|
Vector2(4.7, 71.25),
|
|
|
|
|
|
|
|
Vector2(6.3, 40.1),
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
final outerRightCurveShape = BezierCurveShape(
|
|
|
|
|
|
|
|
controlPoints: outerRightControlPoints,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
final internalFixtureDef = FixtureDef(internalCurveShape);
|
|
|
|
|
|
|
|
fixturesDef.add(internalFixtureDef);
|
|
|
|
final outerRightCurveFixtureDef = FixtureDef(outerRightCurveShape);
|
|
|
|
|
|
|
|
fixturesDef.add(outerRightCurveFixtureDef);
|
|
|
|
|
|
|
|
|
|
|
|
return fixturesDef;
|
|
|
|
return fixturesDef;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -94,6 +130,79 @@ class JetpackRamp extends BodyComponent with InitialPosition, Layered {
|
|
|
|
|
|
|
|
|
|
|
|
return body;
|
|
|
|
return body;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
|
|
|
|
await super.onLoad();
|
|
|
|
|
|
|
|
//await _loadBackground();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _loadBackground() async {
|
|
|
|
|
|
|
|
final spriteRamp = await gameRef.loadSprite(
|
|
|
|
|
|
|
|
Assets.images.components.spaceshipRamp.path,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final spriteRampComponent = SpriteComponent(
|
|
|
|
|
|
|
|
sprite: spriteRamp,
|
|
|
|
|
|
|
|
size: Vector2(38.1, 33.8),
|
|
|
|
|
|
|
|
anchor: Anchor.center,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
..position = Vector2(-12.2, -53.5)
|
|
|
|
|
|
|
|
..priority = 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final spriteRailingBg = await gameRef.loadSprite(
|
|
|
|
|
|
|
|
Assets.images.components.spaceshipRailingBg.path,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
final spriteRailingBgComponent = SpriteComponent(
|
|
|
|
|
|
|
|
sprite: spriteRailingBg,
|
|
|
|
|
|
|
|
size: Vector2(38.3, 35.1),
|
|
|
|
|
|
|
|
anchor: Anchor.center,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
..position = spriteRampComponent.position + Vector2(0, -1)
|
|
|
|
|
|
|
|
..priority = 3;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final spriteRailingFg = await gameRef.loadSprite(
|
|
|
|
|
|
|
|
Assets.images.components.spaceshipRailingFg.path,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
final spriteRailingFgComponent = SpriteComponent(
|
|
|
|
|
|
|
|
sprite: spriteRailingFg,
|
|
|
|
|
|
|
|
size: Vector2(26.1, 28.3),
|
|
|
|
|
|
|
|
anchor: Anchor.center,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
..position = spriteRampComponent.position + Vector2(0, 1)
|
|
|
|
|
|
|
|
..priority = 5;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await add(spriteRailingBgComponent);
|
|
|
|
|
|
|
|
await add(spriteRampComponent);
|
|
|
|
|
|
|
|
await add(spriteRailingFgComponent);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _JetpackBase extends BodyComponent with InitialPosition, Layered {
|
|
|
|
|
|
|
|
_JetpackBase() {
|
|
|
|
|
|
|
|
layer = Layer.board;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
Body createBody() {
|
|
|
|
|
|
|
|
renderBody = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final baseShape = BezierCurveShape(
|
|
|
|
|
|
|
|
controlPoints: [
|
|
|
|
|
|
|
|
Vector2(initialPosition.x - 3, initialPosition.y),
|
|
|
|
|
|
|
|
Vector2(initialPosition.x - 3, initialPosition.y) + Vector2(2, 2),
|
|
|
|
|
|
|
|
Vector2(initialPosition.x + 3, initialPosition.y) + Vector2(-2, 2),
|
|
|
|
|
|
|
|
Vector2(initialPosition.x + 3, initialPosition.y)
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
final fixtureDef = FixtureDef(baseShape);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final bodyDef = BodyDef()
|
|
|
|
|
|
|
|
..userData = this
|
|
|
|
|
|
|
|
..position = initialPosition;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return world.createBody(bodyDef)..createFixture(fixtureDef);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// {@template jetpack_ramp_opening}
|
|
|
|
/// {@template jetpack_ramp_opening}
|
|
|
@ -110,6 +219,7 @@ class _JetpackRampOpening extends RampOpening {
|
|
|
|
pathwayLayer: Layer.jetpack,
|
|
|
|
pathwayLayer: Layer.jetpack,
|
|
|
|
outsideLayer: outsideLayer,
|
|
|
|
outsideLayer: outsideLayer,
|
|
|
|
orientation: RampOrientation.down,
|
|
|
|
orientation: RampOrientation.down,
|
|
|
|
|
|
|
|
pathwayPriority: 4,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
final double _rotation;
|
|
|
|
final double _rotation;
|
|
|
@ -117,7 +227,9 @@ class _JetpackRampOpening extends RampOpening {
|
|
|
|
static final Vector2 _size = Vector2(JetpackRamp.width / 4, .1);
|
|
|
|
static final Vector2 _size = Vector2(JetpackRamp.width / 4, .1);
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Shape get shape => PolygonShape()
|
|
|
|
Shape get shape {
|
|
|
|
|
|
|
|
renderBody = false;
|
|
|
|
|
|
|
|
return PolygonShape()
|
|
|
|
..setAsBox(
|
|
|
|
..setAsBox(
|
|
|
|
_size.x,
|
|
|
|
_size.x,
|
|
|
|
_size.y,
|
|
|
|
_size.y,
|
|
|
@ -125,3 +237,4 @@ class _JetpackRampOpening extends RampOpening {
|
|
|
|
_rotation,
|
|
|
|
_rotation,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|