// CopyCat Battle Tank // // Author Matthew Caryl // Created 5.4.97 package CopyCat; import java.awt.*; import ADT.*; import java.net.*; import java.lang.*; import java.applet.*; import java.io.*; public final class Tank extends Entity { // // Private interface // private static Vector[] vs; private static int[] ts; private static Color[] cs; static { vs = new Vector[14]; vs[ 0] = new Vector( -90f, -200f, 40f); vs[ 1] = new Vector( 90f, -200f, 40f); vs[ 2] = new Vector( 100f, 200f, 50f); vs[ 3] = new Vector(-100f, 200f, 50f); vs[ 4] = new Vector(-100f, -200f, -50f); vs[ 5] = new Vector( 100f, -200f, -50f); vs[ 6] = new Vector( 100f, 200f, -50f); vs[ 7] = new Vector(-100f, 200f, -50f); vs[ 8] = new Vector( 0f, -180f, 70f); vs[ 9] = new Vector( 20f, -180f, 60f); vs[10] = new Vector( -20f, -180f, 60f); vs[11] = new Vector( 0f, 90f, 70f); vs[12] = new Vector( 20f, 90f, 60f); vs[13] = new Vector( -20f, 90f, 60f); ts = new int[20 * 3]; ts[ 0] = 0; ts[ 1] = 1; ts[ 2] = 2; ts[ 3] = 2; ts[ 4] = 3; ts[ 5] = 0; ts[ 6] = 4; ts[ 7] = 7; ts[ 8] = 6; ts[ 9] = 6; ts[10] = 5; ts[11] = 4; ts[12] = 1; ts[13] = 5; ts[14] = 6; ts[15] = 6; ts[16] = 2; ts[17] = 1; ts[18] = 0; ts[19] = 3; ts[20] = 7; ts[21] = 7; ts[22] = 4; ts[23] = 0; ts[24] = 3; ts[25] = 2; ts[26] = 6; ts[27] = 6; ts[28] = 7; ts[29] = 3; ts[30] = 0; ts[31] = 4; ts[32] = 5; ts[33] = 5; ts[34] = 1; ts[35] = 0; ts[36] = 8; ts[37] = 9; ts[38] = 10; ts[39] = 11; ts[40] = 12; ts[41] = 13; ts[42] = 8; ts[43] = 10; ts[44] = 13; ts[45] = 13; ts[46] = 11; ts[47] = 8; ts[48] = 9; ts[49] = 8; ts[50] = 11; ts[51] = 11; ts[52] = 12; ts[53] = 9; ts[54] = 9; ts[55] = 12; ts[56] = 13; ts[57] = 13; ts[58] = 10; ts[59] = 9; cs = new Color[20]; cs[0] = new Color(0x308000); for (int i = 1; i < 12; i++) cs[i] = cs[i - 1]; cs[12] = new Color(255, 0, 0); for (int i = 13; i < 20; i++) cs[i] = cs[i - 1]; } private float x, y; private float heading; private Controller controls; private void turn(float angle) { heading += angle; if (heading < -Math.PI) heading += 2 * Math.PI; else if (heading > Math.PI) heading -= 2 * Math.PI; turnTo(0f, 0f, heading); } private void move(float distance) { x -= (float) Math.sin(heading) * distance; y -= (float) Math.cos(heading) * distance; moveTo(x, y, 0f); } // // Public interface // public static final int FORWARD = 0; public static final int BACKWARD = 1; public static final int CLOCKWISE = 2; public static final int ANTICLOCKWISE = 3; public Tank(Controller C) { super(vs, ts, cs, null); controls = C; } public void tick() { float distance = 0f; if (controls.transfer(FORWARD)) distance += 10f; if (controls.transfer(BACKWARD)) distance -= 10f; if (distance != 0f) move(distance); float angle = 0f; if (controls.transfer(CLOCKWISE)) angle += 0.03f; if (controls.transfer(ANTICLOCKWISE)) angle -= 0.03f; if (angle != 0f) turn(angle); } public float x() { return x; } public float y() { return y; } public float heading() { return heading; } }