Skip to content

Instantly share code, notes, and snippets.

@juskek
Last active August 24, 2021 12:46
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/2ac644d266caeefc2ce97b4df0405af3 to your computer and use it in GitHub Desktop.
Save juskek/2ac644d266caeefc2ce97b4df0405af3 to your computer and use it in GitHub Desktop.
...
class FlyTerminator extends Game {
...
List<Fly>? flies;
Random? rnd;
FlyTerminator() {
initialize();
}
void spawnFly() {
double x = rnd!.nextDouble() * (screenSize!.width - tileSize!);
double y = rnd!.nextDouble() * (screenSize!.height - tileSize!);
flies!.add(Fly(this, x, y));
}
void initialize() async {
// flies = List<Fly>(); // returns null
flies = List<Fly>.empty(growable: true); // returns [ ]
...
rnd = Random();
spawnFly();
}
void render(Canvas canvas) {
...
flies!.forEach((Fly fly) => fly.render(canvas));
}
void update(double t) {
flies!.forEach((Fly fly) => fly.update(t));
...
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment