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

📄 explosion.java

📁 坦克大战游戏源代码
💻 JAVA
字号:
import java.awt.*;

public class explosion{
	public vector gridient, Radius, position;
	public vector[] centre, outer;
	public double radiusCentre, radiusOuter, time, interval;
	public Polygon Centre, Outer;
	public String type;
	public int size;
	public int x_shift, y_shift;

	public explosion(vector position, vector gridient, int size, String type, int x_shift, int y_shift){
		this.position = position;
		this.gridient = gridient;
		this.interval = interval;
		this.type = type;
		this.size = size;
		this.x_shift = x_shift;
		this.y_shift = y_shift;
		Radius = new vector(1,1);
		time = 0;
		radiusCentre = 3; radiusOuter = 3;
		centre = buildPattan(centre, radiusCentre);
		outer = buildPattan(outer, radiusOuter);
	}

	public void changeShape(int x_shift, int y_shift){
		this.x_shift = x_shift;
		this.y_shift = y_shift;
		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);
	}


	public vector[] buildPattan(vector[] v, double radius){
		v = new vector[17];
		for(int i = 0; i < v.length; i++){
			Radius = Radius.rotate2D(Math.PI/9).unit();
			vector direction = new vector(Radius.a, Radius.b, Radius.dot(gridient));
			v[i] = position.add(direction.unit().scale(radius)).subtract(new vector(x_shift, y_shift));
		}
		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){
		vector shift = new vector(x_shift, y_shift);
		if(position.subtract(shift).length() <750){
			try{
			g.setColor(Color.red);
			if(type.equals("ground"))
				g.fillPolygon(Outer);
			g.setColor(Color.yellow);
			if(time>6)
				g.setColor(Color.white);
			g.fillPolygon(Centre);
			}catch(Exception e){}
		}
	}

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

}

⌨️ 快捷键说明

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