public class Roid implements Cloneable { private float xv, yv; protected float x, y, r; private int noIterations; private final float startVelocity = 1.5; private final float splitForce = 1.5; // was 4.5 public Roid(int roidSize) { x = random(0, width-1-roidSize); y = random(0, height-1-roidSize); /* xv=random(-1,1); yv=random(-1,1);*/ xv=random(startVelocity*-1,startVelocity); yv=random(startVelocity*-1,startVelocity); r = roidSize/2; noIterations = 0; } public Object clone() { try { return super.clone(); } catch (CloneNotSupportedException e) { // This should never happen throw new InternalError(e.toString()); } } public void move(AsteroidHandler roidHandler) { // Bounce against walls! if(x+r>=width-1) { x=width-r-2; xv *= -1; //reverse x-velocity } if(x-r<=0) { x=2+r; xv *= -1; } if(y+r>=height-1) { y = height-r-2; yv *= -1; //reverse y-velocity } if(y-r<=0) { y=2+r; yv *= -1; } /* if((x+r>=width-1) || (x-r<=5)) { xv *= -1; } if((y+r>=height-1) || (y-r<=0)) { yv *= -1; } */ /* xv+=random(-.001,.001); yv+=random(-.001,.001); */ // calculate new position x += xv; y += yv; } public void render() { fill (100); rect(x, y, r*2, r*2); } public int getIteration() { return noIterations; } public float getRadius() { return r; } public float getXv() { return this.xv; } public float getYv() { return this.yv; } public void iterate() { r /= 2; noIterations++; } public void makeSpace() { x += r; y += r; } public void push(float a) { float dx = splitForce * cos(a); float dy = splitForce * sin(a); xv += dx; yv += dy; } }