⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 explosion.java

📁 坦克小战网络版
💻 JAVA
字号:
import java.awt.*;

public class explosion{
	private vector gridient, Radius, position;
	private vector[] centre, outer;
	private double radiusCentre, radiusOuter, time;
	public Polygon Centre, Outer;

	public explosion(vector position, vector gridient){
		this.position = position;
		this.gridient = gridient;
		Radius = new vector(1,1);
		time = 0;
		radiusCentre = 3; radiusOuter = 3;
		centre = buildPattan(centre, radiusCentre);
		outer = buildPattan(outer, radiusOuter);
	}

	public void changeShape(T3D tank, T3D enemy){
		if(time < 5)
			radiusCentre+=1;
		if(time > 9)
			radiusCentre+=0.85;
		radiusOuter+=0.85;
		centre = buildPattan(centre, radiusCentre);
		outer = buildPattan(outer, radiusOuter);
		time++;
		Centre = new Polygon(getX(centre), getY(centre), centre.length);
		Outer = new Polygon(getX(outer), getY(outer), outer.length);
		checkIfHit(tank, enemy);
	}

	public void changeShape(){
		if(time < 5)
			radiusCentre+=1;
		if(time > 9)
			radiusCentre+=0.85;
		radiusOuter+=0.75;
		centre = buildPattan(centre, radiusCentre);
		outer = buildPattan(outer, radiusOuter);
		Centre = new Polygon(getX(centre), getY(centre), centre.length);
		Outer = new Polygon(getX(outer), getY(outer), outer.length);
		time++;
	}

	public vector[] buildPattan(vector[] v, double radius){
		v = new vector[35];
		for(int i = 0; i < v.length; i++){
			Radius = Radius.rotate2D(Math.PI/18).unit();
			vector direction = new vector(Radius.a, Radius.b, Radius.dot(gridient));
			v[i] = position.add(direction.unit().scale(radius));
		}
		return v;
	}

	public int[] getX(vector[] v){
		int[] x = new int[v.length];
		for(int i = 0; i < x.length; i++)
			x[i] = (int)v[i].getX();
		return x;
	}

	public int[] getY(vector[] v){
		int[] y = new int[v.length];
		for(int i = 0; i < y.length; i++)
			y[i] = (int)v[i].getY();
		return y;
	}

	public void draw(Graphics g){
		g.setColor(Color.red);
		g.fillPolygon(Outer);
		g.setColor(Color.yellow);
		if(time>5)
			g.setColor(Color.white);
		g.fillPolygon(Centre);
	}

	public boolean over(){
		return time >= 25;
	}

	public void checkIfHit(T3D P1, T3D P2){
		if(P1.tower.centre.subtract(position).length() <= 5+time)
			P1.damage(P2);
		if(P2.tower.centre.subtract(position).length() <= 5+time)
			P2.damage(P1);
	}

}

⌨️ 快捷键说明

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