/* Bombs kill hearts and chompers. */ class Bomb extends Bouncy { static final float bombMass = 1, bombRadius = 10, explosionRadius = 25; static final int explosionDuration = 25; boolean exploding = false; int explodeTime; Bomb(int x, int y) { super(x, y, bombMass, bombRadius); } void doPhysics0() { if (exploding) { if (t >= explodeTime + explosionDuration) remove1(); } else super.doPhysics0(); } void draw() { if (exploding) { stroke(255, 255 - 255 * (t - explodeTime) / explosionDuration, 0); fill(255, 255 - 255 * (t - explodeTime) / explosionDuration, 0); ellipse(x, y, explosionRadius * 2, explosionRadius * 2); } else { bombAnimation.displayCentered(x+2, y-8, t, true, 4, false); } } void explode() { if (!exploding) { playSound(explosion); exploding = true; explodeTime = t; remove0(); } } void collideWith(Bouncy b) { if (b instanceof Bomb) genericCollision(b); else if (b instanceof Heart) { if (!exploding) { explode(); } ((Heart)b).die(); } } void addToLevel() { theString.stringables.add(this); theEntities.add(this); theBouncies.add(this); theBombs.add(this); } void remove0() { theString.stringables.remove(this); theBouncies.remove(this); theBombs.remove(this); } void remove1() { theEntities.remove(this); } }