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

📄 surface.java

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

public class surface{
	private vector[][] x_fixed;
	private vector[][] y_fixed;
	private double x_increasement;
	private double y_increasement;
	private int index;
	public vector shift;
	public int xBoundary, yBoundary;

	public surface(int index, int x_shift, int y_shift){
		x_increasement = 25;
	    y_increasement = 25;
	    x_fixed = new vector[50][50];
	    y_fixed = new vector[50][50];
	    this.index = index;
	    shift = new vector(x_shift,y_shift);
	    xBoundary = 300;
	    yBoundary = 300;
	    createPoint();

	}

	public void createPoint(){
	 	for(int i = 0, x = -630; i < x_fixed.length; i++, x+=x_increasement){
	 		for(int j = 0, y = -590; j < x_fixed[i].length; j++, y+=y_increasement)
				x_fixed[i][j] = createSurface(x, y);

		}

		for(int i = 0, y = -590; i < y_fixed.length; i++, y+=y_increasement){
	 		for(int j = 0, x = -630; j < y_fixed[i].length; j++, x+=x_increasement)
				y_fixed[i][j] = createSurface(x, y);
		}
	}

	public void draw(Graphics g){
		g.setColor(Color.gray);

		for(int i = 0; i < x_fixed.length; i++){
			for(int j = 0; j < x_fixed[i].length; j++){
				if(j > 0 && x_fixed[i][j-1]!= null && x_fixed[i][j]!= null)
					g.drawLine(x_fixed[i][j-1].subtract(shift).getX(), x_fixed[i][j-1].subtract(shift).getY(), x_fixed[i][j].subtract(shift).getX(), x_fixed[i][j].subtract(shift).getY());
			}
		}
		for(int i = 0; i < y_fixed.length; i++){
			for(int j = 0; j < y_fixed[i].length; j++){
				if(j > 0 && y_fixed[i][j-1]!= null && y_fixed[i][j]!= null)
					g.drawLine(y_fixed[i][j-1].subtract(shift).getX(), y_fixed[i][j-1].subtract(shift).getY(), y_fixed[i][j].subtract(shift).getX(), y_fixed[i][j].subtract(shift).getY());
			}
		}
	}

	public void upDate(int x_shift, int y_shift){
		vector temp = shift;
		shift = new vector(x_shift,y_shift);
		if((int)shift.a/100 != (int)temp.a/100 || (int)shift.b/100 != (int)temp.b/100)
			createPoint();
	}


	public vector createSurface(int x, int y){
		double a = x; double b = y;
		if(Math.abs(shift.a) >= xBoundary)
			a+= shift.a/Math.abs(shift.a)*xBoundary;
		else
			a+=(int)shift.a/25*25;;

		if(Math.abs(shift.b) >= yBoundary)
			b+= shift.b/Math.abs(shift.b)*yBoundary;
		else
			b+=(int)shift.b/25*25;
		if(index == 1)
			return new vector(a,b,0);
		if(index == 2)
			return new vector(a, b,Math.sin(Math.sqrt((double)a*a/1600 + (double)b*b/1600))*30);
		if(index == 3)
			return new vector(a, b, (double)a*a*b*b/100000000*Math.exp(-(double)a*a/10000 - (double)b*b/10000)*700);
		return null;
	}

	public double fx(double x, double y){
		if(index == 1)
			return 0;
		if(index == 2)
			return x/1600*(1/(Math.sqrt(x*x/1600 + y*y/1600)))*Math.cos(Math.sqrt(x*x/1600 + y*y/1600))*30;
		if(index == 3)
			return ((double)x*y*y*2/100000000*Math.exp(-(double)x*x/10000-(double)y*y/10000) + (double)x*x*y*y/100000000*x*(-2)/10000*Math.exp(-(double)x*x/10000-(double)y*y/10000))*700;
		return -1;
	}

	public double fy(double x, double y){
		if(index == 1)
			return 0;
		if(index == 2)
			return y/1600*(1/(Math.sqrt(x*x/1600 + y*y/1600)))*Math.cos(Math.sqrt(x*x/1600 + y*y/1600))*30;
		if(index == 3)
			return ((double)x*x*y*2/100000000*Math.exp(-(double)x*x/10000-(double)y*y/10000) + (double)x*x*y*y/100000000*y*(-2)/10000*Math.exp(-(double)x*x/10000-(double)y*y/10000))*700;
		return -1;
	}

	public double evaluate(double x, double y){
		if(index == 1)
			return 0;
		if(index == 2)
			return Math.sin(Math.sqrt(x*x/1600 + y*y/1600))*30;
		if(index == 3)
			return x*x*y*y/100000000*Math.exp(-x*x/10000 - y*y/10000)*700;
		return -1;
	}
}

⌨️ 快捷键说明

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