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_bloc/flame_bloc.dart';
|
||||
import 'package:pinball/game/game.dart';
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
import 'package:pinball_flame/pinball_flame.dart';
|
||||
|
||||
/// {@template ramp_multiplier_behavior}
|
||||
/// Increases the multiplier when a [Ball] is shot 5 times into the
|
||||
/// [SpaceshipRamp].
|
||||
/// {@endtemplate}
|
||||
class RampMultiplierBehavior extends Component {
|
||||
/// {@macro ramp_multiplier_behavior}
|
||||
RampMultiplierBehavior() : super();
|
||||
class RampMultiplierBehavior extends Component
|
||||
with FlameBlocListenable<SpaceshipRampCubit, SpaceshipRampState> {
|
||||
@override
|
||||
bool listenWhen(
|
||||
SpaceshipRampState previousState,
|
||||
SpaceshipRampState newState,
|
||||
) {
|
||||
final hasChanged =
|
||||
previousState.hits != newState.hits && newState.hits != 0;
|
||||
final achievedFiveShots = newState.hits % 5 == 0;
|
||||
final canIncrease = readBloc<GameBloc, GameState>().state.multiplier != 6;
|
||||
return hasChanged && achievedFiveShots && canIncrease;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
await super.onLoad();
|
||||
await add(
|
||||
FlameBlocListener<SpaceshipRampCubit, SpaceshipRampState>(
|
||||
listenWhen: (previousState, newState) {
|
||||
final hasChanged =
|
||||
previousState.hits != newState.hits && newState.hits != 0;
|
||||
final achievedFiveShots = newState.hits % 5 == 0;
|
||||
final canIncrease =
|
||||
readBloc<GameBloc, GameState>().state.multiplier != 6;
|
||||
return hasChanged && achievedFiveShots && canIncrease;
|
||||
},
|
||||
onNewState: (state) {
|
||||
readBloc<GameBloc, GameState>().add(const MultiplierIncreased());
|
||||
},
|
||||
),
|
||||
);
|
||||
void onNewState(SpaceshipRampState state) {
|
||||
readBloc<GameBloc, GameState>().add(const MultiplierIncreased());
|
||||
}
|
||||
}
|
||||
|
@ -1,43 +1,34 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flame_bloc/flame_bloc.dart';
|
||||
import 'package:pinball/game/game.dart';
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
import 'package:pinball_flame/pinball_flame.dart';
|
||||
|
||||
/// {@template ramp_progress_behavior}
|
||||
/// Changes arrow lit when a [Ball] is shot into the [SpaceshipRamp].
|
||||
/// {@endtemplate}
|
||||
class RampProgressBehavior extends Component {
|
||||
/// {@macro ramp_progress_behavior}
|
||||
RampProgressBehavior() : super();
|
||||
class RampProgressBehavior extends Component
|
||||
with FlameBlocListenable<SpaceshipRampCubit, SpaceshipRampState> {
|
||||
@override
|
||||
bool listenWhen(
|
||||
SpaceshipRampState previousState,
|
||||
SpaceshipRampState newState,
|
||||
) {
|
||||
return previousState.hits != newState.hits && newState.hits != 0;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
await super.onLoad();
|
||||
await add(
|
||||
FlameBlocListener<SpaceshipRampCubit, SpaceshipRampState>(
|
||||
listenWhen: (previousState, newState) =>
|
||||
previousState.hits != newState.hits && newState.hits != 0,
|
||||
onNewState: (state) {
|
||||
final gameBloc = readBloc<GameBloc, GameState>();
|
||||
final spaceshipCubit =
|
||||
readBloc<SpaceshipRampCubit, SpaceshipRampState>();
|
||||
void onNewState(SpaceshipRampState state) {
|
||||
final gameBloc = readBloc<GameBloc, GameState>();
|
||||
final spaceshipCubit = readBloc<SpaceshipRampCubit, SpaceshipRampState>();
|
||||
|
||||
final canProgress = !gameBloc.state.isMaxMultiplier ||
|
||||
(gameBloc.state.isMaxMultiplier && !state.fullArrowLit);
|
||||
final canProgress = !gameBloc.state.isMaxMultiplier ||
|
||||
(gameBloc.state.isMaxMultiplier && !state.fullArrowLit);
|
||||
|
||||
if (canProgress) {
|
||||
spaceshipCubit.onProgressed();
|
||||
}
|
||||
if (canProgress) {
|
||||
spaceshipCubit.onProgressed();
|
||||
}
|
||||
|
||||
if (spaceshipCubit.state.fullArrowLit &&
|
||||
!gameBloc.state.isMaxMultiplier) {
|
||||
spaceshipCubit.onProgressed();
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
if (spaceshipCubit.state.fullArrowLit && !gameBloc.state.isMaxMultiplier) {
|
||||
spaceshipCubit.onProgressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue