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

📄 tankbody.java

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

public class tankBody{
	public double x, y, z;
	public int width, length, height, distanceToGround, distanceToCentre;
	public vector centre, normal, gradient, direction2D, direction3D, direction3DCrossNor;
	public surface Surface;
	public vector[] points;
	public paste[] Paste;

	public tankBody(surface Surface, int xPos, int yPos, int distanceToGround, int distanceToCentre, vector direction2D){
		x = xPos;
		y = yPos;
		width = 20; length = 32; height = 7;
		this.distanceToGround = distanceToGround;
		this.distanceToCentre = distanceToCentre;
		this.direction2D = direction2D;
		this.Surface = Surface;
		direction2D = direction2D.unit();
		points = new vector[8];
		defindStatus();
	}

	public void defindStatus(){
		double fx = Surface.fx(x,y), fy = Surface.fy(x, y);
		z = Surface.evaluate(x,y);
		normal = new vector(fx, fy, -1);
		normal = normal.unit();
		gradient = new vector(fx, fy);
		centre = new vector(0, 0, z);
		direction3D = new vector(direction2D.get_x(), direction2D.get_y(), gradient.dot(direction2D));
		direction3D = direction3D.unit();
		direction3DCrossNor = direction3D.cross(normal);
		direction3DCrossNor = direction3DCrossNor.unit();
		addPoints();
	}

	public void addPoints(){
		centre = centre.add(normal.scale(-distanceToGround)).add(direction3D.scale(-distanceToCentre));
		points[0] = createPoint(width, length, height);
		points[1] = createPoint(-width, length, height);
		points[2] = createPoint(-width, -length, height);
		points[3] = createPoint(width, -length, height);
		points[4] = createPoint(width, length - 8, 0);
		points[5] = createPoint(-width, length - 8, 0);
		points[6] = createPoint(-width, -length + 4, 0);
		points[7] = createPoint(width, -length + 4, 0);
		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));
	}

	public void paintSurface(){
		vector[] no1 = new vector[]{points[0], points[1], points[2], points[3]};
		paste NO1 = new paste(no1, findCentre(no1), Color.blue, "tankBody");
		vector[] no3 = new vector[]{points[0], points[1], points[5], points[4]};
		paste NO3 = new paste(no3, findCentre(no3), new Color(91, 122, 188));
		vector[] no4 = new vector[]{points[1], points[2], points[6], points[5]};
		paste NO4 = new paste(no4, findCentre(no4), new Color(91, 142, 198));
		vector[] no5 = new vector[]{points[0], points[4], points[7], points[3]};
		paste NO5 = new paste(no5, findCentre(no5), new Color(91, 142, 198));
		vector[] no6 = new vector[]{points[2], points[3], points[7], points[6]};
		paste NO6 = new paste(no6, findCentre(no6), Color.gray);
		Paste = new paste[]{NO1,NO3, NO4, NO5, NO6};
	}

	public void rotate(double angle){
		direction2D = direction2D.rotate2D(angle);
		direction2D = direction2D.unit();
		defindStatus();
	}

	public void move(double distance){
		direction2D = direction2D.unit();
		x = x + direction2D.scale(distance).get_x();
		y = y + direction2D.scale(distance).get_y();
		defindStatus();

	}

	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);
	}
}

⌨️ 快捷键说明

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