|
|
|
@ -2,88 +2,71 @@ import 'dart:math' as math;
|
|
|
|
|
|
|
|
|
|
import 'package:flame/components.dart';
|
|
|
|
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
|
|
|
import 'package:pinball_components/gen/assets.gen.dart';
|
|
|
|
|
import 'package:pinball_components/pinball_components.dart' hide Assets;
|
|
|
|
|
import 'package:pinball_components/pinball_components.dart';
|
|
|
|
|
import 'package:pinball_flame/pinball_flame.dart';
|
|
|
|
|
|
|
|
|
|
/// {@template spaceship_rail}
|
|
|
|
|
/// A [Blueprint] for the spaceship drop tube.
|
|
|
|
|
/// A [Blueprint] for the rail exiting the [Spaceship].
|
|
|
|
|
/// {@endtemplate}
|
|
|
|
|
class SpaceshipRail extends Blueprint {
|
|
|
|
|
/// {@macro spaceship_rail}
|
|
|
|
|
SpaceshipRail()
|
|
|
|
|
: super(
|
|
|
|
|
components: [
|
|
|
|
|
_SpaceshipRailRamp(),
|
|
|
|
|
_SpaceshipRail(),
|
|
|
|
|
_SpaceshipRailExit(),
|
|
|
|
|
_SpaceshipRailBase(radius: 0.55)
|
|
|
|
|
..initialPosition = Vector2(-26.15, -18.65),
|
|
|
|
|
_SpaceshipRailBase(radius: 0.8)
|
|
|
|
|
..initialPosition = Vector2(-25.5, 12.9),
|
|
|
|
|
_SpaceshipRailForeground()
|
|
|
|
|
_SpaceshipRailExitSpriteComponent()
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _SpaceshipRailRamp extends BodyComponent with Layered {
|
|
|
|
|
_SpaceshipRailRamp()
|
|
|
|
|
class _SpaceshipRail extends BodyComponent with Layered {
|
|
|
|
|
_SpaceshipRail()
|
|
|
|
|
: super(
|
|
|
|
|
priority: RenderPriority.spaceshipRail,
|
|
|
|
|
children: [_SpaceshipRailSpriteComponent()],
|
|
|
|
|
renderBody: false,
|
|
|
|
|
children: [_SpaceshipRailRampSpriteComponent()],
|
|
|
|
|
) {
|
|
|
|
|
layer = Layer.spaceshipExitRail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<FixtureDef> _createFixtureDefs() {
|
|
|
|
|
final fixturesDefs = <FixtureDef>[];
|
|
|
|
|
|
|
|
|
|
final topArcShape = ArcShape(
|
|
|
|
|
center: Vector2(-35.5, -30.9),
|
|
|
|
|
center: Vector2(-35.1, -30.9),
|
|
|
|
|
arcRadius: 2.5,
|
|
|
|
|
angle: math.pi,
|
|
|
|
|
rotation: 0.2,
|
|
|
|
|
);
|
|
|
|
|
final topArcFixtureDef = FixtureDef(topArcShape);
|
|
|
|
|
fixturesDefs.add(topArcFixtureDef);
|
|
|
|
|
|
|
|
|
|
final topLeftCurveShape = BezierCurveShape(
|
|
|
|
|
controlPoints: [
|
|
|
|
|
Vector2(-37.9, -30.4),
|
|
|
|
|
Vector2(-38, -23.9),
|
|
|
|
|
Vector2(-37.6, -30.4),
|
|
|
|
|
Vector2(-37.8, -23.9),
|
|
|
|
|
Vector2(-30.93, -18.2),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
final topLeftCurveFixtureDef = FixtureDef(topLeftCurveShape);
|
|
|
|
|
fixturesDefs.add(topLeftCurveFixtureDef);
|
|
|
|
|
|
|
|
|
|
final middleLeftCurveShape = BezierCurveShape(
|
|
|
|
|
controlPoints: [
|
|
|
|
|
topLeftCurveShape.vertices.last,
|
|
|
|
|
Vector2(-22.6, -10.3),
|
|
|
|
|
Vector2(-30, -0.2),
|
|
|
|
|
Vector2(-29.5, -0.2),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
final middleLeftCurveFixtureDef = FixtureDef(middleLeftCurveShape);
|
|
|
|
|
fixturesDefs.add(middleLeftCurveFixtureDef);
|
|
|
|
|
|
|
|
|
|
final bottomLeftCurveShape = BezierCurveShape(
|
|
|
|
|
controlPoints: [
|
|
|
|
|
middleLeftCurveShape.vertices.last,
|
|
|
|
|
Vector2(-36, 8.6),
|
|
|
|
|
Vector2(-32.04, 18.3),
|
|
|
|
|
Vector2(-35.6, 8.6),
|
|
|
|
|
Vector2(-31.3, 18.3),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
final bottomLeftCurveFixtureDef = FixtureDef(bottomLeftCurveShape);
|
|
|
|
|
fixturesDefs.add(bottomLeftCurveFixtureDef);
|
|
|
|
|
|
|
|
|
|
final topRightStraightShape = EdgeShape()
|
|
|
|
|
..set(
|
|
|
|
|
Vector2(-33, -31.3),
|
|
|
|
|
Vector2(-27.2, -21.3),
|
|
|
|
|
Vector2(-33, -31.3),
|
|
|
|
|
);
|
|
|
|
|
final topRightStraightFixtureDef = FixtureDef(topRightStraightShape);
|
|
|
|
|
fixturesDefs.add(topRightStraightFixtureDef);
|
|
|
|
|
|
|
|
|
|
final middleRightCurveShape = BezierCurveShape(
|
|
|
|
|
controlPoints: [
|
|
|
|
@ -92,8 +75,6 @@ class _SpaceshipRailRamp extends BodyComponent with Layered {
|
|
|
|
|
Vector2(-25.29, 1.7),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
final middleRightCurveFixtureDef = FixtureDef(middleRightCurveShape);
|
|
|
|
|
fixturesDefs.add(middleRightCurveFixtureDef);
|
|
|
|
|
|
|
|
|
|
final bottomRightCurveShape = BezierCurveShape(
|
|
|
|
|
controlPoints: [
|
|
|
|
@ -102,10 +83,16 @@ class _SpaceshipRailRamp extends BodyComponent with Layered {
|
|
|
|
|
Vector2(-26.8, 15.7),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
final bottomRightCurveFixtureDef = FixtureDef(bottomRightCurveShape);
|
|
|
|
|
fixturesDefs.add(bottomRightCurveFixtureDef);
|
|
|
|
|
|
|
|
|
|
return fixturesDefs;
|
|
|
|
|
return [
|
|
|
|
|
FixtureDef(topArcShape),
|
|
|
|
|
FixtureDef(topLeftCurveShape),
|
|
|
|
|
FixtureDef(middleLeftCurveShape),
|
|
|
|
|
FixtureDef(bottomLeftCurveShape),
|
|
|
|
|
FixtureDef(topRightStraightShape),
|
|
|
|
|
FixtureDef(middleRightCurveShape),
|
|
|
|
|
FixtureDef(bottomRightCurveShape),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@ -116,55 +103,47 @@ class _SpaceshipRailRamp extends BodyComponent with Layered {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _SpaceshipRailRampSpriteComponent extends SpriteComponent
|
|
|
|
|
with HasGameRef {
|
|
|
|
|
class _SpaceshipRailSpriteComponent extends SpriteComponent with HasGameRef {
|
|
|
|
|
_SpaceshipRailSpriteComponent()
|
|
|
|
|
: super(
|
|
|
|
|
anchor: Anchor.center,
|
|
|
|
|
position: Vector2(-29.4, -5.7),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
|
await super.onLoad();
|
|
|
|
|
|
|
|
|
|
final sprite = await gameRef.loadSprite(
|
|
|
|
|
final sprite = Sprite(
|
|
|
|
|
gameRef.images.fromCache(
|
|
|
|
|
Assets.images.spaceship.rail.main.keyName,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
this.sprite = sprite;
|
|
|
|
|
size = sprite.originalSize / 10;
|
|
|
|
|
anchor = Anchor.center;
|
|
|
|
|
position = Vector2(-29.4, -5.7);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _SpaceshipRailForeground extends SpriteComponent with HasGameRef {
|
|
|
|
|
_SpaceshipRailForeground()
|
|
|
|
|
: super(priority: RenderPriority.spaceshipRailForeground);
|
|
|
|
|
class _SpaceshipRailExitSpriteComponent extends SpriteComponent
|
|
|
|
|
with HasGameRef {
|
|
|
|
|
_SpaceshipRailExitSpriteComponent()
|
|
|
|
|
: super(
|
|
|
|
|
anchor: Anchor.center,
|
|
|
|
|
position: Vector2(-28, 19.4),
|
|
|
|
|
priority: RenderPriority.spaceshipRailExit,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
|
await super.onLoad();
|
|
|
|
|
|
|
|
|
|
final sprite = await gameRef.loadSprite(
|
|
|
|
|
Assets.images.spaceship.rail.foreground.keyName,
|
|
|
|
|
final sprite = Sprite(
|
|
|
|
|
gameRef.images.fromCache(
|
|
|
|
|
Assets.images.spaceship.rail.exit.keyName,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
this.sprite = sprite;
|
|
|
|
|
size = sprite.originalSize / 10;
|
|
|
|
|
anchor = Anchor.center;
|
|
|
|
|
position = Vector2(-28.5, 19.7);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Represents the ground bases of the [_SpaceshipRailRamp].
|
|
|
|
|
class _SpaceshipRailBase extends BodyComponent with InitialPosition {
|
|
|
|
|
_SpaceshipRailBase({required this.radius}) : super(renderBody: false);
|
|
|
|
|
|
|
|
|
|
final double radius;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Body createBody() {
|
|
|
|
|
final shape = CircleShape()..radius = radius;
|
|
|
|
|
final fixtureDef = FixtureDef(shape);
|
|
|
|
|
final bodyDef = BodyDef(
|
|
|
|
|
position: initialPosition,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return world.createBody(bodyDef)..createFixture(fixtureDef);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|