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

📄 tanktower.java

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

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


	public tankTower(surface Surface, int xPos, int yPos, int distanceToGround, int distanceToCentre, vector direction2D){
		x = xPos;
		y = yPos;
		width = 16; length = 22; height = 5;
		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();
		centre = centre.add(direction3D.scale(-distanceToCentre)).add(normal.scale(-distanceToGround));
		addPoints();
	}

	public void addPoints(){
		points[0] = createPoint(width, length - 4, height);
		points[1] = createPoint(-width, length - 4, height);
		points[2] = createPoint(-width, -length, height);
		points[3] = createPoint(width, -length, height);
		points[4] = createPoint(width, length, 0);
		points[5] = createPoint(-width, length, 0);
		points[6] = createPoint(-width, -length, 0);
		points[7] = createPoint(width, -length, 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);
		vector[] no3 = new vector[]{points[0], points[1], points[5], points[4]};
		paste NO3 = new paste(no3, findCentre(no3), Color.gray);
		vector[] no4 = new vector[]{points[1], points[5], points[6], points[2]};
		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),new Color(101, 131, 160));
		Paste = new paste[]{NO1, NO3, NO4, NO5, NO6};
	}

	public void rotate(double angle){
		direction2D = direction2D.rotate2D(angle);
		direction2D = direction2D.unit();
		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 + -