|
|
@ -4,15 +4,13 @@ import 'package:flame/components.dart';
|
|
|
|
import 'package:flame_bloc/flame_bloc.dart';
|
|
|
|
import 'package:flame_bloc/flame_bloc.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:pinball/game/behaviors/behaviors.dart';
|
|
|
|
import 'package:pinball/game/behaviors/behaviors.dart';
|
|
|
|
import 'package:pinball/game/game.dart';
|
|
|
|
|
|
|
|
import 'package:pinball_components/pinball_components.dart';
|
|
|
|
import 'package:pinball_components/pinball_components.dart';
|
|
|
|
import 'package:pinball_flame/pinball_flame.dart';
|
|
|
|
import 'package:pinball_flame/pinball_flame.dart';
|
|
|
|
|
|
|
|
|
|
|
|
/// {@template ramp_shot_behavior}
|
|
|
|
/// {@template ramp_shot_behavior}
|
|
|
|
/// Increases the score when a [Ball] is shot into the [SpaceshipRamp].
|
|
|
|
/// Increases the score when a [Ball] is shot into the [SpaceshipRamp].
|
|
|
|
/// {@endtemplate}
|
|
|
|
/// {@endtemplate}
|
|
|
|
class RampShotBehavior extends Component
|
|
|
|
class RampShotBehavior extends Component with ParentIsA<SpaceshipRamp> {
|
|
|
|
with ParentIsA<SpaceshipRamp>, FlameBlocReader<GameBloc, GameState> {
|
|
|
|
|
|
|
|
/// {@macro ramp_shot_behavior}
|
|
|
|
/// {@macro ramp_shot_behavior}
|
|
|
|
RampShotBehavior({
|
|
|
|
RampShotBehavior({
|
|
|
|
required Points points,
|
|
|
|
required Points points,
|
|
|
@ -25,38 +23,27 @@ class RampShotBehavior extends Component
|
|
|
|
@visibleForTesting
|
|
|
|
@visibleForTesting
|
|
|
|
RampShotBehavior.test({
|
|
|
|
RampShotBehavior.test({
|
|
|
|
required Points points,
|
|
|
|
required Points points,
|
|
|
|
required this.subscription,
|
|
|
|
|
|
|
|
}) : _points = points,
|
|
|
|
}) : _points = points,
|
|
|
|
super();
|
|
|
|
super();
|
|
|
|
|
|
|
|
|
|
|
|
final Points _points;
|
|
|
|
final Points _points;
|
|
|
|
|
|
|
|
|
|
|
|
/// Subscription to [SpaceshipRampState] at [SpaceshipRamp].
|
|
|
|
|
|
|
|
@visibleForTesting
|
|
|
|
|
|
|
|
StreamSubscription? subscription;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
void onMount() {
|
|
|
|
|
|
|
|
super.onMount();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
subscription = subscription ??
|
|
|
|
|
|
|
|
parent.bloc.stream.listen((state) {
|
|
|
|
|
|
|
|
final achievedOneMillionPoints = state.hits % 10 == 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!achievedOneMillionPoints) {
|
|
|
|
|
|
|
|
parent.add(
|
|
|
|
|
|
|
|
ScoringBehavior(
|
|
|
|
|
|
|
|
points: _points,
|
|
|
|
|
|
|
|
position: Vector2(0, -45),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
void onRemove() {
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
subscription?.cancel();
|
|
|
|
await super.onLoad();
|
|
|
|
super.onRemove();
|
|
|
|
await add(
|
|
|
|
|
|
|
|
FlameBlocListener<SpaceshipRampCubit, SpaceshipRampState>(
|
|
|
|
|
|
|
|
listenWhen: (previousState, newState) =>
|
|
|
|
|
|
|
|
previousState.hits != newState.hits && newState.hits != 0,
|
|
|
|
|
|
|
|
onNewState: (state) {
|
|
|
|
|
|
|
|
parent.add(
|
|
|
|
|
|
|
|
ScoringBehavior(
|
|
|
|
|
|
|
|
points: _points,
|
|
|
|
|
|
|
|
position: Vector2(0, -45),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|