diff --git a/packages/pinball_components/sandbox/lib/stories/baseboard/baseboard_game.dart b/packages/pinball_components/sandbox/lib/stories/baseboard/baseboard_game.dart new file mode 100644 index 00000000..3dab5c6f --- /dev/null +++ b/packages/pinball_components/sandbox/lib/stories/baseboard/baseboard_game.dart @@ -0,0 +1,38 @@ +import 'package:flame_forge2d/flame_forge2d.dart'; +import 'package:pinball_components/pinball_components.dart'; +import 'package:sandbox/common/common.dart'; +import 'package:sandbox/stories/ball/basic_ball_game.dart'; + +class BaseboardGame extends BasicBallGame with Traceable { + static const info = ''' + Shows how the Baseboards are rendered. + + - Activate the "trace" parameter to overlay the body. + - Tap anywhere on the screen to spawn a ball into the game. +'''; + + @override + Future onLoad() async { + await super.onLoad(); + + await images.loadAll([ + Assets.images.baseboard.left.keyName, + Assets.images.baseboard.right.keyName, + ]); + + final center = screenToWorld(camera.viewport.canvasSize! / 2); + final leftBaseboard = Baseboard(side: BoardSide.left) + ..initialPosition = center - Vector2(25, 0) + ..priority = 1; + final rightBaseboard = Baseboard(side: BoardSide.right) + ..initialPosition = center + Vector2(25, 0) + ..priority = 1; + + await addAll([ + leftBaseboard, + rightBaseboard, + ]); + + await traceAllBodies(); + } +} diff --git a/packages/pinball_components/sandbox/lib/stories/baseboard/basic_baseboard_game.dart b/packages/pinball_components/sandbox/lib/stories/baseboard/basic_baseboard_game.dart deleted file mode 100644 index 0650fa13..00000000 --- a/packages/pinball_components/sandbox/lib/stories/baseboard/basic_baseboard_game.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:flame_forge2d/flame_forge2d.dart'; -import 'package:pinball_components/pinball_components.dart'; -import 'package:sandbox/common/common.dart'; - -class BasicBaseboardGame extends BasicGame { - static const info = 'Shows how a Baseboard works.'; - - @override - Future onLoad() async { - await super.onLoad(); - - final center = screenToWorld(camera.viewport.canvasSize! / 2); - - final leftBaseboard = Baseboard(side: BoardSide.left) - ..initialPosition = center - Vector2(25, 0); - final rightBaseboard = Baseboard(side: BoardSide.right) - ..initialPosition = center + Vector2(25, 0); - - await addAll([ - leftBaseboard, - rightBaseboard, - ]); - } -} diff --git a/packages/pinball_components/sandbox/lib/stories/baseboard/stories.dart b/packages/pinball_components/sandbox/lib/stories/baseboard/stories.dart index b3982af4..2e4d3090 100644 --- a/packages/pinball_components/sandbox/lib/stories/baseboard/stories.dart +++ b/packages/pinball_components/sandbox/lib/stories/baseboard/stories.dart @@ -1,15 +1,15 @@ import 'package:dashbook/dashbook.dart'; import 'package:flame/game.dart'; import 'package:sandbox/common/common.dart'; -import 'package:sandbox/stories/baseboard/basic_baseboard_game.dart'; +import 'package:sandbox/stories/baseboard/baseboard_game.dart'; void addBaseboardStories(Dashbook dashbook) { dashbook.storiesOf('Baseboard').add( 'Basic', (context) => GameWidget( - game: BasicBaseboardGame(), + game: BaseboardGame()..trace = context.boolProperty('Trace', true), ), - codeLink: buildSourceLink('baseboard/basic.dart'), - info: BasicBaseboardGame.info, + codeLink: buildSourceLink('baseboard_game/basic.dart'), + info: BaseboardGame.info, ); } diff --git a/packages/pinball_components/sandbox/lib/stories/boundaries/boundaries_game.dart b/packages/pinball_components/sandbox/lib/stories/boundaries/boundaries_game.dart index ab984045..ca7c8cc8 100644 --- a/packages/pinball_components/sandbox/lib/stories/boundaries/boundaries_game.dart +++ b/packages/pinball_components/sandbox/lib/stories/boundaries/boundaries_game.dart @@ -16,6 +16,11 @@ class BoundariesGame extends BasicBallGame with Traceable { Future onLoad() async { await super.onLoad(); + await images.loadAll([ + Assets.images.boundary.outer.keyName, + Assets.images.boundary.bottom.keyName, + ]); + await addFromBlueprint(Boundaries()); await ready(); diff --git a/packages/pinball_components/sandbox/lib/stories/flipper/flipper_game.dart b/packages/pinball_components/sandbox/lib/stories/flipper/flipper_game.dart index c0dfee24..40a638b9 100644 --- a/packages/pinball_components/sandbox/lib/stories/flipper/flipper_game.dart +++ b/packages/pinball_components/sandbox/lib/stories/flipper/flipper_game.dart @@ -33,6 +33,11 @@ class FlipperGame extends BasicBallGame with KeyboardEvents, Traceable { Future onLoad() async { await super.onLoad(); + await images.loadAll([ + Assets.images.flipper.left.keyName, + Assets.images.flipper.right.keyName, + ]); + final center = screenToWorld(camera.viewport.canvasSize! / 2); leftFlipper = Flipper(side: BoardSide.left) diff --git a/packages/pinball_components/sandbox/lib/stories/slingshot/slingshot_game.dart b/packages/pinball_components/sandbox/lib/stories/slingshot/slingshot_game.dart index 7d941099..a0f54ea4 100644 --- a/packages/pinball_components/sandbox/lib/stories/slingshot/slingshot_game.dart +++ b/packages/pinball_components/sandbox/lib/stories/slingshot/slingshot_game.dart @@ -15,6 +15,12 @@ class SlingshotGame extends BasicBallGame with Traceable { @override Future onLoad() async { await super.onLoad(); + + await images.loadAll([ + Assets.images.slingshot.upper.keyName, + Assets.images.slingshot.lower.keyName, + ]); + await addFromBlueprint(Slingshots()); camera.followVector2(Vector2.zero()); await traceAllBodies();