class Bumper { private float iw, ih, ow, oh, rotAng, bounciness; private float eyeSize, eyeX, eyeY; private Particle p; private Particle[] outer; private color c, g; private int bumpCount; Bumper(float x, float y, float rot) { c = playerColor; g = playerGlow; iw = 70; ih = 30; ow = 80; oh = 40; rotAng = rot; bounciness = 10; bumpCount = 0; eyeSize = ih*0.3f; eyeX = iw*0.5f; eyeY = ih*0.2f; outer = new Particle[12]; // make the center p = phys.makeParticle(1, x, y, 0); p.makeFixed(); // make the particles for the outer ring outer[0] = phys.makeParticle(1, x+ow*-0.965925826f, y+oh*-0.258819045f, 0); outer[1] = phys.makeParticle(1, x+ow*-0.707106781f, y+oh*-0.707106781f, 0); outer[2] = phys.makeParticle(1, x+ow*-0.258819045f, y+oh*-0.965925826f, 0); outer[3] = phys.makeParticle(1, x+ow*0.258819045f, y+oh*-0.965925826f, 0); outer[4] = phys.makeParticle(1, x+ow*0.707106781f, y+oh*-0.707106781f, 0); outer[5] = phys.makeParticle(1, x+ow*0.965925826f, y+oh*-0.258819045f, 0); outer[6] = phys.makeParticle(1, x+ow*0.965925826f, y+oh*0.258819045f, 0); outer[7] = phys.makeParticle(1, x+ow*0.707106781f, y+oh*0.707106781f, 0); outer[8] = phys.makeParticle(1, x+ow*0.258819045f, y+oh*0.965925826f, 0); outer[9] = phys.makeParticle(1, x+ow*-0.258819045f, y+oh*0.965925826f, 0); outer[10] = phys.makeParticle(1, x+ow*-0.707106781f, y+oh*0.707106781f, 0); outer[11] = phys.makeParticle(1, x+ow*-0.965925826f, y+oh*0.258819045f, 0); // rotate the outer ring for (int i = 0; i < outer.length; i++) { float d = dist(x(), y(), outer[i].position().x(), outer[i].position().y()); float theta = rot + angle(x-outer[i].position().x(), y-outer[i].position().y()); float mx = d * cos(theta); float my = d * sin(theta); outer[i].moveTo(x+mx, y+my, 0); } // make the springs connecting the outer points to the center for (int i = 0; i < outer.length; i++) { phys.makeSpring(p, outer[i], 1, 0.2, dist(x(), y(), outer[i].position().x(), outer[i].position().y())); } } void update() { if ( bumpCount > bumpMax ) p.kill(); } void interact(Pulser puls) { float d = dist(x(), y(), puls.x(), puls.y()); float bs = 40; if ( d < ow + puls.radius() ) { 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); } // unit vector pointing toward the pulser float vx = (puls.x() - x())/d; float vy = (puls.y() - y())/d; puls.setVelocity(bs*vx, bs*vy); if ( !puls.isAttached() ) { bumpCount++; 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 nme) { float d = dist(x(), y(), nme.x(), nme.y()); float bs = 40; if ( d < ow + nme.radius() ) { float vx = (nme.x() - x())/d; float vy = (nme.y() - y())/d; 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); } nme.addVelocity(bs*vx, bs*vy); } } void interact(Sucker nme) { float d = dist(x(), y(), nme.x(), nme.y()); float bs = 40; if ( d < ow + nme.radius() ) { float vx = (nme.x() - x())/d; float vy = (nme.y() - y())/d; 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); } nme.addVelocity(bs*vx, bs*vy); } } void interact(Blower nme) { float d = dist(x(), y(), nme.x(), nme.y()); float bs = 40; if ( d < ow + nme.radius() ) { float vx = (nme.x() - x())/d; float vy = (nme.y() - y())/d; 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); } nme.addVelocity(bs*vx, bs*vy); } } void interact(Player pl) { float d = dist(x(), y(), pl.x(), pl.y()); float bs = 40/pl.mass(); if ( d < ow + pl.radius() ) { float vx = (pl.x() - x())/d; float vy = (pl.y() - y())/d; 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*vx, bs*vy); } } void kill() { p.kill(); for (int i = 0; i < outer.length; i++) outer[i].kill(); } boolean isDead() { return p.isDead(); } float x() { return p.position().x(); } float y() { return p.position().y(); } float radius() { return ow; } 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() { float glow = glowIntensity; noFill(); pushMatrix(); translate(x(), y()); rotate(rotAng); if ( drawGlow ) { for (int i = 1; i < 7; i++) { stroke(red(g), green(g), blue(g), glow/i); dode(iw*(1-0.02*i), ih*(1-0.02*i)); } for (int i = 1; i < 7; i++) { stroke(red(g), green(g), blue(g), glow/i); dode(iw*(1+0.02*i), ih*(1+0.02*i)); } } stroke(c); dode(iw, ih); face(); popMatrix(); if ( drawGlow ) { stroke(g); pushMatrix(); for (int i = 1; i < 7; i++) { stroke(red(g), green(g), blue(g), glow/i); beginShape(); for (int j = 0; j < outer.length; j++) { float x = x() - outer[j].position().x(); float y = y() - outer[j].position().y(); vertex(x() + x*(1-0.02*i), y() + y*(1-0.02*i)); } endShape(CLOSE); } popMatrix(); pushMatrix(); for (int i = 1; i < 7; i++) { stroke(red(g), green(g), blue(g), glow/i); beginShape(); for (int j = 0; j < outer.length; j++) { float x = x() - outer[j].position().x(); float y = y() - outer[j].position().y(); vertex(x() + x*(1+0.02*i), y() + y*(1+0.02*i)); } endShape(CLOSE); } popMatrix(); } stroke(c); beginShape(); for (int i = 0; i < outer.length; i++) { vertex(outer[i].position().x(), outer[i].position().y()); } endShape(CLOSE); } private void face() { float glow = glowIntensity; if ( drawGlow ) { for (int i = 1; i < 10; i++) { stroke(red(g), green(g), blue(g), glow/i); diamond(eyeSize*(1-0.05*i), -eyeX, eyeY); diamond(eyeSize*(1-0.05*i), eyeX, eyeY); } for (int i = 1; i < 10; i++) { stroke(red(g), green(g), blue(g), glow/i); diamond(eyeSize*(1+0.05*i), -eyeX, eyeY); diamond(eyeSize*(1+0.05*i), eyeX, eyeY); } fill(red(g), green(g), blue(g), 100); noStroke(); rect(-eyeX-eyeSize/2, eyeY-eyeSize/2, eyeSize, eyeSize*1.2); rect(eyeX-eyeSize/2, eyeY-eyeSize/2, eyeSize, eyeSize*1.2); noFill(); } stroke(c); diamond(eyeSize, -eyeX, eyeY); line(-eyeX, eyeY-eyeSize, -eyeX, eyeY+eyeSize); diamond(eyeSize, eyeX, eyeY); line(eyeX, eyeY-eyeSize, eyeX, eyeY+eyeSize); mouth(); } private void mouth() { pushMatrix(); translate(0, eyeY+eyeSize); if ( drawGlow ) { float glow = glowIntensity; for (int i = 1; i < 7; i++) { float sc = 1-(0.03*i); stroke(red(g), green(g), blue(g), glow/i); beginShape(); vertex(sc*-0.25*iw, sc*-eyeSize); vertex(sc*0.25*iw, sc*-eyeSize); vertex(sc*0.16*iw, 0); vertex(0, sc*eyeSize/2); vertex(sc*-0.16*iw, 0); endShape(CLOSE); } for (int i = 1; i < 7; i++) { float sc = 1+(0.03*i); stroke(red(g), green(g), blue(g), glow/i); beginShape(); vertex(sc*-0.25*iw, sc*-eyeSize); vertex(sc*0.25*iw, sc*-eyeSize); vertex(sc*0.16*iw, 0); vertex(0, sc*eyeSize/2); vertex(sc*-0.16*iw, 0); endShape(CLOSE); } } stroke(c); beginShape(); vertex(-0.25*iw, -eyeSize); vertex(0.25*iw, -eyeSize); vertex(0.16*iw, 0); vertex(0, eyeSize/2); vertex(-0.16*iw, 0); endShape(CLOSE); popMatrix(); } }