class Pulser { Particle p; int followDist; private float radius, currRadius, pulseAmt; boolean follow, pulsing, rendered; private color c; Pulser (Particle ip, float r, int fd, float pa, color ic) { p = ip; radius = currRadius = r; followDist = fd + int(r); pulseAmt = pa; c = ic; follow = false; pulsing = false; } boolean isFree() { return !follow; } boolean isFollowing() { return follow; } boolean isOffScreen() { if ( x() < -currRadius ) return true; if ( x() > width + currRadius ) return true; if ( y() < -currRadius ) return true; if ( y() > height + currRadius ) return true; return false; } boolean isDead() { return p.isDead(); } void follow() { follow = true; c = color(red(c), green(c), blue(c), 255); } void render() { smooth(); noStroke(); fill(c); ellipse(x(), y(), currRadius*2, currRadius*2); if ( pulsing ) { currRadius *= .95; if ( currRadius < radius ) { currRadius = radius; pulsing = false; } } rendered = true; if ( follow ) println(" RENDERED FOLLOWER"); else println(" RENDERED FLOATER"); } void pulse() { if ( !pulsing ) { pulsing = true; currRadius = radius * pulseAmt; } } void wallBounce() { int force = pulsing ? 8 : 2; if ( x() < currRadius ) p.setVelocity(force, vy(), 0); if ( x() > width - currRadius ) p.setVelocity(-force, vy(), 0); if ( y() < currRadius ) p.setVelocity(vx(), force, 0); if ( y() > height - currRadius ) p.setVelocity(vx(), -force, 0); } void pulseBounce(Pulser puls) { if ( puls == this ) return; if ( distFrom(puls) < currRadius + puls.currRadius + 5) { int force = pulsing ? 2 : 3; float cx = puls.x() - x(); float cy = puls.y() - y(); puls.p.setVelocity(cx/force, cy/force, 0); puls.dampVelocity(); } } void dampVelocity() { if ( abs(vx()) > 10 ) p.setVelocity(vx()/2, vy(), 0); if ( abs(vy()) > 10 ) p.setVelocity(vx(), vy()/2, 0); } float distFrom(Pulser puls) { return dist(puls.x(), puls.y(), x(), y()); } float distFrom(Player pl) { return dist(pl.x(), pl.y(), x(), y()); } float x() { return p.position().x(); } float y() { return p.position().y(); } float vx() { return p.velocity().x(); } float vy() { return p.velocity().y(); } void kill() { p.kill(); } }