import java.awt.*; import java.lang.*; import java.util.*; import GameEngine; import Location; public class Map { private int maxX = 1000; private int maxY = 1000; private Color nblue = new Color (0, 64, 255); private Color dblue = new Color (0, 0, 192); private Color lblue = new Color (0, 255, 255); private int powerUp[] = { -2000, -2030, -2070, -2150, -2400 }; private int powerUpX[] = new int[5]; private int powerUpY[] = new int[5]; private int powerUpV[] = new int[5]; private double powerUpA[] = new double[5]; private int powerUpC[] = new int[5]; private Location[] myLocs = { new Location (100, 100, 4.71), new Location (500, 100, 4.71), new Location (900, 100, 4.71), new Location (500, 100, 0), new Location (550, 550, 1.57), new Location (500, 900, 3.14), new Location (900, 100, 1.57), new Location (900, 500, 1.57), new Location (900, 900, 1.57) }; GameEngine comp; Map(GameEngine c) { comp = c; } public void paint(Graphics g, int x, int y) { g.setColor(dblue); g.drawLine(-10-x, -10-y, maxX+10-x, -10-y); g.drawLine(-10-x, -10-y, -10-x, maxY+10-y); g.drawLine(maxX+10-x, -10-y, maxX+10-x, maxY+10-y); g.drawLine(-10-x, maxY+10-y, maxX+10-x, maxY+10-y); g.setColor(nblue); g.fillRect(-9-x, -9-y, maxX+18, 9); g.fillRect(-9-x, -9-y, 9, maxY+18); g.fillRect(maxX+1-x, -9-y, 9, maxY+18); g.fillRect(-9-x, maxY+1-y, maxX+18, 9); g.fillRect(200-x, 200-y, 200, 2); g.fillRect(200-x, 200-y, 2, 200); g.fillRect(600-x, 200-y, 200, 2); g.fillRect(800-x, 200-y, 2, 200); g.fillRect(200-x, 800-y, 200, 2); g.fillRect(200-x, 600-y, 2, 200); g.fillRect(600-x, 800-y, 200, 2); g.fillRect(800-x, 600-y, 2, 200); g.fillRect(400-x, 500-y, 200, 2); g.fillRect(500-x, 400-y, 2, 200); g.setColor(lblue); g.drawLine(-x, -y, maxX-x, -y); g.drawLine(-x, -y, -x, maxY-y); g.drawLine(maxX-x, -y, maxX-x, maxY-y); g.drawLine(-x, maxY-y, maxX-x, maxY-y); for (int i = 0; i < 5; i++) { if (powerUp[i] == 1) { g.setColor(Color.blue); g.fillOval(powerUpX[i]-x-5, powerUpY[i]-y-5, 11, 11); g.setColor(Color.cyan); g.drawOval(powerUpX[i]-x-6, powerUpY[i]-y-6, 13, 13); } else if (powerUp[i] == 2) { g.setColor(Color.red); g.fillOval(powerUpX[i]-x-5, powerUpY[i]-y-5, 11, 11); g.setColor(Color.pink); g.drawOval(powerUpX[i]-x-6, powerUpY[i]-y-6, 13, 13); } } } public int checkPowerUp(int x, int y) { for (int i = 0; i < 5; i++) { if (powerUp[i] > 0 && x > (powerUpX[i] - 15) && x < (powerUpX[i] + 15) && y > (powerUpY[i] - 15) && y < (powerUpY[i] + 15)) { int r = powerUp[i]+10; removePowerUp(i); return r; } } return 0; } public int checkObject(int x, int y) { if (x < 15) return 1; if (y < 15) return -1; if (x > maxX - 15) return 1; if (y > maxY - 15) return -1; if (x > 185 && x < 415 && y > 185 && y < 215) return -1; if (x > 185 && x < 215 && y > 185 && y < 415) return 1; if (x > 585 && x < 815 && y > 185 && y < 215) return -1; if (x > 785 && x < 815 && y > 185 && y < 415) return 1; if (x > 185 && x < 415 && y > 785 && y < 815) return -1; if (x > 185 && x < 215 && y > 585 && y < 815) return 1; if (x > 585 && x < 815 && y > 785 && y < 815) return -1; if (x > 785 && x < 815 && y > 585 && y < 815) return 1; if (x > 385 && x < 615 && y > 485 && y < 515) return -1; if (x > 485 && x < 515 && y > 385 && y < 615) return 1; else return 0; } public void update() { for (int i = 0; i < 5; i++) { if (powerUp[i] > 0) { powerUpX[i] += Math.round((float) (powerUpV[i]*Math.cos(powerUpA[i]))); powerUpY[i] += Math.round((float) (powerUpV[i]*Math.sin(powerUpA[i]))); int j = checkObject(powerUpX[i], powerUpY[i]); if (j != 0) changeAngle(i, j); else powerUpC[i] = j; } else if (powerUp[i]++ == 0) { genPowerUp(i); } } } public Location spawnNew() { return myLocs[((int) (Math.random()*1000))%myLocs.length]; } public void removePowerUp(int i) { powerUp[i] = -1800; } public void putPowerUp(int i, int type, int x, int y, double angle, int vel) { powerUp[i] = type; powerUpX[i] = x; powerUpY[i] = y; powerUpA[i] = angle; powerUpV[i] = vel; } private void genPowerUp(int i) { Location l = spawnNew(); powerUpX[i] = l.y; powerUpY[i] = l.x; powerUpV[i] = ((int) Math.random()*24)+4; powerUpA[i] = (Math.random()*1000)/160; if (i < powerUp.length -1) powerUp[i] = 1; else { powerUp[i] = 2; powerUpV[i] += 3; } comp.comp.net.sendPowerUp(i, powerUp[i], powerUpX[i], powerUpY[i], powerUpA[i], powerUpV[i]); } private void changeAngle(int i, int j) { if (powerUpC[i] != j) { double x = (powerUpV[i]*Math.cos(powerUpA[i])); double y = (powerUpV[i]*Math.sin(powerUpA[i])); if (j == 1) powerUpA[i] = Math.atan2(y, -x); else powerUpA[i] = Math.atan2(-y, x); powerUpC[i] = j; } } }