mirror of https://github.com/flutter/pinball.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.1 KiB
44 lines
1.1 KiB
// ignore_for_file: avoid_renaming_method_parameters
|
|
|
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
import 'package:pinball/game/game.dart';
|
|
import 'package:pinball_components/pinball_components.dart';
|
|
|
|
/// {@template score_points}
|
|
/// Specifies the amount of points received on [Ball] collision.
|
|
/// {@endtemplate}
|
|
mixin ScorePoints<T extends Forge2DGame> on BodyComponent<T> {
|
|
/// {@macro score_points}
|
|
int get points;
|
|
|
|
@override
|
|
Future<void> onLoad() async {
|
|
await super.onLoad();
|
|
body.userData = this;
|
|
}
|
|
}
|
|
|
|
/// {@template ball_score_points_callbacks}
|
|
/// Adds points to the score when a [Ball] collides with a [BodyComponent] that
|
|
/// implements [ScorePoints].
|
|
/// {@endtemplate}
|
|
class BallScorePointsCallback extends ContactCallback<Ball, ScorePoints> {
|
|
/// {@macro ball_score_points_callbacks}
|
|
BallScorePointsCallback(PinballGame game) : _gameRef = game;
|
|
|
|
final PinballGame _gameRef;
|
|
|
|
@override
|
|
void begin(
|
|
Ball _,
|
|
ScorePoints scorePoints,
|
|
Contact __,
|
|
) {
|
|
_gameRef.read<GameBloc>().add(
|
|
Scored(points: scorePoints.points),
|
|
);
|
|
|
|
_gameRef.audio.score();
|
|
}
|
|
}
|