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

📄 railtower.java

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

public class RAILtower{
	public double x, y, z;
	public int width, length, height, distanceToGround, distanceToCentre;
	public vector centre, normal, direction3D, direction3DCrossNor, bodyDirection, bodyNormal;
	public vector[] points;
	public paste[] Paste;
	public int x_shift, y_shift;

	public RAILtower(int xPos, int yPos, double zPos, int distanceToGround, int distanceToCentre, vector normal,  vector direction3D, int x_shift, int y_shift){
		x = xPos;
		y = yPos;
		z = zPos;
		width = 14; length = 24; height = 5;
		this.distanceToGround = distanceToGround;
		this.distanceToCentre = distanceToCentre;
		this.x_shift = x_shift;
		this.y_shift = y_shift;
		points = new vector[12];
		Paste = new paste[8];
		this.direction3D = direction3D.unit();
		this.normal = normal.unit();
		bodyNormal = normal;
		bodyDirection = direction3D;
		defindStatus();
	}

	public void defindStatus(){
		centre = new vector(x, y, z);
		direction3DCrossNor = normal.cross(direction3D).unit();
		centre = centre.add(bodyDirection.scale(-distanceToCentre)).add(bodyNormal.scale(-distanceToGround));
		addPoints();
	}

	public void addPoints(){
		points[0] = createPoint(width, length, 0);
		points[1] = createPoint(width - 6, length, height);
		points[2] = createPoint(-width + 6, length, height);
		points[3] = createPoint(-width, length, 0);
		points[4] = createPoint(-width + 6, length, -height);
		points[5] = createPoint(width - 6, length, -height);
		points[6] = createPoint(width, -length, 0);
		points[7] = createPoint(width - 6, -length, height);
		points[8] = createPoint(-width + 6, -length, height);
		points[9] = createPoint(-width, -length, 0);
		points[10] = createPoint(-width + 6, -length, -height);
		points[11] = createPoint(width - 6, -length, -height);
		paintSurface();

	}

	public vector createPoint(int w, int l, int h){
		return centre.add(direction3DCrossNor.scale(w/2)).add(direction3D.scale(l/2)).add(normal.scale(-h)).subtract(new vector(x_shift, y_shift));
	}

	public void paintSurface(){
		vector[] v = new vector[]{points[0], points[1], points[2], points[3], points[4], points[5]};
		Paste[0] = new paste(v, findCentre(new vector[]{points[1], points[2],points[4], points[5]}), new Color(36,68, 104));
		v = new vector[]{points[6], points[7], points[8], points[9], points[10], points[11]};
		Paste[1] = new paste(v, findCentre(new vector[]{points[7], points[8],points[10], points[11]}), Color.blue);
		v = new vector[]{points[1], points[2], points[8], points[7]};
		Paste[2] = new paste(v, findCentre(v), new Color(101,117,237));
		v = new vector[]{points[2], points[3], points[9], points[8]};
		Paste[3] = new paste(v, findCentre(v), new Color(89, 100, 236));
		v = new vector[]{points[3], points[4], points[10], points[9]};
		Paste[4] = new paste(v, findCentre(v), new Color(55, 68, 232));
		v = new vector[]{points[4], points[5], points[11], points[10]};
		Paste[5] = new paste(v, findCentre(v), Color.blue);
		v = new vector[]{points[5], points[0], points[6], points[11]};
		Paste[6] = new paste(v,findCentre(v), new Color(55, 68, 232));
		v = new vector[]{points[0], points[1], points[7], points[6]};
		Paste[7] = new paste(v,findCentre(v), new Color(89, 100, 236));
	}

	public vector findCentre(vector[] v){
		return v[0].add(v[1]).scale(0.5).add(v[2].add(v[3]).scale(0.5)).scale(0.5);
	}	public void shift(int x_shift, int y_shift){
		this.x_shift = x_shift;
		this.y_shift = y_shift;
		addPoints();
	}

	public void rotate(vector targetDirection, vector gradient){
		vector difference = targetDirection.subtract(direction3D);
		direction3D = direction3D.add(difference.unit().scale(0.05)).unit();
		adjust(gradient);
	}

	public void adjust(vector gradient){
		vector direction2D = new vector(direction3D.a, direction3D.b);
		vector v3D = new vector(direction3D.a, direction3D.b, gradient.dot(direction2D.unit())+0.000000000000000000001);
		direction3DCrossNor = v3D.cross(direction3D).unit();
		normal = direction3DCrossNor.cross(direction3D).unit();
		vector v = new vector(0,0,1);
		if(normal.dot(v) >= normal.scale(-1).dot(v))
			normal = normal.scale(-1);

		centre = new vector(x, y, z);
		centre = centre.add(bodyDirection.scale(-distanceToCentre)).add(bodyNormal.scale(-distanceToGround));
		addPoints();
	}

}

⌨️ 快捷键说明

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