feat: properly deactivated bumpers

pull/190/head
alestiago 3 years ago
parent 00cfe14180
commit fbf333f8b2

@ -28,11 +28,11 @@ class FlutterForest extends Component
final signPost = FlutterSignPost()..initialPosition = Vector2(8.35, 58.3); final signPost = FlutterSignPost()..initialPosition = Vector2(8.35, 58.3);
final bigNest = _BigDashNestBumper() final bigNest = _BigDashNestBumper()
..initialPosition = Vector2(18.55, 59.35); ..initialPosition = Vector2(18.55, -59.35);
final smallLeftNest = _SmallDashNestBumper.a() final smallLeftNest = _SmallDashNestBumper.a()
..initialPosition = Vector2(8.95, 51.95); ..initialPosition = Vector2(8.95, -51.95);
final smallRightNest = _SmallDashNestBumper.b() final smallRightNest = _SmallDashNestBumper.b()
..initialPosition = Vector2(23.3, 46.75); ..initialPosition = Vector2(23.3, -46.75);
final dashAnimatronic = DashAnimatronic()..position = Vector2(20, -66); final dashAnimatronic = DashAnimatronic()..position = Vector2(20, -66);
await addAll([ await addAll([
@ -58,12 +58,11 @@ class _FlutterForestController extends ComponentController<FlutterForest>
final activatedBonus = _activatedBumpers.length == 3; final activatedBonus = _activatedBumpers.length == 3;
if (activatedBonus) { if (activatedBonus) {
children.whereType<DashNestBumper>().forEach(
(dashNestBumper) => dashNestBumper.deactivate(),
);
gameRef.read<GameBloc>().add(const BonusActivated(GameBonus.dashNest)); gameRef.read<GameBloc>().add(const BonusActivated(GameBonus.dashNest));
_addBonusBall(); _addBonusBall();
_activatedBumpers.clear(); _activatedBumpers
..forEach((bumper) => bumper.deactivate())
..clear();
} }
} }

@ -1,6 +1,7 @@
// ignore_for_file: cascade_invocations // ignore_for_file: cascade_invocations
import 'package:bloc_test/bloc_test.dart'; import 'package:bloc_test/bloc_test.dart';
import 'package:flame/components.dart';
import 'package:flame_test/flame_test.dart'; import 'package:flame_test/flame_test.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@ -121,14 +122,14 @@ void main() {
); );
flameBlocTester.testGameWidget( flameBlocTester.testGameWidget(
'adds GameBonus.dashNest to the game when all bumpers are activated', 'adds GameBonus.dashNest to the game when 3 bumpers are activated',
setUp: (game, _) async { setUp: (game, _) async {
final ball = Ball(baseColor: const Color(0xFFFF0000)); final ball = Ball(baseColor: const Color(0xFFFF0000));
final flutterForest = FlutterForest(); final flutterForest = FlutterForest();
await game.ensureAddAll([flutterForest, ball]); await game.ensureAddAll([flutterForest, ball]);
final bumpers = flutterForest.children.whereType<DashNestBumper>(); final bumpers = flutterForest.children.whereType<DashNestBumper>();
expect(bumpers, isNotEmpty); expect(bumpers.length, equals(3));
for (final bumper in bumpers) { for (final bumper in bumpers) {
beginContact(game, bumper, ball); beginContact(game, bumper, ball);
await game.ready(); await game.ready();
@ -145,6 +146,32 @@ void main() {
} }
}, },
); );
flameBlocTester.testGameWidget(
'deactivates bumpers when 3 are active',
setUp: (game, _) async {
final ball = Ball(baseColor: const Color(0xFFFF0000));
final flutterForest = FlutterForest();
await game.ensureAddAll([flutterForest, ball]);
final bumpers = [
MockDashNestBumper(),
MockDashNestBumper(),
MockDashNestBumper(),
];
for (final bumper in bumpers) {
flutterForest.controller.activateBumper(bumper);
await game.ready();
if (bumper == bumpers.last) {
for (final bumper in bumpers) {
verify(bumper.deactivate).called(1);
}
}
}
},
);
}); });
}); });
} }

Loading…
Cancel
Save