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

📄 explo3d.java

📁 空战游戏,来自java2 编程第五版源码
💻 JAVA
字号:
import java.applet.*;
import java.awt.*;

class Explo3D extends Object3D
{
	static final int XROT_SPEED = 0;
	static final int YROT_SPEED = 0;
	static final int ZROT_SPEED = 16;
	
	static final int EXPLO_SPEED = 4;

	static double Object[] = {	25,		-25,	0,
								-25,	25,		0,
								-25,	-25,	0,
								25,		25,		0};
	
	static int Lines[] = {	0,1,	2,3};

	int Counter;

	boolean ColFlag = true;
	
	public Explo3D(double x, double y, double z)
	{
		Name = "Explo3D";

		XPos = x;
		YPos = y;
		ZPos = z;

		XRot = 0;
		YRot = 0;
		ZRot = 0;
		
		VertNum = Object.length / 3;
		LineNum = Lines.length / 2;
	    
		Vertices = new Vector3D[VertNum];
		Points = new Point2D[VertNum];
		
		for (int i=0; i<VertNum; i++)
		{
			Points[i]   = new Point2D();
			Vertices[i] = new Vector3D();
			
			Vertices[i].x = Object[i*3+X];
			Vertices[i].y = Object[i*3+Y];
			Vertices[i].z = Object[i*3+Z];
		}

		Visible = true;

		Counter = 0;
		
		WebWar.ExploSfx.play();
	}
	
	public void Draw(Graphics g, Matrix3D CameraMatrix)
	{
		Matrix3D MyMatrix = new Matrix3D();
		
		MyMatrix.RotateZ(ZRot);
		MyMatrix.RotateX(XRot);
		MyMatrix.RotateY(YRot);
		MyMatrix.Scale(XScale,YScale,ZScale);
		MyMatrix.Shear(XShear,YShear);
		MyMatrix.Translate(XPos,YPos,ZPos);

		MyMatrix.Merge(CameraMatrix.GetMatrix());

		for (int i=0; i<VertNum; i++)
		{
			MyMatrix.Transform(Vertices[i]);
			Points[i] = Point2D.Projection(Vertices[i]);			
		}
		
		for (int i=0; i<LineNum; i++)
		{
			if (ColFlag)
				g.setColor(Color.yellow);
			else
				g.setColor(Color.red);
			g.drawLine(Points[Lines[i*2]].x,Points[Lines[i*2]].y,Points[Lines[i*2+1]].x,Points[Lines[i*2+1]].y);
		}
		
		ColFlag = !ColFlag;
	}

	public boolean Handler()
	{
		XRot += XROT_SPEED;
		if (XRot >= 360) XRot -= 360;
		YRot += YROT_SPEED;
		if (YRot >= 360) YRot -= 360;
		ZRot += ZROT_SPEED;
		if (ZRot >= 360) ZRot -= 360;

		ZPos -= EXPLO_SPEED;
		if (ZPos <= 100) return false;

		Counter += 1;
		if (Counter >= 50) return false;

		return true;
	}
}

⌨️ 快捷键说明

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