shot3d.java

来自「空战游戏,来自java2 编程第五版源码」· Java 代码 · 共 84 行

JAVA
84
字号
import java.applet.*;
import java.awt.*;

class Shot3D extends Object3D
{
	static final int SHOT_SPEED = 18;
	
	static double Object[] = {	0,		-10,	0,
								0,		10,		0};
	
	static int Lines[] = {	0,1};

	public Shot3D(double x, double y, double z, int xr, int yr, int zr)
	{
		Name = "Shot3D";

		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.LaserSfx.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++)
		{
			g.setColor(new Color(255,0,0));
			g.drawLine(Points[Lines[i*2]].x,Points[Lines[i*2]].y,Points[Lines[i*2+1]].x,Points[Lines[i*2+1]].y);
		}
	}

	public boolean Handler()
	{
		ZPos += SHOT_SPEED;

		if (ZPos >= 1000)
		{
			Ship3D.LaserCount--;
			return false;
		}

		return true;
	}
}

⌨️ 快捷键说明

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