@ -1,13 +1,8 @@
|
|||||||
export 'board.dart';
|
export 'board.dart';
|
||||||
export 'bonus_word.dart';
|
export 'bonus_word.dart';
|
||||||
export 'chrome_dino.dart';
|
|
||||||
export 'controlled_ball.dart';
|
export 'controlled_ball.dart';
|
||||||
export 'flipper_controller.dart';
|
export 'controlled_flipper.dart';
|
||||||
export 'flutter_forest.dart';
|
export 'flutter_forest.dart';
|
||||||
export 'jetpack_ramp.dart';
|
|
||||||
export 'kicker.dart';
|
|
||||||
export 'launcher_ramp.dart';
|
|
||||||
export 'plunger.dart';
|
export 'plunger.dart';
|
||||||
export 'score_points.dart';
|
export 'score_points.dart';
|
||||||
export 'spaceship_exit_rail.dart';
|
|
||||||
export 'wall.dart';
|
export 'wall.dart';
|
||||||
|
@ -1,127 +0,0 @@
|
|||||||
// ignore_for_file: public_member_api_docs, avoid_renaming_method_parameters
|
|
||||||
|
|
||||||
import 'dart:math' as math;
|
|
||||||
|
|
||||||
import 'package:flame/extensions.dart';
|
|
||||||
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:pinball/game/game.dart';
|
|
||||||
import 'package:pinball_components/pinball_components.dart';
|
|
||||||
|
|
||||||
/// A [Blueprint] which creates the [JetpackRamp].
|
|
||||||
class Jetpack extends Forge2DBlueprint {
|
|
||||||
@override
|
|
||||||
void build(_) {
|
|
||||||
final position = Vector2(
|
|
||||||
BoardDimensions.bounds.left + 40.5,
|
|
||||||
BoardDimensions.bounds.top - 31.5,
|
|
||||||
);
|
|
||||||
|
|
||||||
addAllContactCallback([
|
|
||||||
RampOpeningBallContactCallback<_JetpackRampOpening>(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
final rightOpening = _JetpackRampOpening(
|
|
||||||
rotation: math.pi,
|
|
||||||
)
|
|
||||||
..initialPosition = position + Vector2(12.9, -20)
|
|
||||||
..layer = Layer.opening;
|
|
||||||
final leftOpening = _JetpackRampOpening(
|
|
||||||
outsideLayer: Layer.spaceship,
|
|
||||||
rotation: math.pi,
|
|
||||||
)
|
|
||||||
..initialPosition = position + Vector2(-2.5, -20)
|
|
||||||
..layer = Layer.jetpack;
|
|
||||||
|
|
||||||
final jetpackRamp = JetpackRamp()
|
|
||||||
..initialPosition = position + Vector2(5, -20.2)
|
|
||||||
..layer = Layer.jetpack;
|
|
||||||
|
|
||||||
addAll([
|
|
||||||
rightOpening,
|
|
||||||
leftOpening,
|
|
||||||
jetpackRamp,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// {@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;
|
|
||||||
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.
|
|
||||||
static const width = 5.0;
|
|
||||||
|
|
||||||
List<FixtureDef> _createFixtureDefs() {
|
|
||||||
final fixturesDef = <FixtureDef>[];
|
|
||||||
|
|
||||||
final externalCurveShape = ArcShape(
|
|
||||||
center: initialPosition,
|
|
||||||
arcRadius: _externalRadius,
|
|
||||||
angle: math.pi,
|
|
||||||
rotation: math.pi,
|
|
||||||
);
|
|
||||||
final externalFixtureDef = FixtureDef(externalCurveShape);
|
|
||||||
fixturesDef.add(externalFixtureDef);
|
|
||||||
|
|
||||||
final internalCurveShape = externalCurveShape.copyWith(
|
|
||||||
arcRadius: _externalRadius - width,
|
|
||||||
);
|
|
||||||
final internalFixtureDef = FixtureDef(internalCurveShape);
|
|
||||||
fixturesDef.add(internalFixtureDef);
|
|
||||||
|
|
||||||
return fixturesDef;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Body createBody() {
|
|
||||||
final bodyDef = BodyDef()
|
|
||||||
..userData = this
|
|
||||||
..position = initialPosition;
|
|
||||||
|
|
||||||
final body = world.createBody(bodyDef);
|
|
||||||
_createFixtureDefs().forEach(body.createFixture);
|
|
||||||
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// {@template jetpack_ramp_opening}
|
|
||||||
/// [RampOpening] with [Layer.jetpack] to filter [Ball] collisions
|
|
||||||
/// inside [JetpackRamp].
|
|
||||||
/// {@endtemplate}
|
|
||||||
class _JetpackRampOpening extends RampOpening {
|
|
||||||
/// {@macro jetpack_ramp_opening}
|
|
||||||
_JetpackRampOpening({
|
|
||||||
Layer? outsideLayer,
|
|
||||||
required double rotation,
|
|
||||||
}) : _rotation = rotation,
|
|
||||||
super(
|
|
||||||
insideLayer: Layer.jetpack,
|
|
||||||
outsideLayer: outsideLayer,
|
|
||||||
orientation: RampOrientation.down,
|
|
||||||
);
|
|
||||||
|
|
||||||
final double _rotation;
|
|
||||||
|
|
||||||
static final Vector2 _size = Vector2(JetpackRamp.width / 4, .1);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Shape get shape => PolygonShape()
|
|
||||||
..setAsBox(
|
|
||||||
_size.x,
|
|
||||||
_size.y,
|
|
||||||
initialPosition,
|
|
||||||
_rotation,
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,198 +0,0 @@
|
|||||||
// ignore_for_file: avoid_renaming_method_parameters
|
|
||||||
|
|
||||||
import 'dart:math' as math;
|
|
||||||
import 'dart:ui';
|
|
||||||
|
|
||||||
import 'package:flame/extensions.dart';
|
|
||||||
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
||||||
import 'package:pinball_components/pinball_components.dart' hide Assets;
|
|
||||||
|
|
||||||
/// {@template spaceship_exit_rail}
|
|
||||||
/// A [Blueprint] for the spaceship drop tube.
|
|
||||||
/// {@endtemplate}
|
|
||||||
class SpaceshipExitRail extends Forge2DBlueprint {
|
|
||||||
/// {@macro spaceship_exit_rail}
|
|
||||||
SpaceshipExitRail({required this.position});
|
|
||||||
|
|
||||||
/// The [position] where the elements will be created
|
|
||||||
final Vector2 position;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void build(_) {
|
|
||||||
addAllContactCallback([
|
|
||||||
SpaceshipExitRailEndBallContactCallback(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
final spaceshipExitRailRamp = _SpaceshipExitRailRamp()
|
|
||||||
..initialPosition = position;
|
|
||||||
final exitRail = SpaceshipExitRailEnd()
|
|
||||||
..initialPosition = position + _SpaceshipExitRailRamp.exitPoint;
|
|
||||||
|
|
||||||
addAll([
|
|
||||||
spaceshipExitRailRamp,
|
|
||||||
exitRail,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _SpaceshipExitRailRamp extends BodyComponent
|
|
||||||
with InitialPosition, Layered {
|
|
||||||
_SpaceshipExitRailRamp() : super(priority: 2) {
|
|
||||||
layer = Layer.spaceshipExitRail;
|
|
||||||
// TODO(ruimiguel): remove color once asset is placed.
|
|
||||||
paint = Paint()
|
|
||||||
..color = const Color.fromARGB(255, 249, 65, 3)
|
|
||||||
..style = PaintingStyle.stroke;
|
|
||||||
}
|
|
||||||
|
|
||||||
static final exitPoint = Vector2(9.2, -48.5);
|
|
||||||
|
|
||||||
List<FixtureDef> _createFixtureDefs() {
|
|
||||||
const entranceRotationAngle = 175 * math.pi / 180;
|
|
||||||
const curveRotationAngle = 275 * math.pi / 180;
|
|
||||||
const exitRotationAngle = 340 * math.pi / 180;
|
|
||||||
const width = 5.5;
|
|
||||||
|
|
||||||
final fixturesDefs = <FixtureDef>[];
|
|
||||||
|
|
||||||
final entranceWall = ArcShape(
|
|
||||||
center: Vector2(width / 2, 0),
|
|
||||||
arcRadius: width / 2,
|
|
||||||
angle: math.pi,
|
|
||||||
rotation: entranceRotationAngle,
|
|
||||||
);
|
|
||||||
final entranceFixtureDef = FixtureDef(entranceWall);
|
|
||||||
fixturesDefs.add(entranceFixtureDef);
|
|
||||||
|
|
||||||
final topLeftControlPoints = [
|
|
||||||
Vector2(0, 0),
|
|
||||||
Vector2(10, .5),
|
|
||||||
Vector2(7, 4),
|
|
||||||
Vector2(15.5, 8.3),
|
|
||||||
];
|
|
||||||
final topLeftCurveShape = BezierCurveShape(
|
|
||||||
controlPoints: topLeftControlPoints,
|
|
||||||
)..rotate(curveRotationAngle);
|
|
||||||
final topLeftFixtureDef = FixtureDef(topLeftCurveShape);
|
|
||||||
fixturesDefs.add(topLeftFixtureDef);
|
|
||||||
|
|
||||||
final topRightControlPoints = [
|
|
||||||
Vector2(0, width),
|
|
||||||
Vector2(10, 6.5),
|
|
||||||
Vector2(7, 10),
|
|
||||||
Vector2(15.5, 13.2),
|
|
||||||
];
|
|
||||||
final topRightCurveShape = BezierCurveShape(
|
|
||||||
controlPoints: topRightControlPoints,
|
|
||||||
)..rotate(curveRotationAngle);
|
|
||||||
final topRightFixtureDef = FixtureDef(topRightCurveShape);
|
|
||||||
fixturesDefs.add(topRightFixtureDef);
|
|
||||||
|
|
||||||
final mediumLeftControlPoints = [
|
|
||||||
topLeftControlPoints.last,
|
|
||||||
Vector2(21, 12.9),
|
|
||||||
Vector2(30, 7.1),
|
|
||||||
Vector2(32, 4.8),
|
|
||||||
];
|
|
||||||
final mediumLeftCurveShape = BezierCurveShape(
|
|
||||||
controlPoints: mediumLeftControlPoints,
|
|
||||||
)..rotate(curveRotationAngle);
|
|
||||||
final mediumLeftFixtureDef = FixtureDef(mediumLeftCurveShape);
|
|
||||||
fixturesDefs.add(mediumLeftFixtureDef);
|
|
||||||
|
|
||||||
final mediumRightControlPoints = [
|
|
||||||
topRightControlPoints.last,
|
|
||||||
Vector2(21, 17.2),
|
|
||||||
Vector2(30, 12.1),
|
|
||||||
Vector2(32, 10.2),
|
|
||||||
];
|
|
||||||
final mediumRightCurveShape = BezierCurveShape(
|
|
||||||
controlPoints: mediumRightControlPoints,
|
|
||||||
)..rotate(curveRotationAngle);
|
|
||||||
final mediumRightFixtureDef = FixtureDef(mediumRightCurveShape);
|
|
||||||
fixturesDefs.add(mediumRightFixtureDef);
|
|
||||||
|
|
||||||
final bottomLeftControlPoints = [
|
|
||||||
mediumLeftControlPoints.last,
|
|
||||||
Vector2(40, -1),
|
|
||||||
Vector2(48, 1.9),
|
|
||||||
Vector2(50.5, 2.5),
|
|
||||||
];
|
|
||||||
final bottomLeftCurveShape = BezierCurveShape(
|
|
||||||
controlPoints: bottomLeftControlPoints,
|
|
||||||
)..rotate(curveRotationAngle);
|
|
||||||
final bottomLeftFixtureDef = FixtureDef(bottomLeftCurveShape);
|
|
||||||
fixturesDefs.add(bottomLeftFixtureDef);
|
|
||||||
|
|
||||||
final bottomRightControlPoints = [
|
|
||||||
mediumRightControlPoints.last,
|
|
||||||
Vector2(40, 4),
|
|
||||||
Vector2(46, 6.5),
|
|
||||||
Vector2(48.8, 7.6),
|
|
||||||
];
|
|
||||||
final bottomRightCurveShape = BezierCurveShape(
|
|
||||||
controlPoints: bottomRightControlPoints,
|
|
||||||
)..rotate(curveRotationAngle);
|
|
||||||
final bottomRightFixtureDef = FixtureDef(bottomRightCurveShape);
|
|
||||||
fixturesDefs.add(bottomRightFixtureDef);
|
|
||||||
|
|
||||||
final exitWall = ArcShape(
|
|
||||||
center: exitPoint,
|
|
||||||
arcRadius: width / 2,
|
|
||||||
angle: math.pi,
|
|
||||||
rotation: exitRotationAngle,
|
|
||||||
);
|
|
||||||
final exitFixtureDef = FixtureDef(exitWall);
|
|
||||||
fixturesDefs.add(exitFixtureDef);
|
|
||||||
|
|
||||||
return fixturesDefs;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Body createBody() {
|
|
||||||
final bodyDef = BodyDef()
|
|
||||||
..userData = this
|
|
||||||
..position = initialPosition;
|
|
||||||
|
|
||||||
final body = world.createBody(bodyDef);
|
|
||||||
_createFixtureDefs().forEach(body.createFixture);
|
|
||||||
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// {@template spaceship_exit_rail_end}
|
|
||||||
/// A sensor [BodyComponent] responsible for sending the [Ball]
|
|
||||||
/// back to the board.
|
|
||||||
/// {@endtemplate}
|
|
||||||
class SpaceshipExitRailEnd extends RampOpening {
|
|
||||||
/// {@macro spaceship_exit_rail_end}
|
|
||||||
SpaceshipExitRailEnd()
|
|
||||||
: super(
|
|
||||||
insideLayer: Layer.spaceshipExitRail,
|
|
||||||
orientation: RampOrientation.down,
|
|
||||||
) {
|
|
||||||
layer = Layer.spaceshipExitRail;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Shape get shape {
|
|
||||||
return CircleShape()..radius = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// [ContactCallback] that handles the contact between the [Ball]
|
|
||||||
/// and a [SpaceshipExitRailEnd].
|
|
||||||
///
|
|
||||||
/// It resets the [Ball] priority and filter data so it will "be back" on the
|
|
||||||
/// board.
|
|
||||||
class SpaceshipExitRailEndBallContactCallback
|
|
||||||
extends ContactCallback<SpaceshipExitRailEnd, Ball> {
|
|
||||||
@override
|
|
||||||
void begin(SpaceshipExitRailEnd exitRail, Ball ball, _) {
|
|
||||||
ball
|
|
||||||
..priority = 1
|
|
||||||
..gameRef.reorderChildren()
|
|
||||||
..layer = exitRail.outsideLayer;
|
|
||||||
}
|
|
||||||
}
|
|
After Width: | Height: | Size: 150 KiB |
After Width: | Height: | Size: 119 KiB |
After Width: | Height: | Size: 768 KiB |
After Width: | Height: | Size: 339 KiB |
After Width: | Height: | Size: 33 KiB |
After Width: | Height: | Size: 103 KiB |
Before Width: | Height: | Size: 231 KiB After Width: | Height: | Size: 231 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 63 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
@ -0,0 +1,156 @@
|
|||||||
|
// ignore_for_file: avoid_renaming_method_parameters
|
||||||
|
|
||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
|
/// {@template boundaries}
|
||||||
|
/// A [Blueprint] which creates the [_BottomBoundary] and [_OuterBoundary].
|
||||||
|
///{@endtemplate boundaries}
|
||||||
|
class Boundaries extends Forge2DBlueprint {
|
||||||
|
@override
|
||||||
|
void build(_) {
|
||||||
|
final bottomBoundary = _BottomBoundary();
|
||||||
|
final outerBoundary = _OuterBoundary();
|
||||||
|
|
||||||
|
addAll([bottomBoundary, outerBoundary]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// {@template bottom_boundary}
|
||||||
|
/// Curved boundary at the bottom of the board where the [Ball] exits the field
|
||||||
|
/// of play.
|
||||||
|
/// {@endtemplate bottom_boundary}
|
||||||
|
class _BottomBoundary extends BodyComponent with InitialPosition {
|
||||||
|
/// {@macro bottom_boundary}
|
||||||
|
_BottomBoundary() : super(priority: 2);
|
||||||
|
|
||||||
|
List<FixtureDef> _createFixtureDefs() {
|
||||||
|
final fixturesDefs = <FixtureDef>[];
|
||||||
|
|
||||||
|
final bottomLeftCurve = BezierCurveShape(
|
||||||
|
controlPoints: [
|
||||||
|
Vector2(-43.6, -44.4),
|
||||||
|
Vector2(-31, -43.4),
|
||||||
|
Vector2(-18.7, -52.1),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
final bottomLeftCurveFixtureDef = FixtureDef(bottomLeftCurve);
|
||||||
|
fixturesDefs.add(bottomLeftCurveFixtureDef);
|
||||||
|
|
||||||
|
final bottomRightCurve = BezierCurveShape(
|
||||||
|
controlPoints: [
|
||||||
|
Vector2(31.8, -44.1),
|
||||||
|
Vector2(21.95, -47),
|
||||||
|
Vector2(12.3, -51.4),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
final bottomRightCurveFixtureDef = FixtureDef(bottomRightCurve);
|
||||||
|
fixturesDefs.add(bottomRightCurveFixtureDef);
|
||||||
|
|
||||||
|
return fixturesDefs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Body createBody() {
|
||||||
|
final bodyDef = BodyDef()..position = initialPosition;
|
||||||
|
final body = world.createBody(bodyDef);
|
||||||
|
_createFixtureDefs().forEach(body.createFixture);
|
||||||
|
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
await _loadSprite();
|
||||||
|
renderBody = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _loadSprite() async {
|
||||||
|
final sprite = await gameRef.loadSprite(
|
||||||
|
Assets.images.boundary.bottom.keyName,
|
||||||
|
);
|
||||||
|
|
||||||
|
await add(
|
||||||
|
SpriteComponent(
|
||||||
|
sprite: sprite,
|
||||||
|
size: sprite.originalSize / 10,
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: Vector2(-5.4, 57.4),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// {@template outer_boundary}
|
||||||
|
/// Boundary enclosing the top and left side of the board. The right side of the
|
||||||
|
/// board is closed by the barrier the [LaunchRamp] creates.
|
||||||
|
/// {@endtemplate outer_boundary}
|
||||||
|
class _OuterBoundary extends BodyComponent with InitialPosition {
|
||||||
|
/// {@macro outer_boundary}
|
||||||
|
_OuterBoundary() : super(priority: -1);
|
||||||
|
|
||||||
|
List<FixtureDef> _createFixtureDefs() {
|
||||||
|
final fixturesDefs = <FixtureDef>[];
|
||||||
|
|
||||||
|
final topWall = EdgeShape()
|
||||||
|
..set(
|
||||||
|
Vector2(3.6, 70.2),
|
||||||
|
Vector2(-14.1, 70.2),
|
||||||
|
);
|
||||||
|
final topWallFixtureDef = FixtureDef(topWall);
|
||||||
|
fixturesDefs.add(topWallFixtureDef);
|
||||||
|
|
||||||
|
final topLeftCurve = BezierCurveShape(
|
||||||
|
controlPoints: [
|
||||||
|
Vector2(-32.3, 57.2),
|
||||||
|
Vector2(-31.5, 69.9),
|
||||||
|
Vector2(-14.1, 70.2),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
final topLeftCurveFixtureDef = FixtureDef(topLeftCurve);
|
||||||
|
fixturesDefs.add(topLeftCurveFixtureDef);
|
||||||
|
|
||||||
|
final leftWall = EdgeShape()
|
||||||
|
..set(
|
||||||
|
Vector2(-32.3, 57.2),
|
||||||
|
Vector2(-44.1, -44.4),
|
||||||
|
);
|
||||||
|
final leftWallFixtureDef = FixtureDef(leftWall);
|
||||||
|
fixturesDefs.add(leftWallFixtureDef);
|
||||||
|
|
||||||
|
return fixturesDefs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Body createBody() {
|
||||||
|
final bodyDef = BodyDef()..position = initialPosition;
|
||||||
|
final body = world.createBody(bodyDef);
|
||||||
|
_createFixtureDefs().forEach(body.createFixture);
|
||||||
|
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
await _loadSprite();
|
||||||
|
renderBody = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _loadSprite() async {
|
||||||
|
final sprite = await gameRef.loadSprite(
|
||||||
|
Assets.images.boundary.outer.keyName,
|
||||||
|
);
|
||||||
|
|
||||||
|
await add(
|
||||||
|
SpriteComponent(
|
||||||
|
sprite: sprite,
|
||||||
|
size: sprite.originalSize / 10,
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: Vector2(-0.2, -1.4),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,246 @@
|
|||||||
|
// ignore_for_file: avoid_renaming_method_parameters
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/// {@template spaceship_rail}
|
||||||
|
/// A [Blueprint] for the spaceship drop tube.
|
||||||
|
/// {@endtemplate}
|
||||||
|
class SpaceshipRail extends Forge2DBlueprint {
|
||||||
|
/// {@macro spaceship_rail}
|
||||||
|
SpaceshipRail();
|
||||||
|
|
||||||
|
/// Base priority for ball while be in [_SpaceshipRailRamp].
|
||||||
|
static const ballPriorityWhenOnSpaceshipRail = 2;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void build(_) {
|
||||||
|
addAllContactCallback([
|
||||||
|
SpaceshipRailExitBallContactCallback(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
final railRamp = _SpaceshipRailRamp();
|
||||||
|
final railEnd = SpaceshipRailExit();
|
||||||
|
final topBase = _SpaceshipRailBase(radius: 0.55)
|
||||||
|
..initialPosition = Vector2(-26.15, 18.65);
|
||||||
|
final bottomBase = _SpaceshipRailBase(radius: 0.8)
|
||||||
|
..initialPosition = Vector2(-25.5, -12.9);
|
||||||
|
final railForeground = _SpaceshipRailForeground();
|
||||||
|
|
||||||
|
addAll([
|
||||||
|
railRamp,
|
||||||
|
railEnd,
|
||||||
|
topBase,
|
||||||
|
bottomBase,
|
||||||
|
railForeground,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Represents the spaceship drop rail from the [Spaceship].
|
||||||
|
class _SpaceshipRailRamp extends BodyComponent with InitialPosition, Layered {
|
||||||
|
_SpaceshipRailRamp()
|
||||||
|
: super(
|
||||||
|
priority: SpaceshipRail.ballPriorityWhenOnSpaceshipRail - 1,
|
||||||
|
) {
|
||||||
|
renderBody = false;
|
||||||
|
layer = Layer.spaceshipExitRail;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<FixtureDef> _createFixtureDefs() {
|
||||||
|
final fixturesDefs = <FixtureDef>[];
|
||||||
|
|
||||||
|
final topArcShape = ArcShape(
|
||||||
|
center: Vector2(-35.5, 30.9),
|
||||||
|
arcRadius: 2.5,
|
||||||
|
angle: math.pi,
|
||||||
|
rotation: 2.9,
|
||||||
|
);
|
||||||
|
final topArcFixtureDef = FixtureDef(topArcShape);
|
||||||
|
fixturesDefs.add(topArcFixtureDef);
|
||||||
|
|
||||||
|
final topLeftCurveShape = BezierCurveShape(
|
||||||
|
controlPoints: [
|
||||||
|
Vector2(-37.9, 30.4),
|
||||||
|
Vector2(-38, 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),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
final middleLeftCurveFixtureDef = FixtureDef(middleLeftCurveShape);
|
||||||
|
fixturesDefs.add(middleLeftCurveFixtureDef);
|
||||||
|
|
||||||
|
final bottomLeftCurveShape = BezierCurveShape(
|
||||||
|
controlPoints: [
|
||||||
|
middleLeftCurveShape.vertices.last,
|
||||||
|
Vector2(-36, -8.6),
|
||||||
|
Vector2(-32.04, -18.3),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
final bottomLeftCurveFixtureDef = FixtureDef(bottomLeftCurveShape);
|
||||||
|
fixturesDefs.add(bottomLeftCurveFixtureDef);
|
||||||
|
|
||||||
|
final topRightStraightShape = EdgeShape()
|
||||||
|
..set(
|
||||||
|
Vector2(-33, 31.3),
|
||||||
|
Vector2(-27.2, 21.3),
|
||||||
|
);
|
||||||
|
final topRightStraightFixtureDef = FixtureDef(topRightStraightShape);
|
||||||
|
fixturesDefs.add(topRightStraightFixtureDef);
|
||||||
|
|
||||||
|
final middleRightCurveShape = BezierCurveShape(
|
||||||
|
controlPoints: [
|
||||||
|
topRightStraightShape.vertex1,
|
||||||
|
Vector2(-16.5, 11.4),
|
||||||
|
Vector2(-25.29, -1.7),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
final middleRightCurveFixtureDef = FixtureDef(middleRightCurveShape);
|
||||||
|
fixturesDefs.add(middleRightCurveFixtureDef);
|
||||||
|
|
||||||
|
final bottomRightCurveShape = BezierCurveShape(
|
||||||
|
controlPoints: [
|
||||||
|
middleRightCurveShape.vertices.last,
|
||||||
|
Vector2(-29.91, -8.5),
|
||||||
|
Vector2(-26.8, -15.7),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
final bottomRightCurveFixtureDef = FixtureDef(bottomRightCurveShape);
|
||||||
|
fixturesDefs.add(bottomRightCurveFixtureDef);
|
||||||
|
|
||||||
|
return fixturesDefs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Body createBody() {
|
||||||
|
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 _loadSprite();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _loadSprite() async {
|
||||||
|
final sprite = await gameRef.loadSprite(
|
||||||
|
Assets.images.spaceship.rail.main.keyName,
|
||||||
|
);
|
||||||
|
final spriteComponent = SpriteComponent(
|
||||||
|
sprite: sprite,
|
||||||
|
size: Vector2(17.5, 55.7),
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: Vector2(-29.4, -5.7),
|
||||||
|
);
|
||||||
|
|
||||||
|
await add(spriteComponent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SpaceshipRailForeground extends SpriteComponent with HasGameRef {
|
||||||
|
_SpaceshipRailForeground()
|
||||||
|
: super(
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: Vector2(-28.5, 19.7),
|
||||||
|
priority: SpaceshipRail.ballPriorityWhenOnSpaceshipRail + 1,
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
|
||||||
|
final sprite = await gameRef.loadSprite(
|
||||||
|
Assets.images.spaceship.rail.foreground.keyName,
|
||||||
|
);
|
||||||
|
this.sprite = sprite;
|
||||||
|
size = sprite.originalSize / 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Represents the ground bases of the [_SpaceshipRailRamp].
|
||||||
|
class _SpaceshipRailBase extends BodyComponent with InitialPosition, Layered {
|
||||||
|
_SpaceshipRailBase({required this.radius})
|
||||||
|
: super(
|
||||||
|
priority: SpaceshipRail.ballPriorityWhenOnSpaceshipRail + 1,
|
||||||
|
) {
|
||||||
|
renderBody = false;
|
||||||
|
layer = Layer.board;
|
||||||
|
}
|
||||||
|
|
||||||
|
final double radius;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Body createBody() {
|
||||||
|
final shape = CircleShape()..radius = radius;
|
||||||
|
|
||||||
|
final fixtureDef = FixtureDef(shape);
|
||||||
|
|
||||||
|
final bodyDef = BodyDef()
|
||||||
|
..position = initialPosition
|
||||||
|
..userData = this;
|
||||||
|
|
||||||
|
return world.createBody(bodyDef)..createFixture(fixtureDef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// {@template spaceship_rail_exit}
|
||||||
|
/// A sensor [BodyComponent] responsible for sending the [Ball]
|
||||||
|
/// back to the board.
|
||||||
|
/// {@endtemplate}
|
||||||
|
class SpaceshipRailExit extends RampOpening {
|
||||||
|
/// {@macro spaceship_rail_exit}
|
||||||
|
SpaceshipRailExit()
|
||||||
|
: super(
|
||||||
|
insideLayer: Layer.spaceshipExitRail,
|
||||||
|
orientation: RampOrientation.down,
|
||||||
|
insidePriority: 3,
|
||||||
|
) {
|
||||||
|
renderBody = false;
|
||||||
|
layer = Layer.spaceshipExitRail;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Shape get shape {
|
||||||
|
return ArcShape(
|
||||||
|
center: Vector2(-28, -19),
|
||||||
|
arcRadius: 2.5,
|
||||||
|
angle: math.pi * 0.4,
|
||||||
|
rotation: -0.16,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// [ContactCallback] that handles the contact between the [Ball]
|
||||||
|
/// and a [SpaceshipRailExit].
|
||||||
|
///
|
||||||
|
/// It resets the [Ball] priority and filter data so it will "be back" on the
|
||||||
|
/// board.
|
||||||
|
class SpaceshipRailExitBallContactCallback
|
||||||
|
extends ContactCallback<SpaceshipRailExit, Ball> {
|
||||||
|
@override
|
||||||
|
void begin(SpaceshipRailExit exitRail, Ball ball, _) {
|
||||||
|
ball
|
||||||
|
..sendTo(exitRail.outsidePriority)
|
||||||
|
..layer = exitRail.outsideLayer;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,282 @@
|
|||||||
|
// ignore_for_file: avoid_renaming_method_parameters, comment_references
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/// {@template spaceship_ramp}
|
||||||
|
/// A [Blueprint] which creates the [_SpaceshipRampBackground].
|
||||||
|
/// {@endtemplate}
|
||||||
|
class SpaceshipRamp extends Forge2DBlueprint {
|
||||||
|
/// {@macro spaceship_ramp}
|
||||||
|
SpaceshipRamp();
|
||||||
|
|
||||||
|
/// Base priority for wall while be in the ramp.
|
||||||
|
static const int ballPriorityInsideRamp = 4;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void build(_) {
|
||||||
|
addAllContactCallback([
|
||||||
|
RampOpeningBallContactCallback<_SpaceshipRampOpening>(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
final rightOpening = _SpaceshipRampOpening(
|
||||||
|
// TODO(ruimiguel): set Board priority when defined.
|
||||||
|
outsidePriority: 1,
|
||||||
|
rotation: math.pi,
|
||||||
|
)
|
||||||
|
..initialPosition = Vector2(1.7, 19)
|
||||||
|
..layer = Layer.opening;
|
||||||
|
final leftOpening = _SpaceshipRampOpening(
|
||||||
|
outsideLayer: Layer.spaceship,
|
||||||
|
outsidePriority: Spaceship.ballPriorityWhenOnSpaceship,
|
||||||
|
rotation: math.pi,
|
||||||
|
)
|
||||||
|
..initialPosition = Vector2(-13.7, 19)
|
||||||
|
..layer = Layer.spaceshipEntranceRamp;
|
||||||
|
|
||||||
|
final spaceshipRamp = _SpaceshipRampBackground();
|
||||||
|
|
||||||
|
final spaceshipRampForegroundRailing = _SpaceshipRampForegroundRailing();
|
||||||
|
|
||||||
|
final baseRight = _SpaceshipRampBase()..initialPosition = Vector2(1.7, 20);
|
||||||
|
|
||||||
|
addAll([
|
||||||
|
rightOpening,
|
||||||
|
leftOpening,
|
||||||
|
baseRight,
|
||||||
|
spaceshipRamp,
|
||||||
|
spaceshipRampForegroundRailing,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Represents the upper left blue ramp of the [Board] with its background
|
||||||
|
/// railing.
|
||||||
|
class _SpaceshipRampBackground extends BodyComponent
|
||||||
|
with InitialPosition, Layered {
|
||||||
|
_SpaceshipRampBackground()
|
||||||
|
: super(priority: SpaceshipRamp.ballPriorityInsideRamp - 1) {
|
||||||
|
layer = Layer.spaceshipEntranceRamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Width between walls of the ramp.
|
||||||
|
static const width = 5.0;
|
||||||
|
|
||||||
|
List<FixtureDef> _createFixtureDefs() {
|
||||||
|
final fixturesDef = <FixtureDef>[];
|
||||||
|
|
||||||
|
final outerLeftCurveShape = BezierCurveShape(
|
||||||
|
controlPoints: [
|
||||||
|
Vector2(-30.95, 38),
|
||||||
|
Vector2(-32.5, 71.25),
|
||||||
|
Vector2(-14.2, 71.25),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
final outerLeftCurveFixtureDef = FixtureDef(outerLeftCurveShape);
|
||||||
|
fixturesDef.add(outerLeftCurveFixtureDef);
|
||||||
|
|
||||||
|
final outerRightCurveShape = BezierCurveShape(
|
||||||
|
controlPoints: [
|
||||||
|
outerLeftCurveShape.vertices.last,
|
||||||
|
Vector2(4.7, 71.25),
|
||||||
|
Vector2(6.3, 40),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
final outerRightCurveFixtureDef = FixtureDef(outerRightCurveShape);
|
||||||
|
fixturesDef.add(outerRightCurveFixtureDef);
|
||||||
|
|
||||||
|
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 spriteRamp = await gameRef.loadSprite(
|
||||||
|
Assets.images.spaceship.ramp.main.keyName,
|
||||||
|
);
|
||||||
|
|
||||||
|
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.spaceship.ramp.railingBackground.keyName,
|
||||||
|
);
|
||||||
|
final spriteRailingBgComponent = SpriteComponent(
|
||||||
|
sprite: spriteRailingBg,
|
||||||
|
size: Vector2(38.3, 35.1),
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: spriteRampComponent.position + Vector2(0, -1),
|
||||||
|
);
|
||||||
|
|
||||||
|
await addAll([
|
||||||
|
spriteRailingBgComponent,
|
||||||
|
spriteRampComponent,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Represents the foreground of the railing upper left blue ramp.
|
||||||
|
class _SpaceshipRampForegroundRailing extends BodyComponent
|
||||||
|
with InitialPosition, Layered {
|
||||||
|
_SpaceshipRampForegroundRailing()
|
||||||
|
: super(priority: SpaceshipRamp.ballPriorityInsideRamp + 1) {
|
||||||
|
layer = Layer.spaceshipEntranceRamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
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.spaceship.ramp.railingForeground.keyName,
|
||||||
|
);
|
||||||
|
final spriteRailingFgComponent = SpriteComponent(
|
||||||
|
sprite: spriteRailingFg,
|
||||||
|
size: Vector2(26.1, 28.3),
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: Vector2(-12.2, -52.5),
|
||||||
|
);
|
||||||
|
|
||||||
|
await add(spriteRailingFgComponent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Represents the ground right base of the [SpaceshipRamp].
|
||||||
|
class _SpaceshipRampBase extends BodyComponent with InitialPosition, Layered {
|
||||||
|
_SpaceshipRampBase() {
|
||||||
|
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 spaceship_ramp_opening}
|
||||||
|
/// [RampOpening] with [Layer.spaceshipEntranceRamp] to filter [Ball] collisions
|
||||||
|
/// inside [_SpaceshipRampBackground].
|
||||||
|
/// {@endtemplate}
|
||||||
|
class _SpaceshipRampOpening extends RampOpening {
|
||||||
|
/// {@macro spaceship_ramp_opening}
|
||||||
|
_SpaceshipRampOpening({
|
||||||
|
Layer? outsideLayer,
|
||||||
|
int? outsidePriority,
|
||||||
|
required double rotation,
|
||||||
|
}) : _rotation = rotation,
|
||||||
|
super(
|
||||||
|
insideLayer: Layer.spaceshipEntranceRamp,
|
||||||
|
outsideLayer: outsideLayer,
|
||||||
|
orientation: RampOrientation.down,
|
||||||
|
insidePriority: SpaceshipRamp.ballPriorityInsideRamp,
|
||||||
|
outsidePriority: outsidePriority,
|
||||||
|
);
|
||||||
|
|
||||||
|
final double _rotation;
|
||||||
|
|
||||||
|
static final Vector2 _size = Vector2(_SpaceshipRampBackground.width / 4, .1);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Shape get shape {
|
||||||
|
renderBody = false;
|
||||||
|
return PolygonShape()
|
||||||
|
..setAsBox(
|
||||||
|
_size.x,
|
||||||
|
_size.y,
|
||||||
|
initialPosition,
|
||||||
|
_rotation,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,2 +1,3 @@
|
|||||||
export 'games.dart';
|
export 'games.dart';
|
||||||
export 'methods.dart';
|
export 'methods.dart';
|
||||||
|
export 'trace.dart';
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
extension BodyTrace on BodyComponent {
|
||||||
|
void trace({Color color = const Color(0xFFFF0000)}) {
|
||||||
|
paint = Paint()..color = color;
|
||||||
|
renderBody = true;
|
||||||
|
|
||||||
|
unawaited(
|
||||||
|
mounted.whenComplete(() {
|
||||||
|
final sprite = children.whereType<SpriteComponent>().first;
|
||||||
|
sprite.paint.color = sprite.paint.color.withOpacity(0.5);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
import 'package:dashbook/dashbook.dart';
|
||||||
import 'package:flame/game.dart';
|
import 'package:flame/game.dart';
|
||||||
import 'package:sandbox/common/common.dart';
|
import 'package:sandbox/common/common.dart';
|
||||||
import 'package:sandbox/stories/baseboard/basic.dart';
|
import 'package:sandbox/stories/baseboard/basic_baseboard_game.dart';
|
||||||
|
|
||||||
void addBaseboardStories(Dashbook dashbook) {
|
void addBaseboardStories(Dashbook dashbook) {
|
||||||
dashbook.storiesOf('Baseboard').add(
|
dashbook.storiesOf('Baseboard').add(
|
@ -0,0 +1,14 @@
|
|||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
|
class ChromeDinoGame extends Forge2DGame {
|
||||||
|
static const info = 'Shows how a ChromeDino is rendered.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
|
||||||
|
camera.followVector2(Vector2.zero());
|
||||||
|
await add(ChromeDino());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
import 'package:dashbook/dashbook.dart';
|
||||||
|
import 'package:flame/game.dart';
|
||||||
|
import 'package:sandbox/common/common.dart';
|
||||||
|
import 'package:sandbox/stories/chrome_dino/chrome_dino_game.dart';
|
||||||
|
|
||||||
|
void addChromeDinoStories(Dashbook dashbook) {
|
||||||
|
dashbook.storiesOf('Chrome Dino').add(
|
||||||
|
'Basic',
|
||||||
|
(context) => GameWidget(
|
||||||
|
game: ChromeDinoGame(),
|
||||||
|
),
|
||||||
|
codeLink: buildSourceLink('chrome_dino/basic.dart'),
|
||||||
|
info: ChromeDinoGame.info,
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:ui';
|
||||||
|
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
import 'package:sandbox/common/common.dart';
|
||||||
|
import 'package:sandbox/stories/ball/basic_ball_game.dart';
|
||||||
|
|
||||||
|
class BigDashNestBumperGame extends BasicBallGame {
|
||||||
|
BigDashNestBumperGame({
|
||||||
|
required this.trace,
|
||||||
|
}) : super(color: const Color(0xFF0000FF));
|
||||||
|
|
||||||
|
static const info = '''
|
||||||
|
Shows how a BigDashNestBumper is rendered.
|
||||||
|
|
||||||
|
Activate the "trace" parameter to overlay the body.
|
||||||
|
''';
|
||||||
|
|
||||||
|
final bool trace;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
|
||||||
|
final center = screenToWorld(camera.viewport.canvasSize! / 2);
|
||||||
|
final bigDashNestBumper = BigDashNestBumper()
|
||||||
|
..initialPosition = center
|
||||||
|
..priority = 1;
|
||||||
|
await add(bigDashNestBumper);
|
||||||
|
|
||||||
|
if (trace) bigDashNestBumper.trace();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
import 'package:dashbook/dashbook.dart';
|
||||||
|
import 'package:flame/game.dart';
|
||||||
|
import 'package:sandbox/common/common.dart';
|
||||||
|
import 'package:sandbox/stories/ball/basic_ball_game.dart';
|
||||||
|
import 'package:sandbox/stories/dash_nest_bumper/big_dash_nest_bumper_game.dart';
|
||||||
|
|
||||||
|
void addDashNestBumperStories(Dashbook dashbook) {
|
||||||
|
dashbook.storiesOf('Dash Nest Bumpers').add(
|
||||||
|
'Big',
|
||||||
|
(context) => GameWidget(
|
||||||
|
game: BigDashNestBumperGame(
|
||||||
|
trace: context.boolProperty('Trace', true),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
codeLink: buildSourceLink('dash_nest_bumper/big.dart'),
|
||||||
|
info: BasicBallGame.info,
|
||||||
|
);
|
||||||
|
}
|
@ -1,13 +1,13 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
import 'package:dashbook/dashbook.dart';
|
||||||
import 'package:flame/game.dart';
|
import 'package:flame/game.dart';
|
||||||
import 'package:sandbox/common/common.dart';
|
import 'package:sandbox/common/common.dart';
|
||||||
import 'package:sandbox/stories/effects/fire_effect.dart';
|
import 'package:sandbox/stories/effects/fire_effect_game.dart';
|
||||||
|
|
||||||
void addEffectsStories(Dashbook dashbook) {
|
void addEffectsStories(Dashbook dashbook) {
|
||||||
dashbook.storiesOf('Effects').add(
|
dashbook.storiesOf('Effects').add(
|
||||||
'Fire Effect',
|
'Fire Effect',
|
||||||
(context) => GameWidget(game: FireEffectExample()),
|
(context) => GameWidget(game: FireEffectGame()),
|
||||||
codeLink: buildSourceLink('effects/fire_effect.dart'),
|
codeLink: buildSourceLink('effects/fire_effect.dart'),
|
||||||
info: FireEffectExample.info,
|
info: FireEffectGame.info,
|
||||||
);
|
);
|
||||||
}
|
}
|
@ -1,26 +0,0 @@
|
|||||||
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
||||||
import 'package:pinball_components/pinball_components.dart';
|
|
||||||
import 'package:sandbox/common/common.dart';
|
|
||||||
|
|
||||||
class BasicFlipperGame extends BasicGame {
|
|
||||||
static const info = '''
|
|
||||||
Basic example of how a Flipper works.
|
|
||||||
''';
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> onLoad() async {
|
|
||||||
await super.onLoad();
|
|
||||||
|
|
||||||
final center = screenToWorld(camera.viewport.canvasSize! / 2);
|
|
||||||
|
|
||||||
final leftFlipper = Flipper(side: BoardSide.left)
|
|
||||||
..initialPosition = center - Vector2(Flipper.size.x, 0);
|
|
||||||
final rightFlipper = Flipper(side: BoardSide.right)
|
|
||||||
..initialPosition = center + Vector2(Flipper.size.x, 0);
|
|
||||||
|
|
||||||
await addAll([
|
|
||||||
leftFlipper,
|
|
||||||
rightFlipper,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,70 @@
|
|||||||
|
import 'package:flame/input.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
|
import 'package:sandbox/stories/ball/basic_ball_game.dart';
|
||||||
|
|
||||||
|
class BasicFlipperGame extends BasicBallGame with KeyboardEvents {
|
||||||
|
BasicFlipperGame() : super(color: Colors.blue);
|
||||||
|
|
||||||
|
static const info = 'Shows how a Flipper works.';
|
||||||
|
|
||||||
|
static const _leftFlipperKeys = [
|
||||||
|
LogicalKeyboardKey.arrowLeft,
|
||||||
|
LogicalKeyboardKey.keyA,
|
||||||
|
];
|
||||||
|
|
||||||
|
static const _rightFlipperKeys = [
|
||||||
|
LogicalKeyboardKey.arrowRight,
|
||||||
|
LogicalKeyboardKey.keyD,
|
||||||
|
];
|
||||||
|
|
||||||
|
late Flipper leftFlipper;
|
||||||
|
late Flipper rightFlipper;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
|
||||||
|
final center = screenToWorld(camera.viewport.canvasSize! / 2);
|
||||||
|
|
||||||
|
leftFlipper = Flipper(side: BoardSide.left)
|
||||||
|
..initialPosition = center - Vector2(Flipper.size.x, 0);
|
||||||
|
rightFlipper = Flipper(side: BoardSide.right)
|
||||||
|
..initialPosition = center + Vector2(Flipper.size.x, 0);
|
||||||
|
|
||||||
|
await addAll([
|
||||||
|
leftFlipper,
|
||||||
|
rightFlipper,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
KeyEventResult onKeyEvent(
|
||||||
|
RawKeyEvent event,
|
||||||
|
Set<LogicalKeyboardKey> keysPressed,
|
||||||
|
) {
|
||||||
|
final movedLeftFlipper = _leftFlipperKeys.contains(event.logicalKey);
|
||||||
|
if (movedLeftFlipper) {
|
||||||
|
if (event is RawKeyDownEvent) {
|
||||||
|
leftFlipper.moveUp();
|
||||||
|
} else if (event is RawKeyUpEvent) {
|
||||||
|
leftFlipper.moveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final movedRightFlipper = _rightFlipperKeys.contains(event.logicalKey);
|
||||||
|
if (movedRightFlipper) {
|
||||||
|
if (event is RawKeyDownEvent) {
|
||||||
|
rightFlipper.moveUp();
|
||||||
|
} else if (event is RawKeyUpEvent) {
|
||||||
|
rightFlipper.moveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return movedLeftFlipper || movedRightFlipper
|
||||||
|
? KeyEventResult.handled
|
||||||
|
: KeyEventResult.ignored;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
|
import 'package:sandbox/common/common.dart';
|
||||||
|
import 'package:sandbox/stories/flipper/basic_flipper_game.dart';
|
||||||
|
|
||||||
|
class FlipperTracingGame extends BasicFlipperGame {
|
||||||
|
static const info = '''
|
||||||
|
Basic example of how the Flipper body overlays the sprite.
|
||||||
|
''';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
|
||||||
|
leftFlipper.trace();
|
||||||
|
leftFlipper.body.joints.whereType<RevoluteJoint>().forEach(
|
||||||
|
(joint) => joint.setLimits(0, 0),
|
||||||
|
);
|
||||||
|
|
||||||
|
rightFlipper.trace();
|
||||||
|
rightFlipper.body.joints.whereType<RevoluteJoint>().forEach(
|
||||||
|
(joint) => joint.setLimits(0, 0),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
import 'package:dashbook/dashbook.dart';
|
||||||
import 'package:flame/game.dart';
|
import 'package:flame/game.dart';
|
||||||
import 'package:sandbox/common/common.dart';
|
import 'package:sandbox/common/common.dart';
|
||||||
import 'package:sandbox/stories/flipper/basic.dart';
|
import 'package:sandbox/stories/flipper/basic_flipper_game.dart';
|
||||||
import 'package:sandbox/stories/flipper/tracing.dart';
|
import 'package:sandbox/stories/flipper/flipper_tracing_game.dart';
|
||||||
|
|
||||||
void addFlipperStories(Dashbook dashbook) {
|
void addFlipperStories(Dashbook dashbook) {
|
||||||
dashbook.storiesOf('Flipper')
|
dashbook.storiesOf('Flipper')
|
@ -1,49 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:flame/components.dart';
|
|
||||||
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:pinball_components/pinball_components.dart';
|
|
||||||
import 'package:sandbox/common/common.dart';
|
|
||||||
|
|
||||||
class FlipperTracingGame extends BasicGame {
|
|
||||||
static const info = '''
|
|
||||||
Basic example of how the Flipper body overlays the sprite.
|
|
||||||
''';
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> onLoad() async {
|
|
||||||
await super.onLoad();
|
|
||||||
final center = screenToWorld(camera.viewport.canvasSize! / 2);
|
|
||||||
|
|
||||||
final leftFlipper = Flipper(side: BoardSide.left)
|
|
||||||
..initialPosition = center - Vector2(Flipper.size.x, 0);
|
|
||||||
final rightFlipper = Flipper(side: BoardSide.right)
|
|
||||||
..initialPosition = center + Vector2(Flipper.size.x, 0);
|
|
||||||
|
|
||||||
await addAll([
|
|
||||||
leftFlipper,
|
|
||||||
rightFlipper,
|
|
||||||
]);
|
|
||||||
leftFlipper.trace();
|
|
||||||
rightFlipper.trace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension on BodyComponent {
|
|
||||||
void trace({Color color = Colors.red}) {
|
|
||||||
paint = Paint()..color = color;
|
|
||||||
renderBody = true;
|
|
||||||
body.joints.whereType<RevoluteJoint>().forEach(
|
|
||||||
(joint) => joint.setLimits(0, 0),
|
|
||||||
);
|
|
||||||
body.setType(BodyType.static);
|
|
||||||
|
|
||||||
unawaited(
|
|
||||||
mounted.whenComplete(() {
|
|
||||||
final sprite = children.whereType<SpriteComponent>().first;
|
|
||||||
sprite.paint.color = sprite.paint.color.withOpacity(0.5);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +1,15 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
import 'package:dashbook/dashbook.dart';
|
||||||
import 'package:flame/game.dart';
|
import 'package:flame/game.dart';
|
||||||
import 'package:sandbox/common/common.dart';
|
import 'package:sandbox/common/common.dart';
|
||||||
import 'package:sandbox/stories/spaceship/basic.dart';
|
import 'package:sandbox/stories/spaceship/basic_spaceship_game.dart';
|
||||||
|
|
||||||
void addSpaceshipStories(Dashbook dashbook) {
|
void addSpaceshipStories(Dashbook dashbook) {
|
||||||
dashbook.storiesOf('Spaceship').add(
|
dashbook.storiesOf('Spaceship').add(
|
||||||
'Basic',
|
'Basic',
|
||||||
(context) => GameWidget(game: BasicSpaceship()),
|
(context) => GameWidget(
|
||||||
|
game: BasicSpaceshipGame(),
|
||||||
|
),
|
||||||
codeLink: buildSourceLink('spaceship/basic.dart'),
|
codeLink: buildSourceLink('spaceship/basic.dart'),
|
||||||
info: BasicSpaceship.info,
|
info: BasicSpaceshipGame.info,
|
||||||
);
|
);
|
||||||
}
|
}
|
@ -1,5 +1,8 @@
|
|||||||
export 'ball/ball.dart';
|
export 'ball/stories.dart';
|
||||||
export 'baseboard/baseboard.dart';
|
export 'baseboard/stories.dart';
|
||||||
export 'effects/effects.dart';
|
export 'chrome_dino/stories.dart';
|
||||||
export 'flipper/flipper.dart';
|
export 'dash_nest_bumper/stories.dart';
|
||||||
export 'layer/layer.dart';
|
export 'effects/stories.dart';
|
||||||
|
export 'flipper/stories.dart';
|
||||||
|
export 'layer/stories.dart';
|
||||||
|
export 'spaceship/stories.dart';
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
// ignore_for_file: cascade_invocations
|
||||||
|
|
||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
|
import 'package:flame_test/flame_test.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
|
import '../../helpers/helpers.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('Boundaries', () {
|
||||||
|
final tester = FlameTester(TestGame.new);
|
||||||
|
|
||||||
|
tester.testGameWidget(
|
||||||
|
'render correctly',
|
||||||
|
setUp: (game, tester) async {
|
||||||
|
await game.addFromBlueprint(Boundaries());
|
||||||
|
await game.ready();
|
||||||
|
game.camera.followVector2(Vector2.zero());
|
||||||
|
game.camera.zoom = 3.9;
|
||||||
|
},
|
||||||
|
// TODO(allisonryan0002): enable test when workflows are fixed.
|
||||||
|
// verify: (game, tester) async {
|
||||||
|
// await expectLater(
|
||||||
|
// find.byGame<Forge2DGame>(),
|
||||||
|
// matchesGoldenFile('golden/boundaries.png'),
|
||||||
|
// );
|
||||||
|
// },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
// ignore_for_file: cascade_invocations
|
||||||
|
|
||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
|
import 'package:flame_test/flame_test.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
final flameTester = FlameTester(Forge2DGame.new);
|
||||||
|
|
||||||
|
group('ChromeDino', () {
|
||||||
|
flameTester.test(
|
||||||
|
'loads correctly',
|
||||||
|
(game) async {
|
||||||
|
final chromeDino = ChromeDino();
|
||||||
|
await game.ensureAdd(chromeDino);
|
||||||
|
|
||||||
|
expect(game.contains(chromeDino), isTrue);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'swivels',
|
||||||
|
(game) async {
|
||||||
|
// TODO(alestiago): Write golden tests to check the
|
||||||
|
// swivel animation.
|
||||||
|
final chromeDino = ChromeDino();
|
||||||
|
await game.ensureAdd(chromeDino);
|
||||||
|
|
||||||
|
final previousPosition = chromeDino.body.position.clone();
|
||||||
|
game.update(64);
|
||||||
|
|
||||||
|
expect(chromeDino.body.position, isNot(equals(previousPosition)));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
After Width: | Height: | Size: 324 KiB |
After Width: | Height: | Size: 177 KiB |
@ -0,0 +1,31 @@
|
|||||||
|
// ignore_for_file: cascade_invocations
|
||||||
|
|
||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
|
import 'package:flame_test/flame_test.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
|
import '../../helpers/helpers.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('LaunchRamp', () {
|
||||||
|
final tester = FlameTester(TestGame.new);
|
||||||
|
|
||||||
|
tester.testGameWidget(
|
||||||
|
'renders correctly',
|
||||||
|
setUp: (game, tester) async {
|
||||||
|
await game.addFromBlueprint(LaunchRamp());
|
||||||
|
await game.ready();
|
||||||
|
game.camera.followVector2(Vector2.zero());
|
||||||
|
game.camera.zoom = 4.1;
|
||||||
|
},
|
||||||
|
// TODO(allisonryan0002): enable test when workflows are fixed.
|
||||||
|
// verify: (game, tester) async {
|
||||||
|
// await expectLater(
|
||||||
|
// find.byGame<Forge2DGame>(),
|
||||||
|
// matchesGoldenFile('golden/launch-ramp.png'),
|
||||||
|
// );
|
||||||
|
// },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
// ignore_for_file: cascade_invocations
|
||||||
|
|
||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
|
import 'package:flame_test/flame_test.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:mocktail/mocktail.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
|
import '../../helpers/helpers.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('SpaceshipRail', () {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
final flameTester = FlameTester(TestGame.new);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'loads correctly',
|
||||||
|
(game) async {
|
||||||
|
final spaceshipRail = SpaceshipRail();
|
||||||
|
await game.addFromBlueprint(spaceshipRail);
|
||||||
|
await game.ready();
|
||||||
|
|
||||||
|
for (final element in spaceshipRail.components) {
|
||||||
|
expect(game.contains(element), isTrue);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO(alestiago): Make ContactCallback private and use `beginContact`
|
||||||
|
// instead.
|
||||||
|
group('SpaceshipRailExitBallContactCallback', () {
|
||||||
|
late Forge2DGame game;
|
||||||
|
late SpaceshipRailExit railExit;
|
||||||
|
late Ball ball;
|
||||||
|
late Body body;
|
||||||
|
late Fixture fixture;
|
||||||
|
late Filter filterData;
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
game = MockGame();
|
||||||
|
|
||||||
|
railExit = MockSpaceshipRailExit();
|
||||||
|
|
||||||
|
ball = MockBall();
|
||||||
|
body = MockBody();
|
||||||
|
when(() => ball.gameRef).thenReturn(game);
|
||||||
|
when(() => ball.body).thenReturn(body);
|
||||||
|
|
||||||
|
fixture = MockFixture();
|
||||||
|
filterData = MockFilter();
|
||||||
|
when(() => body.fixtures).thenReturn([fixture]);
|
||||||
|
when(() => fixture.filterData).thenReturn(filterData);
|
||||||
|
});
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
when(() => ball.priority).thenReturn(1);
|
||||||
|
when(() => railExit.outsideLayer).thenReturn(Layer.board);
|
||||||
|
when(() => railExit.outsidePriority).thenReturn(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('changes the ball priority on contact', () {
|
||||||
|
SpaceshipRailExitBallContactCallback().begin(
|
||||||
|
railExit,
|
||||||
|
ball,
|
||||||
|
MockContact(),
|
||||||
|
);
|
||||||
|
|
||||||
|
verify(() => ball.sendTo(railExit.outsidePriority)).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('changes the ball layer on contact', () {
|
||||||
|
SpaceshipRailExitBallContactCallback().begin(
|
||||||
|
railExit,
|
||||||
|
ball,
|
||||||
|
MockContact(),
|
||||||
|
);
|
||||||
|
|
||||||
|
verify(() => ball.layer = railExit.outsideLayer).called(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
// ignore_for_file: cascade_invocations
|
||||||
|
|
||||||
|
import 'package:flame_test/flame_test.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
|
import '../../helpers/helpers.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('SpaceshipRamp', () {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
final flameTester = FlameTester(TestGame.new);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'loads correctly',
|
||||||
|
(game) async {
|
||||||
|
final spaceshipEntranceRamp = SpaceshipRamp();
|
||||||
|
await game.addFromBlueprint(spaceshipEntranceRamp);
|
||||||
|
await game.ready();
|
||||||
|
|
||||||
|
for (final element in spaceshipEntranceRamp.components) {
|
||||||
|
expect(game.contains(element), isTrue);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
@ -1,23 +0,0 @@
|
|||||||
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
||||||
import 'package:flame_test/flame_test.dart';
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
|
||||||
import 'package:pinball/game/game.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
TestWidgetsFlutterBinding.ensureInitialized();
|
|
||||||
final flameTester = FlameTester(Forge2DGame.new);
|
|
||||||
|
|
||||||
group('ChromeDino', () {
|
|
||||||
flameTester.test(
|
|
||||||
'loads correctly',
|
|
||||||
(game) async {
|
|
||||||
final chromeDino = ChromeDino();
|
|
||||||
|
|
||||||
await game.ready();
|
|
||||||
await game.ensureAdd(chromeDino);
|
|
||||||
|
|
||||||
expect(game.contains(chromeDino), isTrue);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
|
||||||
import 'package:mocktail/mocktail.dart';
|
|
||||||
import 'package:pinball/game/game.dart';
|
|
||||||
import 'package:pinball_components/pinball_components.dart';
|
|
||||||
|
|
||||||
import '../../helpers/helpers.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
group('SpaceshipExitRail', () {
|
|
||||||
late PinballGame game;
|
|
||||||
late SpaceshipExitRailEnd exitRailEnd;
|
|
||||||
late Ball ball;
|
|
||||||
late Body body;
|
|
||||||
late Fixture fixture;
|
|
||||||
late Filter filterData;
|
|
||||||
|
|
||||||
setUp(() {
|
|
||||||
game = MockPinballGame();
|
|
||||||
|
|
||||||
exitRailEnd = MockSpaceshipExitRailEnd();
|
|
||||||
|
|
||||||
ball = MockBall();
|
|
||||||
body = MockBody();
|
|
||||||
when(() => ball.gameRef).thenReturn(game);
|
|
||||||
when(() => ball.body).thenReturn(body);
|
|
||||||
|
|
||||||
fixture = MockFixture();
|
|
||||||
filterData = MockFilter();
|
|
||||||
when(() => body.fixtures).thenReturn([fixture]);
|
|
||||||
when(() => fixture.filterData).thenReturn(filterData);
|
|
||||||
});
|
|
||||||
|
|
||||||
group('SpaceshipExitHoleBallContactCallback', () {
|
|
||||||
test('changes the ball priority on contact', () {
|
|
||||||
when(() => exitRailEnd.outsideLayer).thenReturn(Layer.board);
|
|
||||||
|
|
||||||
SpaceshipExitRailEndBallContactCallback().begin(
|
|
||||||
exitRailEnd,
|
|
||||||
ball,
|
|
||||||
MockContact(),
|
|
||||||
);
|
|
||||||
|
|
||||||
verify(() => ball.priority = 1).called(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('reorders the game children', () {
|
|
||||||
when(() => exitRailEnd.outsideLayer).thenReturn(Layer.board);
|
|
||||||
|
|
||||||
SpaceshipExitRailEndBallContactCallback().begin(
|
|
||||||
exitRailEnd,
|
|
||||||
ball,
|
|
||||||
MockContact(),
|
|
||||||
);
|
|
||||||
|
|
||||||
verify(game.reorderChildren).called(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|