public class Missile { private float x, y, xv, yv, a, adir; boolean setForDestruction = false; // sets to true once, and only once in a missiles life time. private final float accelRate = 0.25; public Missile(float initx, float inity, float initxv, float inityv, float dir) { x = initx; y = inity; xv = initxv; yv = inityv; adir = dir; a = 0.1; } // Returns false if outside of visible screen public boolean move() { a += accelRate; float dx = a * cos(adir); float dy = a * sin(adir); xv += dx; yv += dy; x += xv; y += yv; if((x>=width-1) || (x<=0) || (y>=height-1) || (y<=0)) { return false; } else return true; } public void render() { stroke(255); fill(255); ellipse(x, y, 2, 2); } // Did the missile hit a roid? public Roid checkHit(){ Roid retRoid = null; // check current point AND past trajectory path float step = 0.5; float cx = this.x - xv; float cy = this.y - yv; boolean checkFinished = false; Roid hitRoid = null; while(!checkFinished && hitRoid==null) { hitRoid = roidHandler.whichRoid( cx, cy, 7 ); // radius was 2, then 10 if(cx <= x) cx+=step; if(cy <= y) cy+=step; if(cx > x && cy > y) checkFinished = true; } if(hitRoid != null) { // Split target roid roidHandler.splitRoid(hitRoid, this.getAngle()); retRoid = hitRoid; } return hitRoid; } public float getAngle() { return adir; } }