feat: include DashForest area (#49)

* feat: removed Wall friction

* feat: included SlingShot

* feat: adjusted SlingShot size

* feat: included tests

* refactor: fixed tests

* feat: included DashForest

* feat: included tests

* docs: used correct reference

* docs: fixed typo in comment

* docs: improved doc comments

* refactor: used initialPosition API
pull/56/head
Alejandro Santiago 2 years ago committed by GitHub
parent 9fd7078968
commit aba49660c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,15 +1,87 @@
import 'package:flame/components.dart';
import 'package:pinball/game/game.dart';
/// {@template board}
/// The main flat surface of the [PinballGame], where the [Flipper]s,
/// [RoundBumper]s, [SlingShot]s are arranged.
/// {entemplate}
class Board extends Component {
/// {@macro board}
Board({required Vector2 size}) : _size = size;
final Vector2 _size;
@override
Future<void> onLoad() async {
// TODO(alestiago): adjust positioning once sprites are added.
final bottomGroup = _BottomGroup(
position: Vector2(
_size.x / 2,
_size.y / 1.25,
),
spacing: 2,
);
final dashForest = _FlutterForest(
position: Vector2(
_size.x / 1.25,
_size.y / 4.25,
),
);
await addAll([
bottomGroup,
dashForest,
]);
}
}
/// {@template flutter_forest}
/// Area positioned at the top right of the [Board] where the [Ball]
/// can bounce off [RoundBumper]s.
/// {@endtemplate}
class _FlutterForest extends Component {
/// {@macro flutter_forest}
_FlutterForest({
required this.position,
});
final Vector2 position;
@override
Future<void> onLoad() async {
// TODO(alestiago): adjust positioning once sprites are added.
// TODO(alestiago): Use [NestBumper] instead of [RoundBumper] once provided.
final smallLeftNest = RoundBumper(
radius: 1,
points: 10,
)..initialPosition = position + Vector2(-4.8, 2.8);
final smallRightNest = RoundBumper(
radius: 1,
points: 10,
)..initialPosition = position + Vector2(0.5, -5.5);
final bigNest = RoundBumper(
radius: 2,
points: 20,
)..initialPosition = position;
await addAll([
smallLeftNest,
smallRightNest,
bigNest,
]);
}
}
/// {@template bottom_group}
/// Grouping of the board's bottom [Component]s.
///
/// The bottom [Component]s are the [Flipper]s and the [Baseboard]s.
/// The [_BottomGroup] consists of[Flipper]s, [Baseboard]s and [SlingShot]s.
/// {@endtemplate}
// TODO(alestiago): Consider renaming once entire Board is defined.
class BottomGroup extends Component {
class _BottomGroup extends Component {
/// {@macro bottom_group}
BottomGroup({
_BottomGroup({
required this.position,
required this.spacing,
});
@ -17,7 +89,7 @@ class BottomGroup extends Component {
/// The amount of space between the line of symmetry.
final double spacing;
/// The position of this [BottomGroup].
/// The position of this [_BottomGroup].
final Vector2 position;
@override
@ -37,7 +109,7 @@ class BottomGroup extends Component {
}
/// {@template bottom_group_side}
/// Group with one side of [BottomGroup]'s symmetric [Component]s.
/// Group with one side of [_BottomGroup]'s symmetric [Component]s.
///
/// For example, [Flipper]s are symmetric components.
/// {@endtemplate}

@ -49,19 +49,19 @@ class PinballGame extends Forge2DGame
);
unawaited(_addBonusWord());
unawaited(
add(
BottomGroup(
position: screenToWorld(
Vector2(
camera.viewport.effectiveSize.x / 2,
camera.viewport.effectiveSize.y / 1.25,
),
),
spacing: 2,
unawaited(_addBoard());
}
Future<void> _addBoard() async {
final board = Board(
size: screenToWorld(
Vector2(
camera.viewport.effectiveSize.x,
camera.viewport.effectiveSize.y,
),
),
);
await add(board);
}
Future<void> _addBonusWord() async {

@ -11,15 +11,15 @@ void main() {
TestWidgetsFlutterBinding.ensureInitialized();
final flameTester = FlameTester(Forge2DGame.new);
group('BottomGroup', () {
group('Board', () {
flameTester.test(
'loads correctly',
(game) async {
final bottomGroup = BottomGroup(position: Vector2.zero(), spacing: 0);
final board = Board(size: Vector2.all(500));
await game.ready();
await game.ensureAdd(bottomGroup);
await game.ensureAdd(board);
expect(game.contains(bottomGroup), isTrue);
expect(game.contains(board), isTrue);
},
);
@ -27,11 +27,11 @@ void main() {
flameTester.test(
'has one left flipper',
(game) async {
final bottomGroup = BottomGroup(position: Vector2.zero(), spacing: 0);
final board = Board(size: Vector2.all(500));
await game.ready();
await game.ensureAdd(bottomGroup);
await game.ensureAdd(board);
final leftFlippers = bottomGroup.findNestedChildren<Flipper>(
final leftFlippers = board.findNestedChildren<Flipper>(
condition: (flipper) => flipper.side.isLeft,
);
expect(leftFlippers.length, equals(1));
@ -41,11 +41,11 @@ void main() {
flameTester.test(
'has one right flipper',
(game) async {
final bottomGroup = BottomGroup(position: Vector2.zero(), spacing: 0);
final board = Board(size: Vector2.all(500));
await game.ready();
await game.ensureAdd(bottomGroup);
await game.ensureAdd(board);
final rightFlippers = bottomGroup.findNestedChildren<Flipper>(
final rightFlippers = board.findNestedChildren<Flipper>(
condition: (flipper) => flipper.side.isRight,
);
expect(rightFlippers.length, equals(1));
@ -55,11 +55,11 @@ void main() {
flameTester.test(
'has two Baseboards',
(game) async {
final bottomGroup = BottomGroup(position: Vector2.zero(), spacing: 0);
final board = Board(size: Vector2.all(500));
await game.ready();
await game.ensureAdd(bottomGroup);
await game.ensureAdd(board);
final baseboards = bottomGroup.findNestedChildren<Baseboard>();
final baseboards = board.findNestedChildren<Baseboard>();
expect(baseboards.length, equals(2));
},
);
@ -67,14 +67,27 @@ void main() {
flameTester.test(
'has two SlingShots',
(game) async {
final bottomGroup = BottomGroup(position: Vector2.zero(), spacing: 0);
final board = Board(size: Vector2.all(500));
await game.ready();
await game.ensureAdd(bottomGroup);
await game.ensureAdd(board);
final slingShots = bottomGroup.findNestedChildren<SlingShot>();
final slingShots = board.findNestedChildren<SlingShot>();
expect(slingShots.length, equals(2));
},
);
flameTester.test(
'has three RoundBumpers',
(game) async {
// TODO(alestiago): change to [NestBumpers] once provided.
final board = Board(size: Vector2.all(500));
await game.ready();
await game.ensureAdd(board);
final roundBumpers = board.findNestedChildren<RoundBumper>();
expect(roundBumpers.length, equals(3));
},
);
});
});
}

@ -54,10 +54,10 @@ void main() {
},
);
flameTester.test('has only one BottomGroup', (game) async {
flameTester.test('has one Board', (game) async {
await game.ready();
expect(
game.children.whereType<BottomGroup>().length,
game.children.whereType<Board>().length,
equals(1),
);
});

Loading…
Cancel
Save