Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tweaks

  • Loading branch information...
commit 7c5002044cdca070f9d5ccea1ae5ad8bd5676d7f 1 parent cdd18f8
@gfx authored
Showing with 10 additions and 13 deletions.
  1. +10 −13 Fireworks.dart
View
23 Fireworks.dart
@@ -63,11 +63,10 @@ class Spark {
view.cx.fill();
- // returns true if it dismissed
- if(size <= 0.1) return true;
- if(posX <= 0 || posY <= 0) return true;
- if(posX >= view.width || posY >= view.height) return true;
- return false;
+ if(size <= 0.1) return false;
+ if(posX <= 0 || posY <= 0) return false;
+ if(posX >= view.width || posY >= view.height) return false;
+ return true;
}
}
@@ -83,17 +82,17 @@ class Firework {
}
}
- void update(CanvasRenderingContext2D cx) {
+ bool update() {
for(int i = 0; i < sparks.length; ++i) {
Spark s = sparks[i];
- if(s.draw(this.view, color)) {
+ if(! s.draw(view, color)) {
sparks.removeRange(i, 1);
}
}
+ return !sparks.isEmpty();
}
- bool dismissed() => sparks.isEmpty();
}
class FireworkView {
@@ -143,13 +142,11 @@ class FireworkView {
for(int i = 0; i < fireworks.length; ++i) {
Firework fw = fireworks[i];
- fw.update(cx);
-
- if(fw.dismissed()) {
- fireworks.removeRange(i, 1);
+ if(fw.update()) {
+ numSparks += fw.sparks.length;
}
else {
- numSparks += fw.sparks.length;
+ fireworks.removeRange(i, 1);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.