From 1ee76a1dfb1d8d163368e44c2b92079bc6ef07f1 Mon Sep 17 00:00:00 2001 From: Allison Ryan Date: Wed, 9 Mar 2022 15:09:11 -0600 Subject: [PATCH] refactor: position ball internally --- lib/game/components/ball.dart | 2 +- lib/game/pinball_game.dart | 11 ++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/game/components/ball.dart b/lib/game/components/ball.dart index 2d9dddf0..5f1bbfd6 100644 --- a/lib/game/components/ball.dart +++ b/lib/game/components/ball.dart @@ -7,7 +7,7 @@ class Ball extends PositionBodyComponent with BlocComponent { Ball({ required Vector2 position, - }) : _position = position, + }) : _position = Vector2(position.x, position.y + ballSize.y), super(size: ballSize); static final ballSize = Vector2.all(2); diff --git a/lib/game/pinball_game.dart b/lib/game/pinball_game.dart index 5d416fca..0c27ee94 100644 --- a/lib/game/pinball_game.dart +++ b/lib/game/pinball_game.dart @@ -44,14 +44,7 @@ class PinballGame extends Forge2DGame } void spawnBall() { - add( - Ball( - position: Vector2( - plunger.body.position.x, - plunger.body.position.y + Ball.ballSize.y, - ), - ), - ); + add(Ball(position: plunger.body.position)); } void _addContactCallbacks() { @@ -138,7 +131,7 @@ class PinballGame extends Forge2DGame position: screenToWorld( Vector2( camera.viewport.effectiveSize.x - 30, - camera.viewport.effectiveSize.y - Plunger.compressionDistance, + camera.viewport.effectiveSize.y, ), ), ),