class Deathskull { private float hitPoints, currHP, eyeX, eyeY, sc; private color c, g; private boolean mOpen; private Particle p; private Pulser target; Deathskull() { init(1); } Deathskull(float _sc) { init(_sc); } private void init(float _sc) { p = phys.makeParticle(1, random(width), random(height), 0); target = null; sc = _sc; hitPoints = currHP = 2000*sc; eyeX = eyeY = 0; c = skullColor; g = skullGlow; mOpen = false; } void update() { if ( target != null ) { if ( target.isDying() || target.isDead() || target.isAttached() || target.isMoving() ) { target.targeted = false; target = null; } } if ( target != null ) { float d = dist(target.x(), target.y(), x(), y()); p.addVelocity(0.5f*(target.x() - x())/d, 0.5f*(target.y() - y())/d, 0); if ( d < target.radius() + radius() ) { switch( target.type ) { case KICK: target.score(-75); break; case SNARE: target.score(-100); break; case HAT: target.score(-125); break; } target.kill(); target = null; } } } void target(Pulser puls) { if ( target == null ) { target = puls; puls.targeted = true; } else if ( dist(puls.x(), puls.y(), x(), y()) < dist(target.x(), target.y(), x(), y()) ) { target.targeted = false; target = puls; puls.targeted = true; } } void damage(float amt) { if ( amt > 0 ) { currHP -= amt; println("Skull took " + amt + " points of damage."); } if ( currHP < 0 ) kill(); } void setVelocity(float x, float y) { p.setVelocity(x, y, 0); } void addVelocity(float x, float y) { p.addVelocity(x, y, 0); } void moveTo(float x, float y) { p.moveTo(x, y, 0); } void kill() { if ( target != null ) target.targeted = false; p.kill(); } // state boolean awareOf(Pulser puls) { return !(puls.targeted || puls.isCaught() || puls.isAttached() || puls.isMoving() || puls.isDying() || puls.isDead() || p.isDead() ); } boolean isOffScreen() { if ( x() < -radius() ) return true; if ( x() > width + radius() ) return true; if ( y() < -radius() ) return true; if ( y() > height + radius() ) return true; return false; } boolean isDead() { return p.isDead(); } float radius() { return 30*sc; } float x() { return p.position().x(); } float y() { return p.position().y(); } float vx() { return p.velocity().x(); } float vy() { return p.velocity().y(); } // rendering void render() { float glow = glowIntensity; noFill(); pushMatrix(); translate(x(), y()); scale(sc); if ( drawGlow ) { pushMatrix(); for (int i = 1; i < 12; i++) { stroke(red(g), green(g), blue(g), glow/i); scale(0.98f); face(); eyes(); } popMatrix(); pushMatrix(); for (int i = 1; i < 12; i++) { stroke(red(g), green(g), blue(g), glow/i); scale(1.02f); face(); eyes(); } popMatrix(); } stroke(c); face(); eyes(); popMatrix(); if ( target != null ) { stroke(red(c), green(c), blue(c), 128); line(x() - 12 + eyeX, y() + eyeY, target.eyeXL(), target.eyeYL()); line(x() + 12 + eyeX, y() + eyeY, target.eyeXR(), target.eyeYR()); } } private void eyes() { if ( currHP/hitPoints > 0.5f ) { if ( target != null ) { float d = dist(x(), y(), target.x(), target.y()); eyeX = 2*(target.x() - x())/d; eyeY = 2*(target.y() - y())/d; } else { eyeX = 0; eyeY = 0; } //left eye translate(-12, 0); diamond(7.5); //right eye translate(24, 0); diamond(7.5); translate(-12, 0); // eyeballs noStroke(); fill(255, 0, 0); ellipse(-12 + eyeX, eyeY, 0.5f, 0.5f); ellipse(12 + eyeX, eyeY, 0.5f, 0.5f); noFill(); } else { //left eye translate(-12, 0); cross(4); //right eye translate(24, 0); cross(4); translate(-12, 0); } } private void face() { // outline pent(30); //nose triangle(-4, 9, 0, 2, 4, 9); line(0, 1, 0, 10); //left cheek line(-25, -1, -15, 9); line(-15, 9, -14, 20); //right cheek line(25, -1, 15, 9); line(15, 9, 14, 20); mouth(); } private void mouth() { if ( frameCount%15 == 0 ) mOpen = !mOpen; if ( mOpen ) { //upper lip line(-15, 13, 15, 13); line(-8, 11, -8, 13); line(0, 11, 0, 13); line(8, 11, 8, 13); //lower lip line(-15, 19, 15, 19); line(-8, 19, -8, 21); line(0, 19, 0, 21); line(8, 19, 8, 21); } else { //closed line(-14, 15, 14, 15); line(-8, 13, -8, 17); line(0, 13, 0, 17); line(8, 13, 8, 17); } } }