📄 enemy3d.java
字号:
import java.applet.*;
import java.awt.*;
class Enemy3D extends Object3D
{
static final int SHIP_SPEED = 4;
static final int XROT_SPEED = 2;
static final int YROT_SPEED = 1;
static final int ZROT_SPEED = 2;
static double Object[] = { 0, -20, 0,
20, 0, 0,
0, 20, 0,
-20, 0, 0,
0, 0, -20,
0, 0, 20};
static int Lines[] = { 0,1, 1,2, 2,3, 3,0,
0,4, 1,4, 2,4, 3,4,
0,5, 1,5, 2,5, 3,5};
int XWinkel;
int YWinkel;
int XAdd;
int YAdd;
int XRadius = 240;
int YRadius = 200;
int ShootCounter;
public Enemy3D(int enemyflag, int xw, int yw, int xadd, int yadd, int shootflag)
{
Name = "Enemy3D";
ZPos = 1200;
XWinkel = xw;
YWinkel = yw;
XAdd = xadd;
YAdd = yadd;
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;
ShootCounter = 0;
}
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,255,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()
{
if (WebWar.Collision(this))
{
WebWar.GetNewObject(new Explo3D(XPos,YPos,ZPos));
WebWar.Score += 500;
return false;
}
else
{
XPos = (int)(XRadius * Matrix3D.Sin(XWinkel));
YPos = (int)(YRadius * Matrix3D.Cos(YWinkel));
XWinkel -= XAdd;
if (XWinkel < 0) XWinkel += 360;
if (XWinkel > 360) XWinkel -= 360;
YWinkel -= YAdd;
if (YWinkel < 0) YWinkel += 360;
if (YWinkel > 360) YWinkel -= 360;
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 -= 4;
if (ZPos <= 100) return false;
if (ShootCounter == 100)
{
if ((Ship3D.Player.XPos == XPos) && (Ship3D.Player.YPos == YPos))
{
ShootCounter = 0;
WebWar.GetNewObject(new Bullet3D(XPos,YPos,ZPos,XRot,YRot,ZRot));
}
}
else ShootCounter++;
return true;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -