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

📄 ssmtower.java

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

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


	public SSMtower(surface Surface, int xPos, int yPos, int distanceToGround, int distanceToCentre, vector direction2D, vector bodyDirection, int x_shift, int y_shift){
		x = xPos;
		y = yPos;
		width = 12; length = 22; height = 5;
		this.distanceToGround = distanceToGround;
		this.distanceToCentre = distanceToCentre;
		this.direction2D = direction2D;
		this.Surface = Surface;
		this.x_shift = x_shift;
		this.y_shift = y_shift;
		direction2D = direction2D.unit();
		points = new vector[8];
		this.bodyDirection = bodyDirection;
		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(x, y, 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(bodyDirection.scale(-distanceToCentre)).add(normal.scale(-distanceToGround));
		addPoints();
	}

	public void addPoints(){
		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, 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)).subtract(new vector(x_shift, y_shift));
	}

	public void paintSurface(){
		vector[] no1 = new vector[]{points[0], points[1], points[2], points[3]};
		paste NO1 = new paste(no1, findCentre(no1), new Color(215,199, 0));
		vector[] no2 = new vector[]{points[4], points[5], points[6], points[7]};
		paste NO2 = new paste(no2, findCentre(no2), new Color(215,199, 0));
		vector[] no3 = new vector[]{points[0], points[1], points[5], points[4]};
		paste NO3 = new paste(no3, findCentre(no3), new Color(225, 225, 225), "ssmtowerfront");
		vector[] no4 = new vector[]{points[1], points[2], points[6], points[5]};
		paste NO4 = new paste(no4, findCentre(no4), new Color(215,199, 0));
		vector[] no5 = new vector[]{points[0], points[4], points[7], points[3]};
		paste NO5 = new paste(no5, findCentre(no5), new Color(215,199, 0));
		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, NO2, NO3, NO4, NO5, NO6};
	}

	public void rotate(double angle, vector v){
		direction2D = direction2D.rotate2D(angle);
		direction2D = direction2D.unit();
		bodyDirection = v;
		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);
	}

	public void shift(int x_shift, int y_shift){
		this.x_shift = x_shift;
		this.y_shift = y_shift;
		addPoints();
	}


}

⌨️ 快捷键说明

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