feat (sandbox): added layers story at sandbox to check collision with nested components (#97)

* feat: added layers story to check collision with nested components

* feat: added more components to layer story

* chore: unused import

* chore: renamed component
pull/104/head
Rui Miguel Alonso 4 years ago committed by GitHub
parent e6eacfa9e7
commit 9f1f9f4466
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -13,6 +13,7 @@ void main() {
final dashbook = Dashbook(theme: ThemeData.dark());
addBallStories(dashbook);
addLayerStories(dashbook);
addEffectsStories(dashbook);
runApp(dashbook);
}

@ -0,0 +1,98 @@
import 'package:flame/input.dart';
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flutter/material.dart';
import 'package:pinball_components/pinball_components.dart';
import 'package:sandbox/common/common.dart';
class BasicLayerGame extends BasicGame with TapDetector {
BasicLayerGame({required this.color});
static const info = '''
Basic example of how layers work with a Ball hitting other components,
tap anywhere on the screen to spawn a ball into the game.
''';
final Color color;
@override
Future<void> onLoad() async {
await add(BigSquare()..initialPosition = Vector2(30, -40));
await add(SmallSquare()..initialPosition = Vector2(50, -40));
await add(UnlayeredSquare()..initialPosition = Vector2(60, -40));
}
@override
void onTapUp(TapUpInfo info) {
add(
Ball(baseColor: color)..initialPosition = info.eventPosition.game,
);
}
}
class BigSquare extends BodyComponent with InitialPosition, Layered {
BigSquare() {
paint = Paint()
..color = const Color.fromARGB(255, 8, 218, 241)
..style = PaintingStyle.stroke;
layer = Layer.jetpack;
}
@override
Body createBody() {
final shape = PolygonShape()..setAsBoxXY(16, 16);
final fixtureDef = FixtureDef(shape);
final bodyDef = BodyDef()..position = initialPosition;
return world.createBody(bodyDef)..createFixture(fixtureDef);
}
@override
Future<void> onLoad() async {
await super.onLoad();
await addAll(
[
UnlayeredSquare()..initialPosition = Vector2.all(4),
SmallSquare()..initialPosition = Vector2.all(-4),
],
);
}
}
class SmallSquare extends BodyComponent with InitialPosition, Layered {
SmallSquare() {
paint = Paint()
..color = const Color.fromARGB(255, 27, 241, 8)
..style = PaintingStyle.stroke;
layer = Layer.board;
}
@override
Body createBody() {
final shape = PolygonShape()..setAsBoxXY(2, 2);
final fixtureDef = FixtureDef(shape);
final bodyDef = BodyDef()..position = initialPosition;
return world.createBody(bodyDef)..createFixture(fixtureDef);
}
}
class UnlayeredSquare extends BodyComponent with InitialPosition {
UnlayeredSquare() {
paint = Paint()
..color = const Color.fromARGB(255, 241, 8, 8)
..style = PaintingStyle.stroke;
}
@override
Body createBody() {
final shape = PolygonShape()..setAsBoxXY(3, 3);
final fixtureDef = FixtureDef(shape);
final bodyDef = BodyDef()..position = initialPosition;
return world.createBody(bodyDef)..createFixture(fixtureDef);
}
}

@ -0,0 +1,18 @@
import 'package:dashbook/dashbook.dart';
import 'package:flame/game.dart';
import 'package:flutter/material.dart';
import 'package:sandbox/common/common.dart';
import 'package:sandbox/stories/layer/basic.dart';
void addLayerStories(Dashbook dashbook) {
dashbook.storiesOf('Layer').add(
'Layer',
(context) => GameWidget(
game: BasicLayerGame(
color: context.colorProperty('color', Colors.blue),
),
),
codeLink: buildSourceLink('layer/basic.dart'),
info: BasicLayerGame.info,
);
}

@ -1 +1,2 @@
export 'ball/ball.dart';
export 'layer/layer.dart';

@ -142,6 +142,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
geometry:
dependency: transitive
description:
path: "../../geometry"
relative: true
source: path
version: "1.0.0+1"
js:
dependency: transitive
description:

Loading…
Cancel
Save