mirror of https://github.com/flutter/pinball.git
commit
fad93733de
@ -1,23 +0,0 @@
|
||||
<!--
|
||||
Thanks for contributing!
|
||||
|
||||
Provide a description of your changes below and a general summary in the title
|
||||
|
||||
Please look at the following checklist to ensure that your PR can be accepted quickly:
|
||||
-->
|
||||
|
||||
## Description
|
||||
|
||||
<!--- Describe your changes in detail -->
|
||||
|
||||
## Type of Change
|
||||
|
||||
<!--- Put an `x` in all the boxes that apply: -->
|
||||
|
||||
- [ ] ✨ New feature (non-breaking change which adds functionality)
|
||||
- [ ] 🛠️ Bug fix (non-breaking change which fixes an issue)
|
||||
- [ ] ❌ Breaking change (fix or feature that would cause existing functionality to change)
|
||||
- [ ] 🧹 Code refactor
|
||||
- [ ] ✅ Build configuration change
|
||||
- [ ] 📝 Documentation
|
||||
- [ ] 🗑️ Chore
|
@ -1,10 +0,0 @@
|
||||
name: sandbox
|
||||
|
||||
on: [pull_request, push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_package.yml@v1
|
||||
with:
|
||||
flutter_channel: stable
|
||||
flutter_version: 2.10.0
|
@ -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';
|
||||
|
Loading…
Reference in new issue