class BounceBall extends Ball { float FRICTION = 0.99; float SPRING = 0.001; BounceBall (int ix, int iy, float ivx, float ivy, float iradius) { // just use Ball's constructor, it's good enough super(ix, iy, ivx, ivy, iradius); } // this overwrites Ball's update function void update() { vx *= FRICTION; vy *= FRICTION; spring(width/2, height/2); // but we call it here anyways super.update(); limit(); } void spring(float targX, float targY) { vx += (targX-x) * SPRING; vy += (targY-y) * SPRING; } void limit() { if ((y > height - radius) || (y < radius)) { vy = -vy; y = constrain(y, radius, height-radius); } if ((x < radius) || (x > width - radius)) { vx = -vx; x = constrain(x, radius, width - radius); } } }