Merge branch 'main' into feat/add-dino-wall

pull/115/head
RuiAlonso 4 years ago
commit 7c7cbca393

3
.gitignore vendored

@ -131,3 +131,6 @@ app.*.map.json
test/.test_runner.dart
web/__/firebase/init.js
# Application exceptions
!/packages/pinball_components/assets/images/flutter_sign_post.png

@ -7,7 +7,8 @@ import 'package:pinball_components/pinball_components.dart';
/// {endtemplate}
class Board extends Component {
/// {@macro board}
Board();
// TODO(alestiago): Make Board a Blueprint and sort out priorities.
Board() : super(priority: 5);
@override
Future<void> onLoad() async {

@ -43,6 +43,8 @@ class FlutterForest extends Component
Future<void> onLoad() async {
gameRef.addContactCallback(DashNestBumperBallContactCallback());
final signPost = FlutterSignPost()..initialPosition = Vector2(8.35, 58.3);
// TODO(alestiago): adjust positioning once sprites are added.
final smallLeftNest = SmallDashNestBumper(id: 'small_left_nest')
..initialPosition = Vector2(8.95, 51.95);
@ -52,6 +54,7 @@ class FlutterForest extends Component
..initialPosition = Vector2(18.55, 59.35);
await addAll([
signPost,
smallLeftNest,
smallRightNest,
bigNest,

@ -8,6 +8,7 @@ extension PinballGameAssetsX on PinballGame {
Future<void> preLoadAssets() async {
await Future.wait([
images.load(components.Assets.images.ball.keyName),
images.load(components.Assets.images.flutterSignPost.keyName),
images.load(components.Assets.images.flipper.left.keyName),
images.load(components.Assets.images.flipper.right.keyName),
images.load(Assets.images.components.background.path),

@ -49,7 +49,7 @@ class PinballGame extends Forge2DGame
unawaited(
addFromBlueprint(
Spaceship(
position: Vector2(-25, 32),
position: Vector2(-26.5, 28.5),
),
),
);

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

@ -3,15 +3,27 @@
/// FlutterGen
/// *****************************************************
// ignore_for_file: directives_ordering,unnecessary_import
import 'package:flutter/widgets.dart';
class $AssetsImagesGen {
const $AssetsImagesGen();
/// File path: assets/images/ball.png
AssetGenImage get ball => const AssetGenImage('assets/images/ball.png');
$AssetsImagesFlipperGen get flipper => const $AssetsImagesFlipperGen();
/// File path: assets/images/flutter_sign_post.png
AssetGenImage get flutterSignPost =>
const AssetGenImage('assets/images/flutter_sign_post.png');
/// File path: assets/images/spaceship_bridge.png
AssetGenImage get spaceshipBridge =>
const AssetGenImage('assets/images/spaceship_bridge.png');
/// File path: assets/images/spaceship_saucer.png
AssetGenImage get spaceshipSaucer =>
const AssetGenImage('assets/images/spaceship_saucer.png');
}
@ -19,8 +31,11 @@ class $AssetsImagesGen {
class $AssetsImagesFlipperGen {
const $AssetsImagesFlipperGen();
/// File path: assets/images/flipper/left.png
AssetGenImage get left =>
const AssetGenImage('assets/images/flipper/left.png');
/// File path: assets/images/flipper/right.png
AssetGenImage get right =>
const AssetGenImage('assets/images/flipper/right.png');
}

@ -2,6 +2,7 @@ export 'ball.dart';
export 'board_side.dart';
export 'fire_effect.dart';
export 'flipper.dart';
export 'flutter_sign_post.dart';
export 'initial_position.dart';
export 'joint_anchor.dart';
export 'layer.dart';

@ -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);
}
}

@ -16,7 +16,7 @@ class Spaceship extends Forge2DBlueprint {
Spaceship({required this.position});
/// Total size of the spaceship.
static final size = Vector2(24, 18);
static final size = Vector2(25, 19);
/// The [position] where the elements will be created
final Vector2 position;
@ -32,8 +32,8 @@ class Spaceship extends Forge2DBlueprint {
SpaceshipSaucer()..initialPosition = position,
SpaceshipEntrance()..initialPosition = position,
AndroidHead()..initialPosition = position,
SpaceshipHole()..initialPosition = position - Vector2(4.8, 4.2),
SpaceshipHole()..initialPosition = position - Vector2(-7.2, 0.6),
SpaceshipHole()..initialPosition = position - Vector2(5.2, 4.8),
SpaceshipHole()..initialPosition = position - Vector2(-7.2, 0.8),
SpaceshipWall()..initialPosition = position,
]);
}
@ -180,16 +180,17 @@ class SpaceshipHole extends BodyComponent with InitialPosition, Layered {
@override
Body createBody() {
renderBody = false;
final circleShape = CircleShape()..radius = 1.5;
final shape = ArcShape(center: Vector2(-3.5, 2), arcRadius: 6, angle: 1);
final bodyDef = BodyDef()
..userData = this
..position = initialPosition
..angle = 5.2
..type = BodyType.static;
return world.createBody(bodyDef)
..createFixture(
FixtureDef(circleShape)..isSensor = true,
FixtureDef(shape)..isSensor = true,
);
}
}
@ -237,7 +238,7 @@ class SpaceshipWall extends BodyComponent with InitialPosition, Layered {
final bodyDef = BodyDef()
..userData = this
..position = initialPosition
..angle = 90 * pi / 180
..angle = 90 * pi / 172
..type = BodyType.static;
return world.createBody(bodyDef)

@ -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);
},
);
});
}

@ -23,9 +23,9 @@ void main() {
},
);
group('children', () {
group('loads', () {
flameTester.test(
'has one left flipper',
'one left flipper',
(game) async {
final board = Board();
await game.ready();
@ -39,7 +39,7 @@ void main() {
);
flameTester.test(
'has one right flipper',
'one right flipper',
(game) async {
final board = Board();
await game.ready();
@ -52,7 +52,7 @@ void main() {
);
flameTester.test(
'has two Baseboards',
'two Baseboards',
(game) async {
final board = Board();
await game.ready();
@ -64,7 +64,7 @@ void main() {
);
flameTester.test(
'has two Kickers',
'two Kickers',
(game) async {
final board = Board();
await game.ready();
@ -76,7 +76,7 @@ void main() {
);
flameTester.test(
'has one FlutterForest',
'one FlutterForest',
(game) async {
// TODO(alestiago): change to [NestBumpers] once provided.
final board = Board();
@ -89,7 +89,7 @@ void main() {
);
flameTester.test(
'has one ChromeDino',
'one ChromeDino',
(game) async {
final board = Board();
await game.ready();

@ -25,6 +25,22 @@ void main() {
},
);
group('loads', () {
flameTester.test(
'a FlutterSignPost',
(game) async {
await game.ready();
final flutterForest = FlutterForest();
await game.ensureAdd(flutterForest);
expect(
game.descendants().whereType<FlutterSignPost>().length,
equals(1),
);
},
);
});
flameTester.test(
'onNewState adds a new ball',
(game) async {

Loading…
Cancel
Save