class ParticleList extends ArrayList { void tick() { Iterator i = iterator(); while(i.hasNext()) { Particle p = (Particle) i.next(); p.tick(); if(p.life <= 0) i.remove(); } } void draw() { Iterator i = iterator(); while(i.hasNext()) { Particle p = (Particle) i.next(); p.draw(); } } } boolean inRadius(PVector a, PVector b, float rad) { return rad*rad > (a.x - b.x)*(a.x - b.x) + (a.y - b.y) * (a.y - b.y);// + (a.z - b.z) * (a.z - b.z); } abstract class Particle { PVector pos; PVector vel; PVector accel; int life; int maxlife; Particle(PVector p, PVector v, int lifetime) { this(p, v, new PVector(0, 0), lifetime); } Particle(PVector p, PVector v, PVector a, int lifetime) { accel = new PVector(a.x, a.y); pos = new PVector(p.x, p.y); vel = new PVector(v.x, v.y); life = maxlife = lifetime; } void tick() { vel.add(accel); pos.add(vel); life--; } abstract void draw(); } class PointMark extends Particle { int value; PointMark(PVector p, int points) { super(p, new PVector(0, 0), 180); value = points; } void draw() { textFont(font, 8); if(value >= 100) textFont(font, 16); textAlign(CENTER, CENTER); fill(255, 255.0*life/maxlife); text(""+value, pos.x, pos.y); } } class ShockWave extends Particle { ShockWave(PVector p) { super(p, new PVector(0, 0), 90); } void draw() { noFill(); strokeWeight(5); stroke(255, 255*life/maxlife); float r = SHELL_RADIUS+ (maxlife-life)/(float)maxlife * 100; ellipse(pos.x, pos.y, r, r); strokeWeight(1); } } class Ripple extends Particle { Ripple(PVector p) { super(p, new PVector(0, 0), 90); } void draw() { noFill(); strokeWeight(1); stroke(255, 255*life/maxlife); float r = ENEMY_RADIUS+ (maxlife-life)/(float)maxlife * 30; ellipse(pos.x, pos.y, r, r); strokeWeight(1); } } PVector proj(PVector src, PVector dest) { return PVector.mult(dest, src.dot(dest)/dest.dot(dest)); } void regPoly(float x, float y, float r, int sides, float rot) { beginShape(); for(int i = 0; i < sides; i++) { float segAngle = TWO_PI/sides; vertex(cos(i*segAngle + rot) * r + x, sin(i*segAngle + rot) * r + y); } endShape(CLOSE); } PVector randomVector(float magn) { float angle = random(TWO_PI); return new PVector(cos(angle)*magn, sin(angle)*magn); } color blendColors(color a, color b, float blent) { return color(red(a)*(1-blent)+red(b)*(blent), green(a)*(1-blent)+green(b)*(blent), blue(a)*(1-blent)+blue(b)*(blent)); }