class Judge { public float x, y; float dx, dy; float rotation; int health; int shootCount; float targetAngle; int changeAngleCount; float targX; float targY; Animation anim; AnimFrames animFrames; Judge(float X, float Y, float scl, AnimFrames frames) { x = X; y = Y; dx = 0; dy = 0; rotation = 0; animFrames = frames; anim = new Animation(x, y, scl, frames); anim.setIdle(false); health = 3; shootCount = (int)random(50, 200); changeAngleCount = 0; } void hurt() { health--; rotation += 0.5; player.heal(); } boolean update() { if(0 >= shootCount) { float xdiff = player.x - x; float ydiff = player.y - y; float scaleFactor = 0.25*mag(xdiff, ydiff); float beamAngle = atan2(ydiff, xdiff) + random(-0.1, 0.1); beams.add(new Beam(x, y, xdiff/scaleFactor + dx, ydiff/scaleFactor + dy, beamAngle, false)); shootCount = (int)random(100, 150); } else shootCount--; changeAngleCount--; if(changeAngleCount <= 0) { changeAngleCount = (int)random(100, 200); targetAngle = random(0.4*PI, 0.8*PI); } targX = player.x + (400)*cos(targetAngle); targY = player.y - (400)*sin(targetAngle); x += dx; y += dy; dx += (targX - x)*0.03; dy += (targY - y)*0.03; dx *= 0.7; dy *= 0.7; render(); return (health <= 0); } void render() { pushMatrix(); translate(x-cam, y); rotate(rotation); translate(cam-x, -y); anim.update(x-cam-anim.w/2, y-anim.h/2); //image(spr, x-cam-mWidth/2, y-mHeight/2, mWidth, mHeight); //noFill(); //rect(x-cam-mWidth/2, y-mHeight/2, mWidth, mHeight); popMatrix(); } }