class Heart extends Bouncy { final static int trailLength = 40; final static float heartMass = 1; final static float trailRadius = 13, heartCollisionRadius = 13; final static int framesPerTrailPoint = 2; int deathTime; int heartNumber; boolean showNumber; float trailX[] = new float[trailLength], trailY[] = new float[trailLength]; boolean trailOn[] = new boolean[trailLength]; int counter; Heart(float x, float y) { super(x, y, heartMass, heartCollisionRadius); for (int i = 0; i < trailLength; ++ i) { trailOn[i] = false; } } Heart(float x, float y, int num) { this(x,y); heartNumber = num; showNumber = true; } void doPhysics1() { super.doPhysics1(); int trailT = t / framesPerTrailPoint; if (dead) { trailOn[trailT % trailLength] = false; if (trailT - deathTime > trailLength) { remove1(); } } else { // Leave a trail. trailX[trailT % trailLength] = x; trailY[trailT % trailLength] = y; trailOn[trailT % trailLength] = true; } } void draw() { if (dead) return; image(heartImage, x - heartImage.width*imageScale/2, y - heartImage.height*imageScale/2, heartImage.width*imageScale, heartImage.height*imageScale); if (showNumber) fontBlack.DrawCentered(x+1, y-5, "" + heartNumber, 2); } void die() { if (dead) return; dead = true; deathTime = t; remove0(); } void collideWith(Bouncy b) { if (b instanceof Heart) genericCollision(b); else b.collideWith(this); } void addToLevel() { ++ nLiveHearts; theHearts.add(this); theString.stringables.add(this); theEntities.add(this); theBouncies.add(this); } void remove0() { -- nLiveHearts; theString.stringables.remove(this); theBouncies.remove(this); } void remove1() { theEntities.remove(this); theHearts.remove(this); } }