refactor: move logic to cubit

pull/301/head
Allison Ryan 3 years ago
parent 93c2c496b6
commit 95f1682365

@ -14,9 +14,7 @@ class ChromeDinoChompingBehavior extends ContactBehavior<ChromeDino> {
super.beginContact(other, contact);
if (other is! Ball) return;
if (parent.bloc.state.status != ChromeDinoStatus.chomping) {
other.firstChild<SpriteComponent>()!.setOpacity(0);
parent.bloc.onChomp(other);
}
}
}

@ -18,8 +18,10 @@ class ChromeDinoCubit extends Cubit<ChromeDinoState> {
}
void onChomp(Ball ball) {
if (ball != state.ball) {
emit(state.copyWith(status: ChromeDinoStatus.chomping, ball: ball));
}
}
void onSpit() {
emit(

@ -26,8 +26,7 @@ void main() {
});
flameTester.test(
'beginContact sets ball sprite to be invisible and calls onChomp '
'when status is not chomping',
'beginContact sets ball sprite to be invisible and calls onChomp',
(game) async {
final ball = Ball(baseColor: Colors.red);
final behavior = ChromeDinoChompingBehavior();

Loading…
Cancel
Save