mirror of https://github.com/flutter/pinball.git
commit
97208adfd8
@ -1,2 +1,3 @@
|
||||
export 'games.dart';
|
||||
export 'methods.dart';
|
||||
export 'trace.dart';
|
||||
|
@ -0,0 +1,19 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
extension BodyTrace on BodyComponent {
|
||||
void trace({Color color = const Color(0xFFFF0000)}) {
|
||||
paint = Paint()..color = color;
|
||||
renderBody = true;
|
||||
|
||||
unawaited(
|
||||
mounted.whenComplete(() {
|
||||
final sprite = children.whereType<SpriteComponent>().first;
|
||||
sprite.paint.color = sprite.paint.color.withOpacity(0.5);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
import 'package:dashbook/dashbook.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:sandbox/common/common.dart';
|
||||
import 'package:sandbox/stories/baseboard/basic.dart';
|
||||
import 'package:sandbox/stories/baseboard/basic_baseboard_game.dart';
|
||||
|
||||
void addBaseboardStories(Dashbook dashbook) {
|
||||
dashbook.storiesOf('Baseboard').add(
|
@ -0,0 +1,14 @@
|
||||
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
|
||||
class ChromeDinoGame extends Forge2DGame {
|
||||
static const info = 'Shows how a ChromeDino is rendered.';
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
await super.onLoad();
|
||||
|
||||
camera.followVector2(Vector2.zero());
|
||||
await add(ChromeDino());
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
import 'package:dashbook/dashbook.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:sandbox/common/common.dart';
|
||||
import 'package:sandbox/stories/chrome_dino/chrome_dino_game.dart';
|
||||
|
||||
void addChromeDinoStories(Dashbook dashbook) {
|
||||
dashbook.storiesOf('Chrome Dino').add(
|
||||
'Basic',
|
||||
(context) => GameWidget(
|
||||
game: ChromeDinoGame(),
|
||||
),
|
||||
codeLink: buildSourceLink('chrome_dino/basic.dart'),
|
||||
info: ChromeDinoGame.info,
|
||||
);
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
import 'dart:async';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
import 'package:sandbox/common/common.dart';
|
||||
import 'package:sandbox/stories/ball/basic_ball_game.dart';
|
||||
|
||||
class BigDashNestBumperGame extends BasicBallGame {
|
||||
BigDashNestBumperGame({
|
||||
required this.trace,
|
||||
}) : super(color: const Color(0xFF0000FF));
|
||||
|
||||
static const info = '''
|
||||
Shows how a BigDashNestBumper is rendered.
|
||||
|
||||
Activate the "trace" parameter to overlay the body.
|
||||
''';
|
||||
|
||||
final bool trace;
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
await super.onLoad();
|
||||
|
||||
final center = screenToWorld(camera.viewport.canvasSize! / 2);
|
||||
final bigDashNestBumper = BigDashNestBumper()
|
||||
..initialPosition = center
|
||||
..priority = 1;
|
||||
await add(bigDashNestBumper);
|
||||
|
||||
if (trace) bigDashNestBumper.trace();
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
import 'package:dashbook/dashbook.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:sandbox/common/common.dart';
|
||||
import 'package:sandbox/stories/ball/basic_ball_game.dart';
|
||||
import 'package:sandbox/stories/dash_nest_bumper/big_dash_nest_bumper_game.dart';
|
||||
|
||||
void addDashNestBumperStories(Dashbook dashbook) {
|
||||
dashbook.storiesOf('Dash Nest Bumpers').add(
|
||||
'Big',
|
||||
(context) => GameWidget(
|
||||
game: BigDashNestBumperGame(
|
||||
trace: context.boolProperty('Trace', true),
|
||||
),
|
||||
),
|
||||
codeLink: buildSourceLink('dash_nest_bumper/big.dart'),
|
||||
info: BasicBallGame.info,
|
||||
);
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
import 'package:dashbook/dashbook.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:sandbox/common/common.dart';
|
||||
import 'package:sandbox/stories/effects/fire_effect.dart';
|
||||
import 'package:sandbox/stories/effects/fire_effect_game.dart';
|
||||
|
||||
void addEffectsStories(Dashbook dashbook) {
|
||||
dashbook.storiesOf('Effects').add(
|
||||
'Fire Effect',
|
||||
(context) => GameWidget(game: FireEffectExample()),
|
||||
(context) => GameWidget(game: FireEffectGame()),
|
||||
codeLink: buildSourceLink('effects/fire_effect.dart'),
|
||||
info: FireEffectExample.info,
|
||||
info: FireEffectGame.info,
|
||||
);
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||
import 'package:sandbox/common/common.dart';
|
||||
import 'package:sandbox/stories/flipper/basic_flipper_game.dart';
|
||||
|
||||
class FlipperTracingGame extends BasicFlipperGame {
|
||||
static const info = '''
|
||||
Basic example of how the Flipper body overlays the sprite.
|
||||
''';
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
await super.onLoad();
|
||||
|
||||
leftFlipper.trace();
|
||||
leftFlipper.body.joints.whereType<RevoluteJoint>().forEach(
|
||||
(joint) => joint.setLimits(0, 0),
|
||||
);
|
||||
|
||||
rightFlipper.trace();
|
||||
rightFlipper.body.joints.whereType<RevoluteJoint>().forEach(
|
||||
(joint) => joint.setLimits(0, 0),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
import 'package:dashbook/dashbook.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:sandbox/common/common.dart';
|
||||
import 'package:sandbox/stories/flipper/basic.dart';
|
||||
import 'package:sandbox/stories/flipper/tracing.dart';
|
||||
import 'package:sandbox/stories/flipper/basic_flipper_game.dart';
|
||||
import 'package:sandbox/stories/flipper/flipper_tracing_game.dart';
|
||||
|
||||
void addFlipperStories(Dashbook dashbook) {
|
||||
dashbook.storiesOf('Flipper')
|
@ -1,36 +0,0 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:sandbox/stories/flipper/basic.dart';
|
||||
|
||||
class FlipperTracingGame extends BasicFlipperGame {
|
||||
static const info = '''
|
||||
Basic example of how the Flipper body overlays the sprite.
|
||||
''';
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
await super.onLoad();
|
||||
leftFlipper.trace();
|
||||
rightFlipper.trace();
|
||||
}
|
||||
}
|
||||
|
||||
extension on BodyComponent {
|
||||
void trace({Color color = Colors.red}) {
|
||||
paint = Paint()..color = color;
|
||||
renderBody = true;
|
||||
body.joints.whereType<RevoluteJoint>().forEach(
|
||||
(joint) => joint.setLimits(0, 0),
|
||||
);
|
||||
|
||||
unawaited(
|
||||
mounted.whenComplete(() {
|
||||
final sprite = children.whereType<SpriteComponent>().first;
|
||||
sprite.paint.color = sprite.paint.color.withOpacity(0.5);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,13 +1,15 @@
|
||||
import 'package:dashbook/dashbook.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:sandbox/common/common.dart';
|
||||
import 'package:sandbox/stories/spaceship/basic.dart';
|
||||
import 'package:sandbox/stories/spaceship/basic_spaceship_game.dart';
|
||||
|
||||
void addSpaceshipStories(Dashbook dashbook) {
|
||||
dashbook.storiesOf('Spaceship').add(
|
||||
'Basic',
|
||||
(context) => GameWidget(game: BasicSpaceship()),
|
||||
(context) => GameWidget(
|
||||
game: BasicSpaceshipGame(),
|
||||
),
|
||||
codeLink: buildSourceLink('spaceship/basic.dart'),
|
||||
info: BasicSpaceship.info,
|
||||
info: BasicSpaceshipGame.info,
|
||||
);
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
export 'ball/ball.dart';
|
||||
export 'baseboard/baseboard.dart';
|
||||
export 'effects/effects.dart';
|
||||
export 'flipper/flipper.dart';
|
||||
export 'layer/layer.dart';
|
||||
export 'ball/stories.dart';
|
||||
export 'baseboard/stories.dart';
|
||||
export 'chrome_dino/stories.dart';
|
||||
export 'dash_nest_bumper/stories.dart';
|
||||
export 'effects/stories.dart';
|
||||
export 'flipper/stories.dart';
|
||||
export 'layer/stories.dart';
|
||||
export 'spaceship/stories.dart';
|
||||
|
Loading…
Reference in new issue