mirror of https://github.com/flutter/pinball.git
parent
1641fae88e
commit
a346419694
Before Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 17 KiB |
@ -0,0 +1,2 @@
|
||||
export 'kicker_ball_contact_behavior.dart';
|
||||
export 'kicker_blinking_behavior.dart';
|
@ -1 +1,14 @@
|
||||
// ignore_for_file: public_member_api_docs
|
||||
|
||||
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
import 'package:pinball_flame/pinball_flame.dart';
|
||||
|
||||
class KickerBallContactBehavior extends ContactBehavior<Kicker> {
|
||||
@override
|
||||
void beginContact(Object other, Contact contact) {
|
||||
super.beginContact(other, contact);
|
||||
if (other is! Ball) return;
|
||||
parent.bloc.onBallContacted();
|
||||
}
|
||||
}
|
||||
|
@ -1 +1,37 @@
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
import 'package:pinball_flame/pinball_flame.dart';
|
||||
|
||||
/// {@template kicker_blinking_behavior}
|
||||
/// Makes a [Kicker] blink back to [KickerState.lit] when [KickerState.dimmed].
|
||||
/// {@endtemplate}
|
||||
class KickerBlinkingBehavior extends TimerComponent with ParentIsA<Kicker> {
|
||||
/// {@macro kicker_blinking_behavior}
|
||||
KickerBlinkingBehavior() : super(period: 0.05);
|
||||
|
||||
void _onNewState(KickerState state) {
|
||||
switch (state) {
|
||||
case KickerState.lit:
|
||||
break;
|
||||
case KickerState.dimmed:
|
||||
timer
|
||||
..reset()
|
||||
..start();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
await super.onLoad();
|
||||
timer.stop();
|
||||
parent.bloc.stream.listen(_onNewState);
|
||||
}
|
||||
|
||||
@override
|
||||
void onTick() {
|
||||
super.onTick();
|
||||
timer.stop();
|
||||
parent.bloc.onBlinked();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue