|
|
@ -2,45 +2,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
import 'dart:math' as math;
|
|
|
|
import 'dart:math' as math;
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const int ballPriorityInsideRamp = 4;
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
void build(_) {
|
|
|
|
void build(_) {
|
|
|
|
final position = Vector2(
|
|
|
|
|
|
|
|
BoardDimensions.bounds.left + 40.5,
|
|
|
|
|
|
|
|
BoardDimensions.bounds.top - 31.5,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addAllContactCallback([
|
|
|
|
addAllContactCallback([
|
|
|
|
RampOpeningBallContactCallback<_JetpackRampOpening>(),
|
|
|
|
RampOpeningBallContactCallback<_JetpackRampOpening>(),
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
final rightOpening = _JetpackRampOpening(
|
|
|
|
final rightOpening = _JetpackRampOpening(
|
|
|
|
|
|
|
|
// TODO(ruimiguel): set Board priority when defined.
|
|
|
|
|
|
|
|
outsidePriority: 1,
|
|
|
|
rotation: math.pi,
|
|
|
|
rotation: math.pi,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
..initialPosition = position + Vector2(12.9, -20)
|
|
|
|
..initialPosition = Vector2(1.7, 19)
|
|
|
|
..layer = Layer.opening;
|
|
|
|
..layer = Layer.opening;
|
|
|
|
final leftOpening = _JetpackRampOpening(
|
|
|
|
final leftOpening = _JetpackRampOpening(
|
|
|
|
outsideLayer: Layer.spaceship,
|
|
|
|
outsideLayer: Layer.spaceship,
|
|
|
|
|
|
|
|
outsidePriority: Spaceship.ballPriorityWhenOnSpaceship,
|
|
|
|
rotation: math.pi,
|
|
|
|
rotation: math.pi,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
..initialPosition = position + Vector2(-2.5, -20)
|
|
|
|
..initialPosition = Vector2(-13.7, 19)
|
|
|
|
..layer = Layer.jetpack;
|
|
|
|
..layer = Layer.jetpack;
|
|
|
|
|
|
|
|
|
|
|
|
final jetpackRamp = JetpackRamp()
|
|
|
|
final jetpackRamp = JetpackRamp();
|
|
|
|
..initialPosition = position + Vector2(5, -20.2)
|
|
|
|
|
|
|
|
..layer = Layer.jetpack;
|
|
|
|
final jetpackRampWallFg = _JetpackRampForegroundRailing();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final baseRight = _JetpackBase()..initialPosition = Vector2(1.7, 20);
|
|
|
|
|
|
|
|
|
|
|
|
addAll([
|
|
|
|
addAll([
|
|
|
|
rightOpening,
|
|
|
|
rightOpening,
|
|
|
|
leftOpening,
|
|
|
|
leftOpening,
|
|
|
|
|
|
|
|
baseRight,
|
|
|
|
jetpackRamp,
|
|
|
|
jetpackRamp,
|
|
|
|
|
|
|
|
jetpackRampWallFg,
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -49,42 +56,45 @@ 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: Jetpack.ballPriorityInsideRamp - 1) {
|
|
|
|
layer = Layer.jetpack;
|
|
|
|
layer = Layer.jetpack;
|
|
|
|
paint = Paint()
|
|
|
|
|
|
|
|
..color = const Color.fromARGB(255, 8, 218, 241)
|
|
|
|
|
|
|
|
..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 outerLeftCurveShape = BezierCurveShape(
|
|
|
|
center: initialPosition,
|
|
|
|
controlPoints: [
|
|
|
|
arcRadius: _externalRadius,
|
|
|
|
Vector2(-30.95, 38),
|
|
|
|
angle: math.pi,
|
|
|
|
Vector2(-32.5, 71.25),
|
|
|
|
rotation: math.pi,
|
|
|
|
Vector2(-14.2, 71.25),
|
|
|
|
|
|
|
|
],
|
|
|
|
);
|
|
|
|
);
|
|
|
|
final externalFixtureDef = FixtureDef(externalCurveShape);
|
|
|
|
|
|
|
|
fixturesDef.add(externalFixtureDef);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final internalCurveShape = externalCurveShape.copyWith(
|
|
|
|
final outerLeftCurveFixtureDef = FixtureDef(outerLeftCurveShape);
|
|
|
|
arcRadius: _externalRadius - width,
|
|
|
|
fixturesDef.add(outerLeftCurveFixtureDef);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final outerRightCurveShape = BezierCurveShape(
|
|
|
|
|
|
|
|
controlPoints: [
|
|
|
|
|
|
|
|
outerLeftCurveShape.vertices.last,
|
|
|
|
|
|
|
|
Vector2(4.7, 71.25),
|
|
|
|
|
|
|
|
Vector2(6.3, 40),
|
|
|
|
|
|
|
|
],
|
|
|
|
);
|
|
|
|
);
|
|
|
|
final internalFixtureDef = FixtureDef(internalCurveShape);
|
|
|
|
|
|
|
|
fixturesDef.add(internalFixtureDef);
|
|
|
|
final outerRightCurveFixtureDef = FixtureDef(outerRightCurveShape);
|
|
|
|
|
|
|
|
fixturesDef.add(outerRightCurveFixtureDef);
|
|
|
|
|
|
|
|
|
|
|
|
return fixturesDef;
|
|
|
|
return fixturesDef;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Body createBody() {
|
|
|
|
Body createBody() {
|
|
|
|
|
|
|
|
renderBody = false;
|
|
|
|
|
|
|
|
|
|
|
|
final bodyDef = BodyDef()
|
|
|
|
final bodyDef = BodyDef()
|
|
|
|
..userData = this
|
|
|
|
..userData = this
|
|
|
|
..position = initialPosition;
|
|
|
|
..position = initialPosition;
|
|
|
@ -94,6 +104,140 @@ class JetpackRamp extends BodyComponent with InitialPosition, Layered {
|
|
|
|
|
|
|
|
|
|
|
|
return body;
|
|
|
|
return body;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
|
|
|
|
await super.onLoad();
|
|
|
|
|
|
|
|
await _loadSprites();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _loadSprites() 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),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await addAll([
|
|
|
|
|
|
|
|
spriteRailingBgComponent,
|
|
|
|
|
|
|
|
spriteRampComponent,
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _JetpackRampForegroundRailing extends BodyComponent
|
|
|
|
|
|
|
|
with InitialPosition, Layered {
|
|
|
|
|
|
|
|
_JetpackRampForegroundRailing()
|
|
|
|
|
|
|
|
: super(priority: Jetpack.ballPriorityInsideRamp + 1) {
|
|
|
|
|
|
|
|
layer = Layer.jetpack;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<FixtureDef> _createFixtureDefs() {
|
|
|
|
|
|
|
|
final fixturesDef = <FixtureDef>[];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final innerLeftCurveShape = BezierCurveShape(
|
|
|
|
|
|
|
|
controlPoints: [
|
|
|
|
|
|
|
|
Vector2(-24.5, 38),
|
|
|
|
|
|
|
|
Vector2(-26.3, 64),
|
|
|
|
|
|
|
|
Vector2(-13.8, 64.5),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final innerLeftCurveFixtureDef = FixtureDef(innerLeftCurveShape);
|
|
|
|
|
|
|
|
fixturesDef.add(innerLeftCurveFixtureDef);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final innerRightCurveShape = BezierCurveShape(
|
|
|
|
|
|
|
|
controlPoints: [
|
|
|
|
|
|
|
|
innerLeftCurveShape.vertices.last,
|
|
|
|
|
|
|
|
Vector2(-1, 64.5),
|
|
|
|
|
|
|
|
Vector2(0.1, 39.5),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 _loadSprites();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _loadSprites() async {
|
|
|
|
|
|
|
|
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: Vector2(-12.2, -52.5),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await add(spriteRailingFgComponent);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _JetpackBase extends BodyComponent with InitialPosition, Layered {
|
|
|
|
|
|
|
|
_JetpackBase() {
|
|
|
|
|
|
|
|
layer = Layer.board;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
Body createBody() {
|
|
|
|
|
|
|
|
renderBody = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const baseWidth = 6;
|
|
|
|
|
|
|
|
final baseShape = BezierCurveShape(
|
|
|
|
|
|
|
|
controlPoints: [
|
|
|
|
|
|
|
|
Vector2(initialPosition.x - baseWidth / 2, initialPosition.y),
|
|
|
|
|
|
|
|
Vector2(initialPosition.x - baseWidth / 2, initialPosition.y) +
|
|
|
|
|
|
|
|
Vector2(2, 2),
|
|
|
|
|
|
|
|
Vector2(initialPosition.x + baseWidth / 2, initialPosition.y) +
|
|
|
|
|
|
|
|
Vector2(-2, 2),
|
|
|
|
|
|
|
|
Vector2(initialPosition.x + baseWidth / 2, 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}
|
|
|
@ -104,12 +248,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(
|
|
|
|
insideLayer: Layer.jetpack,
|
|
|
|
insideLayer: Layer.jetpack,
|
|
|
|
outsideLayer: outsideLayer,
|
|
|
|
outsideLayer: outsideLayer,
|
|
|
|
orientation: RampOrientation.down,
|
|
|
|
orientation: RampOrientation.down,
|
|
|
|
|
|
|
|
insidePriority: Jetpack.ballPriorityInsideRamp,
|
|
|
|
|
|
|
|
outsidePriority: outsidePriority,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
final double _rotation;
|
|
|
|
final double _rotation;
|
|
|
@ -117,7 +264,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 +274,4 @@ class _JetpackRampOpening extends RampOpening {
|
|
|
|
_rotation,
|
|
|
|
_rotation,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|