import java.awt.*; public class square extends shape { public double angle, anglechange; //I also put a rotation on my square, angle is the angle it's drawn at in radians, and //anglechange is a small random number (from 0 to .2) that is added to it every animation frame and then reduced by 20% public square(int x, int y, int size, int xVel, int yVel, int gravX, int gravY) //constructer that accepts everything { super(x, y, size, xVel, yVel, gravX, gravY); angle=Math.random()*Math.PI/2; anglechange=Math.random()/5; } //constructor that sets everything but the ending points randomly public square(int gravX, int gravY) { super((int)(Math.random()*300), (int)(Math.random()*300), 55, (int)(Math.random()*100-50), (int)(Math.random()*100-50), gravX, gravY); angle=Math.random()*Math.PI/2; anglechange=Math.random()/5; } //overrides paint in shape public void paint(Graphics g) { int x[]=new int[4]; int y[]=new int[4]; x[0]=(int)(centerX-size*Math.cos(angle)); //it takes a little trigonometry to rotate a square y[0]=(int)(centerY-size*Math.sin(angle)); x[1]=(int)(centerX-size*Math.cos(Math.PI/2+angle)); y[1]=(int)(centerY-size*Math.sin(Math.PI/2+angle)); x[2]=(int)(centerX+size*Math.cos(angle)); y[2]=(int)(centerY+size*Math.sin(angle)); x[3]=(int)(centerX+size*Math.cos(Math.PI/2+angle)); y[3]=(int)(centerY+size*Math.sin(Math.PI/2+angle)); g.fillPolygon(x, y, 4); } //changeposition in shape overridden to adjust anglechange as well public void changeposition() { if (!stopped) { centerX+=(int)(Xvel/10); centerY+=(int)(Yvel/10); angle=angle+anglechange; if (angle>Math.PI/2) angle = angle-Math.PI/2; Xvel=Xvel*.9; Yvel=Yvel*.9; anglechange=anglechange*.8; if (anglechange<.03) anglechange=.025; if ((Math.abs(centerX-gravX)<=2) && (Math.abs(centerY-gravY)<=2)/* && Math.abs(Xvel)<1.5 && Math.abs(Yvel)<1.5*/ && anglechange<=.03 && (Math.abs(Math.PI/2-angle)<.1)) stopped=true; } else { centerX=gravX; centerY=gravY; angle=Math.PI/2; } //this is where I want it to settle if it's stopped. } }