mirror of https://github.com/flutter/pinball.git
parent
1a39737cf6
commit
ada5ada264
@ -1,36 +1,27 @@
|
|||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:flame/components.dart';
|
import 'package:flame/components.dart';
|
||||||
import 'package:flame_bloc/flame_bloc.dart';
|
import 'package:flame_bloc/flame_bloc.dart';
|
||||||
import 'package:pinball/game/game.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_multiplier_behavior}
|
|
||||||
/// Increases the multiplier when a [Ball] is shot 5 times into the
|
/// Increases the multiplier when a [Ball] is shot 5 times into the
|
||||||
/// [SpaceshipRamp].
|
/// [SpaceshipRamp].
|
||||||
/// {@endtemplate}
|
class RampMultiplierBehavior extends Component
|
||||||
class RampMultiplierBehavior extends Component {
|
with FlameBlocListenable<SpaceshipRampCubit, SpaceshipRampState> {
|
||||||
/// {@macro ramp_multiplier_behavior}
|
|
||||||
RampMultiplierBehavior() : super();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> onLoad() async {
|
bool listenWhen(
|
||||||
await super.onLoad();
|
SpaceshipRampState previousState,
|
||||||
await add(
|
SpaceshipRampState newState,
|
||||||
FlameBlocListener<SpaceshipRampCubit, SpaceshipRampState>(
|
) {
|
||||||
listenWhen: (previousState, newState) {
|
|
||||||
final hasChanged =
|
final hasChanged =
|
||||||
previousState.hits != newState.hits && newState.hits != 0;
|
previousState.hits != newState.hits && newState.hits != 0;
|
||||||
final achievedFiveShots = newState.hits % 5 == 0;
|
final achievedFiveShots = newState.hits % 5 == 0;
|
||||||
final canIncrease =
|
final canIncrease = readBloc<GameBloc, GameState>().state.multiplier != 6;
|
||||||
readBloc<GameBloc, GameState>().state.multiplier != 6;
|
|
||||||
return hasChanged && achievedFiveShots && canIncrease;
|
return hasChanged && achievedFiveShots && canIncrease;
|
||||||
},
|
}
|
||||||
onNewState: (state) {
|
|
||||||
|
@override
|
||||||
|
void onNewState(SpaceshipRampState state) {
|
||||||
readBloc<GameBloc, GameState>().add(const MultiplierIncreased());
|
readBloc<GameBloc, GameState>().add(const MultiplierIncreased());
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue