class Deathskull { private float hitPoints, eyeX, eyeY; private color c; private boolean mOpen; private Particle p; private Pulser target; Deathskull() { p = phys.makeParticle(1, random(width), random(height), 0); target = null; hitPoints = 100; eyeX = eyeY = 0; c = color(44, 255, 193); mOpen = false; } void target(Pulser puls) { if ( puls == target || puls.targeted || puls.caught ) return; if ( target == null ) { target = puls; puls.targeted = true; } else if ( distFrom(puls) < distFrom(target) ) { target.targeted = false; target = puls; puls.targeted = true; } } void chase() { if ( target != null ) { if ( target.isDead() || target.isAttached() || target.isMoving() ) { target.targeted = false; target = null; } } if ( target != null ) { float d = distFrom(target); setVelocity(2*(target.x() - x())/d, 2*(target.y() - y())/d); if ( distFrom(target) < target.getRadius() + 30 ) { target.points = -50; score -= 50; target.kill(); target = null; } } } void damage(float amt) { if ( amt > 0 ) { hitPoints -= amt; println("Skull took " + amt + " points of damage."); } if ( hitPoints < 0 ) p.kill(); } void setVelocity(float x, float y) { p.setVelocity(x, y, 0); } float distFrom(Pulser puls) { return dist(puls.x(), puls.y(), x(), y()); } void kill() { p.kill(); } // state boolean isOffScreen() { if ( x() < -30 ) return true; if ( x() > width + 30 ) return true; if ( y() < -30 ) return true; if ( y() > height + 30 ) return true; return false; } boolean isDead() { return p.isDead(); } 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() { if ( target != null && screenStats ) { stroke(128); line(x(), y(), target.x(), target.y()); } float glow = glowIntensity; noFill(); pushMatrix(); translate(x(), y()); stroke(c); face(); eyes(); if ( drawGlow ) { pushMatrix(); for (int i = 1; i < 7; i++) { stroke(red(c), green(c), blue(c), glow/i); scale(0.98f); face(); eyes(); } popMatrix(); pushMatrix(); for (int i = 1; i < 7; i++) { stroke(red(c), green(c), blue(c), glow/i); scale(1.02f); face(); eyes(); } popMatrix(); } popMatrix(); } private void eyes() { if ( hitPoints > 60 ) { //left eye translate(-12, 0); diamond(7.5); //right eye translate(24, 0); diamond(7.5); translate(-12, 0); if ( target != null ) { float x = x(); float y = y(); float mx = target.x(); float my = target.y(); float hypo = dist(x, y, mx, my); float high = dist(x, y, x, my); float wide = dist(x, my, mx, my); eyeX = ( mx > x ? 2*wide/hypo : -2*wide/hypo); eyeY = ( my > y ? 2*high/hypo : -2*high/hypo); } else { eyeX = 0; eyeY = 0; } fill(255, 0, 0); noStroke(); ellipse(-12 + eyeX, eyeY, 1, 1); ellipse(12 + eyeX, eyeY, 1, 1); noFill(); stroke(c); } 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); } } }