|
|
@ -5,6 +5,11 @@ import 'package:flame_forge2d/flame_forge2d.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:pinball/game/game.dart';
|
|
|
|
import 'package:pinball/game/game.dart';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum FlipperType {
|
|
|
|
|
|
|
|
left,
|
|
|
|
|
|
|
|
right,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// {@template flipper}
|
|
|
|
/// {@template flipper}
|
|
|
|
/// A bat, typically found in pairs at the bottom of the board.
|
|
|
|
/// A bat, typically found in pairs at the bottom of the board.
|
|
|
|
///
|
|
|
|
///
|
|
|
@ -12,11 +17,11 @@ import 'package:pinball/game/game.dart';
|
|
|
|
/// {@endtemplate flipper}
|
|
|
|
/// {@endtemplate flipper}
|
|
|
|
class Flipper extends BodyComponent {
|
|
|
|
class Flipper extends BodyComponent {
|
|
|
|
/// {@macro flipper}
|
|
|
|
/// {@macro flipper}
|
|
|
|
Flipper._({
|
|
|
|
Flipper({
|
|
|
|
required Vector2 position,
|
|
|
|
required Vector2 position,
|
|
|
|
bool isMirrored = false,
|
|
|
|
required this.type,
|
|
|
|
}) : _position = position,
|
|
|
|
}) : _position = position,
|
|
|
|
_isMirrored = isMirrored,
|
|
|
|
_isMirrored = type == FlipperType.left,
|
|
|
|
_speed = _calculateSpeed() {
|
|
|
|
_speed = _calculateSpeed() {
|
|
|
|
// TODO(alestiago): Use sprite instead of color when provided.
|
|
|
|
// TODO(alestiago): Use sprite instead of color when provided.
|
|
|
|
paint = Paint()
|
|
|
|
paint = Paint()
|
|
|
@ -24,22 +29,6 @@ class Flipper extends BodyComponent {
|
|
|
|
..style = PaintingStyle.fill;
|
|
|
|
..style = PaintingStyle.fill;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// {@macro flipper}
|
|
|
|
|
|
|
|
Flipper.right({
|
|
|
|
|
|
|
|
required Vector2 position,
|
|
|
|
|
|
|
|
}) : this._(
|
|
|
|
|
|
|
|
position: position,
|
|
|
|
|
|
|
|
isMirrored: true,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// {@macro flipper}
|
|
|
|
|
|
|
|
Flipper.left({
|
|
|
|
|
|
|
|
required Vector2 position,
|
|
|
|
|
|
|
|
}) : this._(
|
|
|
|
|
|
|
|
position: position,
|
|
|
|
|
|
|
|
isMirrored: false,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// The width of the [Flipper].
|
|
|
|
/// The width of the [Flipper].
|
|
|
|
static const width = 12.0;
|
|
|
|
static const width = 12.0;
|
|
|
|
|
|
|
|
|
|
|
@ -75,6 +64,8 @@ class Flipper extends BodyComponent {
|
|
|
|
/// The initial position of the [Flipper] body.
|
|
|
|
/// The initial position of the [Flipper] body.
|
|
|
|
final Vector2 _position;
|
|
|
|
final Vector2 _position;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final FlipperType type;
|
|
|
|
|
|
|
|
|
|
|
|
/// Whether the [Flipper] is mirrored.
|
|
|
|
/// Whether the [Flipper] is mirrored.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// A mirrored [Flipper] is one positioned at the right of the borad.
|
|
|
|
/// A mirrored [Flipper] is one positioned at the right of the borad.
|
|
|
@ -160,8 +151,21 @@ class Flipper extends BodyComponent {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FlipperAnchor extends Anchor {
|
|
|
|
|
|
|
|
FlipperAnchor({
|
|
|
|
|
|
|
|
required Flipper flipper,
|
|
|
|
|
|
|
|
}) : super(
|
|
|
|
|
|
|
|
position: Vector2(
|
|
|
|
|
|
|
|
flipper.type == FlipperType.left
|
|
|
|
|
|
|
|
? flipper.body.position.x
|
|
|
|
|
|
|
|
: flipper.body.position.x + Flipper.width,
|
|
|
|
|
|
|
|
flipper.body.position.y - Flipper.height / 2,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// {@template flipper_anchor_revolute_joint_def}
|
|
|
|
/// {@template flipper_anchor_revolute_joint_def}
|
|
|
|
/// Hinges one end of [Flipper] to an [Anchor] to achieve an arc motion.
|
|
|
|
/// Hinges one end of [Flipper] to a [Anchor] to achieve an arc motion.
|
|
|
|
/// {@endtemplate}
|
|
|
|
/// {@endtemplate}
|
|
|
|
class FlipperAnchorRevoluteJointDef extends RevoluteJointDef {
|
|
|
|
class FlipperAnchorRevoluteJointDef extends RevoluteJointDef {
|
|
|
|
/// {@macro flipper_anchor_revolute_joint_def}
|
|
|
|
/// {@macro flipper_anchor_revolute_joint_def}
|
|
|
|