feat: fixed positioning

pull/70/head
Erick Zanardo 4 years ago
parent 8a435d78f0
commit a9122c8bb9

@ -30,20 +30,23 @@ class JetpackRamp extends Component with HasGameRef<PinballGame> {
// TODO(ruialonso): Use a bezier curve once control points are defined.
color: const Color.fromARGB(255, 8, 218, 241),
center: position,
width: 20,
radius: 60,
width: 5,
radius: 18,
angle: math.pi,
)
..initialPosition = position + Vector2(60, 0)
..layer = layer;
rotation: math.pi,
)..layer = layer;
// TODO figure out the new values for this
final leftOpening = _JetpackRampOpening(outsideLayer: Layer.spaceship)
..initialPosition = position + Vector2(-27.6, 25.3)
final leftOpening = _JetpackRampOpening(
outsideLayer: Layer.spaceship,
rotation: math.pi,
)
..initialPosition = position - Vector2(2, 22)
..layer = Layer.jetpack;
final rightOpening = _JetpackRampOpening()
..initialPosition = position + Vector2(-10.6, 25.3)
final rightOpening = _JetpackRampOpening(
rotation: math.pi,
)
..initialPosition = position - Vector2(-13, 22)
..layer = Layer.opening;
await addAll([
@ -62,20 +65,26 @@ class _JetpackRampOpening extends RampOpening {
/// {@macro jetpack_ramp_opening}
_JetpackRampOpening({
Layer? outsideLayer,
}) : super(
required double rotation,
}) : _rotation = rotation,
super(
pathwayLayer: Layer.jetpack,
outsideLayer: outsideLayer,
orientation: RampOrientation.down,
);
// TODO(ruialonso): Avoid magic number 2, should be proportional to
final double _rotation;
// TODO(ruialonso): Avoid magic number 3, should be propotional to
// [JetpackRamp].
static const _size = 2;
static final Vector2 _size = Vector2(3, .1);
@override
Shape get shape => PolygonShape()
..setAsEdge(
Vector2(initialPosition.x - _size, initialPosition.y),
Vector2(initialPosition.x + _size, initialPosition.y),
..setAsBox(
_size.x,
_size.y,
initialPosition,
_rotation,
);
}

@ -29,27 +29,26 @@ class LauncherRamp extends Component with HasGameRef<PinballGame> {
final straightPath = Pathway.straight(
color: const Color.fromARGB(255, 34, 255, 0),
start: Vector2(position.x, position.y),
end: Vector2(position.x, 620),
width: 25,
end: Vector2(position.x, 74),
width: 5,
)
..initialPosition = position
..layer = layer;
final curvedPath = Pathway.arc(
color: const Color.fromARGB(255, 251, 255, 0),
center: position + Vector2(116, -20),
radius: 80,
angle: 10 * math.pi / 12,
width: 25,
)
..initialPosition = position + Vector2(-28.8, -6)
..layer = layer;
center: position + Vector2(-1, 68),
radius: 20,
angle: 8 * math.pi / 9,
width: 5,
rotation: math.pi,
)..layer = layer;
// TODO figure the new values for the openings
final leftOpening = _LauncherRampOpening(rotation: 13 * math.pi / 180)
..initialPosition = position + Vector2(-72.5, 12)
..initialPosition = position + Vector2(1, 49)
..layer = Layer.opening;
final rightOpening = _LauncherRampOpening(rotation: 0)
..initialPosition = position + Vector2(-46.8, 17)
..initialPosition = position + Vector2(-16, 46)
..layer = Layer.opening;
await addAll([

@ -152,7 +152,7 @@ class Pathway extends BodyComponent with InitialPosition, Layered {
for (final path in _paths) {
final chain = ChainShape()
..createChain(
path.map(gameRef.screenToWorld).toList(),
path.toList(),
);
fixturesDef.add(FixtureDef(chain));
}

@ -16,8 +16,8 @@ class Spaceship extends Forge2DBlueprint {
@override
void build() {
final position = Vector2(
PinballGame.boardBounds.left + radius + 4,
PinballGame.boardBounds.center.dy + 5,
PinballGame.boardBounds.left + radius + 0.5,
PinballGame.boardBounds.center.dy + 34,
);
addAllContactCallback([

@ -83,14 +83,14 @@ class PinballGame extends Forge2DGame
Future<void> _addPaths() async {
final jetpackRamp = JetpackRamp(
position: Vector2(
boardBounds.left - 14,
boardBounds.top - 10,
PinballGame.boardBounds.left + 25,
PinballGame.boardBounds.top - 20,
),
);
final launcherRamp = LauncherRamp(
position: Vector2(
boardBounds.right - 14,
boardBounds.top - 10,
PinballGame.boardBounds.right - 23,
PinballGame.boardBounds.bottom + 40,
),
);

@ -15,7 +15,7 @@ void main() {
flameTester.test(
'loads correctly',
(game) async {
final board = Board(size: Vector2.all(500));
final board = Board();
await game.ready();
await game.ensureAdd(board);
@ -27,7 +27,7 @@ void main() {
flameTester.test(
'has one left flipper',
(game) async {
final board = Board(size: Vector2.all(500));
final board = Board();
await game.ready();
await game.ensureAdd(board);
@ -41,7 +41,7 @@ void main() {
flameTester.test(
'has one right flipper',
(game) async {
final board = Board(size: Vector2.all(500));
final board = Board();
await game.ready();
await game.ensureAdd(board);
@ -55,7 +55,7 @@ void main() {
flameTester.test(
'has two Baseboards',
(game) async {
final board = Board(size: Vector2.all(500));
final board = Board();
await game.ready();
await game.ensureAdd(board);
@ -67,7 +67,7 @@ void main() {
flameTester.test(
'has two SlingShots',
(game) async {
final board = Board(size: Vector2.all(500));
final board = Board();
await game.ready();
await game.ensureAdd(board);
@ -80,7 +80,7 @@ void main() {
'has three RoundBumpers',
(game) async {
// TODO(alestiago): change to [NestBumpers] once provided.
final board = Board(size: Vector2.all(500));
final board = Board();
await game.ready();
await game.ensureAdd(board);

Loading…
Cancel
Save