mirror of https://github.com/flutter/pinball.git
feat: included FlutterSignPost (#107)
* feat: loaded flutter_sign_post.png * feat: added board priority * feat: included FlutterSignPost * feat: included tests * refactor: renamed tests names for consistency * chore: refactored exception * docs: fixed incorrect grammar Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * docs: fixed typo * refactor: cleaned SpriteComponent logic Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com>pull/112/head
parent
0b72a28183
commit
dd88114d1c
After Width: | Height: | Size: 8.2 KiB |
@ -0,0 +1,41 @@
|
|||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
|
/// {@template flutter_sign_post}
|
||||||
|
/// A sign, found in the FlutterForest.
|
||||||
|
/// {@endtemplate}
|
||||||
|
// TODO(alestiago): Revisit doc comment if FlutterForest is moved to package.
|
||||||
|
class FlutterSignPost extends BodyComponent with InitialPosition {
|
||||||
|
Future<void> _loadSprite() async {
|
||||||
|
final sprite = await gameRef.loadSprite(
|
||||||
|
Assets.images.flutterSignPost.keyName,
|
||||||
|
);
|
||||||
|
final spriteComponent = SpriteComponent(
|
||||||
|
sprite: sprite,
|
||||||
|
size: sprite.originalSize / 10,
|
||||||
|
anchor: Anchor.bottomCenter,
|
||||||
|
position: Vector2(0.65, 0.45),
|
||||||
|
);
|
||||||
|
await add(spriteComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
paint = Paint()
|
||||||
|
..color = Colors.blue.withOpacity(0.5)
|
||||||
|
..style = PaintingStyle.fill;
|
||||||
|
await _loadSprite();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Body createBody() {
|
||||||
|
final shape = CircleShape()..radius = 0.25;
|
||||||
|
final fixtureDef = FixtureDef(shape);
|
||||||
|
final bodyDef = BodyDef()..position = initialPosition;
|
||||||
|
|
||||||
|
return world.createBody(bodyDef)..createFixture(fixtureDef);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
// ignore_for_file: cascade_invocations
|
||||||
|
|
||||||
|
import 'package:flame_test/flame_test.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
|
import '../../helpers/helpers.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
final flameTester = FlameTester(TestGame.new);
|
||||||
|
|
||||||
|
group('FlutterSignPost', () {
|
||||||
|
flameTester.test(
|
||||||
|
'loads correctly',
|
||||||
|
(game) async {
|
||||||
|
final flutterSignPost = FlutterSignPost();
|
||||||
|
await game.ready();
|
||||||
|
await game.ensureAdd(flutterSignPost);
|
||||||
|
|
||||||
|
expect(game.contains(flutterSignPost), isTrue);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in new issue