mirror of https://github.com/flutter/pinball.git
fix: sanbox stories (#219)
parent
38602c8dba
commit
29ec61ff97
@ -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<void> 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();
|
||||||
|
}
|
||||||
|
}
|
@ -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<void> 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,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +1,15 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
import 'package:dashbook/dashbook.dart';
|
||||||
import 'package:flame/game.dart';
|
import 'package:flame/game.dart';
|
||||||
import 'package:sandbox/common/common.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) {
|
void addBaseboardStories(Dashbook dashbook) {
|
||||||
dashbook.storiesOf('Baseboard').add(
|
dashbook.storiesOf('Baseboard').add(
|
||||||
'Basic',
|
'Basic',
|
||||||
(context) => GameWidget(
|
(context) => GameWidget(
|
||||||
game: BasicBaseboardGame(),
|
game: BaseboardGame()..trace = context.boolProperty('Trace', true),
|
||||||
),
|
),
|
||||||
codeLink: buildSourceLink('baseboard/basic.dart'),
|
codeLink: buildSourceLink('baseboard_game/basic.dart'),
|
||||||
info: BasicBaseboardGame.info,
|
info: BaseboardGame.info,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue