From a41b6ee28cbc98b4e0bcf7da9a9e65aaaeab7200 Mon Sep 17 00:00:00 2001 From: alestiago Date: Tue, 8 Mar 2022 16:26:29 +0000 Subject: [PATCH] refactor: reorganized methods --- lib/game/pinball_game.dart | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/game/pinball_game.dart b/lib/game/pinball_game.dart index 8846a8b0..0894333b 100644 --- a/lib/game/pinball_game.dart +++ b/lib/game/pinball_game.dart @@ -10,10 +10,6 @@ class PinballGame extends Forge2DGame late final RevoluteJoint _leftFlipperRevoluteJoint; late final RevoluteJoint _rightFlipperRevoluteJoint; - void spawnBall() { - add(Ball(position: ballStartingPosition)); - } - // TODO(erickzanardo): Change to the plumber position late final ballStartingPosition = screenToWorld( Vector2( @@ -26,6 +22,26 @@ class PinballGame extends Forge2DGame // TODO(alestiago): Change to the design position. late final flippersPosition = ballStartingPosition - Vector2(0, 5); + @override + void onAttach() { + super.onAttach(); + spawnBall(); + } + + void spawnBall() { + add(Ball(position: ballStartingPosition)); + } + + @override + Future onLoad() async { + addContactCallback(BallScorePointsCallback()); + + await add(BottomWall(this)); + addContactCallback(BottomWallBallContactCallback()); + + await _addFlippers(); + } + Future _addFlippers() async { const spaceBetweenFlippers = 2; final leftFlipper = Flipper.left( @@ -85,20 +101,4 @@ class PinballGame extends Forge2DGame ), ); } - - @override - Future onLoad() async { - addContactCallback(BallScorePointsCallback()); - - await add(BottomWall(this)); - addContactCallback(BottomWallBallContactCallback()); - - await _addFlippers(); - } - - @override - void onAttach() { - super.onAttach(); - spawnBall(); - } }