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

📄 bullet3d.java

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

class Bullet3D extends Object3D
{
	static final int BULLET_SPEED = 10;
	
	static final int XROT_SPEED = 8;
	static final int YROT_SPEED = 8;
	static final int ZROT_SPEED = 8;
	
	static double Object[] = {	5,		-5,		0,
								-5,		5,		0,
								-5,		-5,		0,
								5,		5,		0};
	
	static int Lines[] = {	0,1,	2,3};

	boolean ColFlag = true;
	
	public Bullet3D(double x, double y, double z, int xr, int yr, int zr)
	{
		Name = "Bullet3D";

		XPos = x;
		YPos = y;
		ZPos = z;
		
		XRot = xr;
		YRot = yr;
		ZRot = zr;
		
		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;

		WebWar.BulletSfx.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.white);
			else
				g.setColor(Color.blue);
			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 -= BULLET_SPEED;
		if (ZPos <= 100)
			return false;

		if (WebWar.Player_Collision(this))
		{
			return false;
		}
		return true;
	}
}

⌨️ 快捷键说明

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