/Users/petercappello/NetBeansProjects/56-2014/56-2014-4-AdaptableZapem/src/StarCritter.java |
import java.awt.Graphics;
import static java.lang.Math.PI;
import static java.lang.Math.cos;
import static java.lang.Math.sin;
@author
class StarCritter extends Critter
{
private static final int RADIUS = EDGE_LENGTH / 2;
private static int[] TRIANGLE_X =
{
(int) ( RADIUS * cos( PI / 2.0 ) ),
(int) ( RADIUS * cos( 7.0 * PI / 6.0 ) ),
(int) ( RADIUS * cos( 11.0 * PI / 6.0 ) )
};
private static final int[] TRIANGLE_Y =
{
(int) ( RADIUS * sin( PI / 2.0 ) ),
(int) ( RADIUS * sin( 7.0 * PI / 6.0 ) ),
(int) ( RADIUS * sin( 11.0 * PI / 6.0 ) )
};
private static final int[] TRIANGLE2_Y =
{
(int) ( -RADIUS * sin( PI / 2.0 ) ),
(int) ( -RADIUS * sin( 7.0 * PI / 6.0 ) ),
(int) ( -RADIUS * sin( 11.0 * PI / 6.0 ) )
};
private int[] xArray;
private int[] yArray;
private int[] zArray;
@Override
public void move()
{
super.move();
xArray = new int[] { x, x, x };
yArray = new int[] { y, y, y };
zArray = new int[] { y, y, y };
for ( int i = 0; i < TRIANGLE_X.length; i++ )
{
xArray[ i ] += TRIANGLE_X[ i ] + EDGE_LENGTH / 2;
yArray[ i ] += TRIANGLE_Y[ i ] + EDGE_LENGTH / 2;
zArray[ i ] += TRIANGLE2_Y[ i ] + EDGE_LENGTH / 2;
}
}
@Override
public void draw( Graphics graphics )
{
graphics.setColor( color );
graphics.fillPolygon( xArray, yArray, TRIANGLE_X.length );
graphics.fillPolygon( xArray, zArray, TRIANGLE_X.length );
}
}