map.java

来自「坦克大战游戏源代码」· Java 代码 · 共 45 行

JAVA
45 行
字号
import java.awt.*;

public class map{
	public enemy[] Enemy;


	public map(enemy[] Enemy){
		this.Enemy = Enemy;
	}

	public void update(enemy[] Enemy){
		this.Enemy = Enemy;
	}

	public void draw(Graphics g){
		g.setColor(Color.orange);
		g.drawRect(1,1, 150,150);
		g.drawRect(2,2, 148,148);

		for(int i = 0; i < Enemy.length; i++){
			if(Enemy[i] != null){
				if(Enemy[i].distanceFromTarget() == 0){
					g.setColor(Color.blue);
					vector direction = new vector(Enemy[i].getDirection3D().a, -Enemy[i].getDirection3D().b);
					vector left = direction.rotate2D(-Math.PI/6).unit();
					vector right = direction.rotate2D(Math.PI/6).unit();
					vector p1 = direction.unit().scale(4).add(new vector(75,75));
					vector p2 = direction.unit().scale(-4).add(new vector(75,75));
					g.drawLine((int)p1.a, (int)p1.b, (int)p2.a, (int)p2.b);
					vector p3 = p1.add(left.scale(-3));
					vector p4 = p1.add(right.scale(-3));
					g.drawLine((int)p1.a, (int)p1.b, (int)p4.a, (int)p4.b);
					g.drawLine((int)p1.a, (int)p1.b, (int)p3.a, (int)p3.b);
				}
				else{
					g.setColor(Color.red);
					vector p = Enemy[i].miniMapPosition().add(new vector(75,75));
					if(!(p.a >= 148 || p.a <=2 || p.b >= 148 || p.b <=2))
						g.fillRect((int)(p.a - 1), (int)(p.b - 1), 3, 3);
				}
			}
		}
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?