Skip to content

Instantly share code, notes, and snippets.

@juskek
Last active August 24, 2021 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juskek/47855a06fdcb0ce7dafe7fd60202d641 to your computer and use it in GitHub Desktop.
Save juskek/47855a06fdcb0ce7dafe7fd60202d641 to your computer and use it in GitHub Desktop.
...
class FlyTerminator extends Game with TapDetector {
...
void spawnFly() {
...
flies!.add(Fly(this, x, y));
}
void update(double t) {
...
flies!.removeWhere((Fly fly) => fly.isOffScreen);
}
void onTapDown(TapDownDetails tapDownDetails) {
// flies!.forEach((Fly fly) {
// if (fly.flyRect!.contains(tapDownDetails.globalPosition)) {
// fly.onTapDown();
// }
// });
for (int i = 0; i < flies!.length; i++) {
if (flies![i].flyRect!.contains(tapDownDetails.globalPosition)) {
flies![i].onTapDown();
}
}
}
}
class Fly {
...
void update(double t) {
if (isDead) {
flyRect = flyRect!.translate(0, game.tileSize! * 12 * t);
}
if (flyRect!.top > game.screenSize!.height) {
isOffScreen = true;
}
}
void onTapDown() {
flyPaint.color = Color(0xffff4757);
isDead = true;
game.spawnFly();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment