1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| ...
typedef CheckCollisionCallback = bool Function(GameControl target);
class Asteroids extends GameControl {
final CheckCollisionCallback onCheckCollision;
Asteroids({required this.onCheckCollision});
void _createAsteroid(Size size) {
var _x = _random.nextDouble() * (size.width - ASTEROID_SIZE);
getGameControlGroup()?.addControl(Asteroid(_x, 0, onCheckCollision));
}
...
}
class Asteroid extends GameControl {
Asteroid(double ax, double ay, CheckCollisionCallback onCheckCollision)
{
...
_onCheckCollision = onCheckCollision;
}
@override
void tick(Canvas canvas, Size size, int current, int term) {
...
if (_onCheckCollision != null) {
if (_onCheckCollision!(this)) deleted = true;
}
}
double _speed = 2;
CheckCollisionCallback? _onCheckCollision;
}
|