class Chaser { float x, y; float heading; Boolean lit; Boolean left; float integrity; Boolean active; Chaser(float x, float y) { this.x = x; this.y = y; this.heading = random(TWO_PI); lit = false; integrity = 1; active = true; } void update() { // check angle difference float playerAngle = atan2(y - playerY, x - playerX); if (lightOn) { //float angleDifference = angle - playerHeading; float angleDifference = getAngleDifference(playerAngle, playerHeading); // illuminate if angle difference is small enough if (abs(angleDifference) < LIGHT_ANGLE / 2) { lit = true; integrity -= BURN_RATE; if (integrity <= 0) { active = false; } } else { lit = false; } } else { lit = false; } // move if not lit if (!lit) { // turn toward player playerAngle = (atan2(playerY - y, playerX - x) + TWO_PI) % TWO_PI; float angleDifference = getAngleDifference(playerAngle, heading); if (angleDifference < -CHASER_STEERING_TOLERANCE) { heading += CHASER_TURN_RATE; left = true; } else if (angleDifference > CHASER_STEERING_TOLERANCE) { heading -= CHASER_TURN_RATE; left = false; } else { left = false; } heading = (heading + TWO_PI) % TWO_PI; // move forward x += CHASER_SPEED * cos(heading); y += CHASER_SPEED * sin(heading); } } void draw() { int offsetX = 0; int offsetY = 0; float sizeModification = 1; if (lit) { stroke(255); fill(192 + random(64)); sizeModification = 1 + 1 - integrity; offsetX = (int) random(-2 * sizeModification, 2 * sizeModification); offsetY = (int) random(-2 * sizeModification, 2 * sizeModification); } else { stroke(0); fill(0); } ellipse(x + offsetX, y + offsetY, CHASER_SIZE * sizeModification, CHASER_SIZE * sizeModification); //if (left) { //fill(255, 192, 192); //ellipse(x, y, 8, 8); //} } }