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); super.beginContact(other, contact);
if (other is! Ball) return; if (other is! Ball) return;
if (parent.bloc.state.status != ChromeDinoStatus.chomping) { other.firstChild<SpriteComponent>()!.setOpacity(0);
other.firstChild<SpriteComponent>()!.setOpacity(0); parent.bloc.onChomp(other);
parent.bloc.onChomp(other);
}
} }
} }

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

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

Loading…
Cancel
Save