refactor: changed name for RampBallAscendingContactBehavior

pull/296/head
RuiAlonso 3 years ago
parent bb28113d6b
commit 069809a440

@ -1 +1 @@
export 'ramp_ball_contact_behavior.dart';
export 'ramp_ball_ascending_contact_behavior.dart';

@ -4,20 +4,21 @@ import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_flame/pinball_flame.dart';
/// {@template ramp_ball_contact_behavior}
/// Detects a [Ball]that enters in the [SpaceshipRamp].
/// {@template ramp_ball_ascending_contact_behavior}
/// Detects an ascending [Ball] that enters into the [SpaceshipRamp].
///
/// The [Ball] can hit with sensor to recognize if [Ball] goes in or out the
/// [SpaceshipRamp].
/// The [Ball] can hit with sensor to recognize if a [Ball] goes into or out of
/// the [SpaceshipRamp].
/// {@endtemplate}
class RampBallContactBehavior extends ContactBehavior<RampScoringSensor> {
class RampBallAscendingContactBehavior
extends ContactBehavior<RampScoringSensor> {
@override
void beginContact(Object other, Contact contact) {
super.beginContact(other, contact);
if (other is! Ball) return;
if (other.body.linearVelocity.y < 0) {
parent.parent.bloc.onBallInside();
parent.parent.bloc.onAscendingBallEntered();
}
}
}

@ -8,7 +8,7 @@ part 'spaceship_ramp_state.dart';
class SpaceshipRampCubit extends Cubit<SpaceshipRampState> {
SpaceshipRampCubit() : super(const SpaceshipRampState.initial());
void onBallInside() {
void onAscendingBallEntered() {
emit(
state.copyWith(hits: state.hits + 1),
);

@ -27,11 +27,11 @@ class SpaceshipRamp extends Component {
required this.bloc,
}) : super(
children: [
// TODO(ruimiguel): refactor RampSensor and RampOpening to be in
// only one sensor.
// TODO(ruimiguel): refactor RampScoringSensor and
// _SpaceshipRampOpening to be in only one sensor if possible.
RampScoringSensor(
children: [
RampBallContactBehavior(),
RampBallAscendingContactBehavior(),
],
)..initialPosition = Vector2(1.7, -20.4),
_SpaceshipRampOpening(

@ -54,7 +54,7 @@ class SpaceshipRampGame extends BallGame with KeyboardEvents {
) {
if (event is RawKeyDownEvent &&
event.logicalKey == LogicalKeyboardKey.space) {
_spaceshipRamp.bloc.onBallInside();
_spaceshipRamp.bloc.onAscendingBallEntered();
return KeyEventResult.handled;
}

@ -36,12 +36,12 @@ void main() {
final flameTester = FlameTester(() => TestGame(assets));
group(
'RampBallContactBehavior',
'RampBallAscendingContactBehavior',
() {
test('can be instantiated', () {
expect(
RampBallContactBehavior(),
isA<RampBallContactBehavior>(),
RampBallAscendingContactBehavior(),
isA<RampBallAscendingContactBehavior>(),
);
});
@ -57,9 +57,9 @@ void main() {
});
flameTester.test(
"calls 'onBallInside' when a ball enters into the ramp",
"calls 'onAscendingBallEntered' when a ball enters into the ramp",
(game) async {
final behavior = RampBallContactBehavior();
final behavior = RampBallAscendingContactBehavior();
final bloc = _MockSpaceshipRampCubit();
whenListen(
bloc,
@ -80,14 +80,14 @@ void main() {
behavior.beginContact(ball, _MockContact());
verify(bloc.onBallInside).called(1);
verify(bloc.onAscendingBallEntered).called(1);
},
);
flameTester.test(
"doesn't call 'onBallInside' when a ball goes out the ramp",
"doesn't call 'onAscendingBallEntered' when a ball goes out the ramp",
(game) async {
final behavior = RampBallContactBehavior();
final behavior = RampBallAscendingContactBehavior();
final bloc = _MockSpaceshipRampCubit();
whenListen(
bloc,
@ -108,7 +108,7 @@ void main() {
behavior.beginContact(ball, _MockContact());
verifyNever(bloc.onBallInside);
verifyNever(bloc.onAscendingBallEntered);
},
);
});

@ -6,14 +6,14 @@ import 'package:pinball_components/pinball_components.dart';
void main() {
group('SpaceshipRampCubit', () {
group('onBallInside', () {
group('onAscendingBallEntered', () {
blocTest<SpaceshipRampCubit, SpaceshipRampState>(
'emits hits incremented and arrow goes to the next value',
build: SpaceshipRampCubit.new,
act: (bloc) => bloc
..onBallInside()
..onBallInside()
..onBallInside(),
..onAscendingBallEntered()
..onAscendingBallEntered()
..onAscendingBallEntered(),
expect: () => [
SpaceshipRampState(hits: 1),
SpaceshipRampState(hits: 2),

@ -79,7 +79,7 @@ void main() {
final canvas = ZCanvasComponent(children: [ramp]);
await game.ensureAdd(canvas);
ramp.bloc.onBallInside();
ramp.bloc.onAscendingBallEntered();
await game.ready();
await tester.pump();
@ -112,8 +112,8 @@ void main() {
await game.ensureAdd(canvas);
ramp.bloc
..onBallInside()
..onBallInside();
..onAscendingBallEntered()
..onAscendingBallEntered();
await game.ready();
await tester.pump();
@ -146,9 +146,9 @@ void main() {
await game.ensureAdd(canvas);
ramp.bloc
..onBallInside()
..onBallInside()
..onBallInside();
..onAscendingBallEntered()
..onAscendingBallEntered()
..onAscendingBallEntered();
await game.ready();
await tester.pump();
@ -181,10 +181,10 @@ void main() {
await game.ensureAdd(canvas);
ramp.bloc
..onBallInside()
..onBallInside()
..onBallInside()
..onBallInside();
..onAscendingBallEntered()
..onAscendingBallEntered()
..onAscendingBallEntered()
..onAscendingBallEntered();
await game.ready();
await tester.pump();
@ -217,11 +217,11 @@ void main() {
await game.ensureAdd(canvas);
ramp.bloc
..onBallInside()
..onBallInside()
..onBallInside()
..onBallInside()
..onBallInside();
..onAscendingBallEntered()
..onAscendingBallEntered()
..onAscendingBallEntered()
..onAscendingBallEntered()
..onAscendingBallEntered();
await game.ready();
await tester.pump();

Loading…
Cancel
Save