feat: fixed positioning

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

@ -22,8 +22,8 @@ class Board extends Component {
final dashForest = _FlutterForest( final dashForest = _FlutterForest(
position: Vector2( position: Vector2(
PinballGame.boardBounds.right - 20, PinballGame.boardBounds.right - 20,
PinballGame.boardBounds.top - 20, PinballGame.boardBounds.top - 20,
), ),
); );

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

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

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

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

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

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

Loading…
Cancel
Save