Last active
August 24, 2021 13:11
-
-
Save juskek/47855a06fdcb0ce7dafe7fd60202d641 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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