class Bumper { private float ri, ro, bounciness; private Particle p; private Particle[] outer; private color c; Bumper() { c = color(255); ri = 30; ro = 40; bounciness = 10; outer = new Particle[7]; // make the center p = phys.makeParticle(1, random(45, width-45), random(45, height-45), 0); p.makeFixed(); // make the particles for the outer ring outer[0] = phys.makeParticle(1, x()+ro*-0.98f, y()+ro*-0.198997487f, 0); outer[1] = phys.makeParticle(1, x()+ro*-0.45f, y()+ro*-0.893028554f, 0); outer[2] = phys.makeParticle(1, x()+ro*0.45f, y()+ro*-0.893028554f, 0); outer[3] = phys.makeParticle(1, x()+ro*0.98f, y()+ro*-0.198997487f, 0); outer[4] = phys.makeParticle(1, x()+ro*0.8f, y()+ro*0.6f, 0); outer[5] = phys.makeParticle(1, x(), y()+ro, 0); outer[6] = phys.makeParticle(1, x()+ro*-0.8f, y()+ro*0.6f, 0); // make the springs connecting the inner and outer rings for (int i = 0; i < outer.length; i++) { phys.makeSpring(p, outer[i], 1, 0.2, ro); } phys.makeSpring(outer[0], outer[1], 1, 1, dOut(0, 1)); phys.makeSpring(outer[1], outer[2], 1, 1, dOut(1, 2)); phys.makeSpring(outer[2], outer[3], 1, 1, dOut(2, 3)); phys.makeSpring(outer[3], outer[4], 1, 1, dOut(3, 4)); phys.makeSpring(outer[4], outer[5], 1, 1, dOut(4, 5)); phys.makeSpring(outer[5], outer[6], 1, 1, dOut(5, 6)); phys.makeSpring(outer[6], outer[0], 1, 1, dOut(6, 0)); } void interact(Pulser puls) { float d = dist(x(), y(), puls.x(), puls.y()); float bs = 40; if ( d < ro + puls.radius() ) { float dx = puls.x() - x(); float dy = puls.y() - y(); for (int i = 0; i < outer.length; i++) { float ds = dist(x(), y(), outer[i].position().x(), outer[i].position().y()); outer[i].setVelocity( bounciness * ((x() - outer[i].position().x())/ds), bounciness * ((y() - outer[i].position().y())/ds), 0); } puls.setVelocity(bs*(dx/d), bs*(dy/d)); if ( !puls.isAttached() ) { switch( puls.type ) { case KICK: score.addScore(75, x(), y()); break; case SNARE: score.addScore(100, x(), y()); break; case HAT: score.addScore(125, x(), y()); break; } } } } void interact(Deathskull sk) { float d = dist(x(), y(), sk.x(), sk.y()); float bs = 40; if ( d < ro + sk.radius() ) { float dx = sk.x() - x(); float dy = sk.y() - y(); for (int i = 0; i < outer.length; i++) { float ds = dist(x(), y(), outer[i].position().x(), outer[i].position().y()); outer[i].setVelocity( bounciness * ((x() - outer[i].position().x())/ds), bounciness * ((y() - outer[i].position().y())/ds), 0); } sk.addVelocity(bs*(dx/d), bs*(dy/d)); } } void interact(Player pl) { float d = dist(x(), y(), pl.x(), pl.y()); float bs = 40/pl.mass(); if ( d < ro + pl.radius() ) { float dx = pl.x() - x(); float dy = pl.y() - y(); for (int i = 0; i < outer.length; i++) { float ds = dist(x(), y(), outer[i].position().x(), outer[i].position().y()); outer[i].setVelocity( bounciness * ((x() - outer[i].position().x())/ds), bounciness * ((y() - outer[i].position().y())/ds), 0); } pl.addVelocity(bs*(dx/d), bs*(dy/d)); } } float x() { return p.position().x(); } float y() { return p.position().y(); } float radius() { return ro; } float dOut(int i, int j) { return dist(outer[i].position().x(), outer[i].position().y(), outer[j].position().x(), outer[j].position().y()); } void render() { noFill(); stroke(c); sept(ri, x(), y()); beginShape(); for (int i = 0; i < outer.length; i++) { vertex(outer[i].position().x(), outer[i].position().y()); } endShape(CLOSE); } }