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.
31 lines
874 B
31 lines
874 B
3 years ago
|
// ignore_for_file: avoid_renaming_method_parameters
|
||
|
|
||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||
|
import 'package:pinball/game/game.dart';
|
||
|
|
||
|
/// {@template score_points}
|
||
|
/// Specifies the amount of points received on [Ball] collision.
|
||
|
/// {@endtemplate}
|
||
|
mixin ScorePoints on BodyComponent {
|
||
|
/// {@macro score_points}
|
||
|
int get points;
|
||
|
}
|
||
|
|
||
|
/// Adds points to the score when a [Ball] collides with a [BodyComponent] that
|
||
|
/// implements [ScorePoints].
|
||
|
class BallScorePointsCallback extends ContactCallback<Ball, ScorePoints> {
|
||
|
@override
|
||
|
void begin(
|
||
|
Ball ball,
|
||
|
ScorePoints hasPoints,
|
||
|
Contact _,
|
||
|
) {
|
||
|
ball.gameRef.read<GameBloc>().add(Scored(points: hasPoints.points));
|
||
|
}
|
||
|
|
||
|
// TODO(alestiago): remove once this issue is closed.
|
||
|
// https://github.com/flame-engine/flame/issues/1414
|
||
|
@override
|
||
|
void end(Ball _, ScorePoints __, Contact ___) {}
|
||
|
}
|