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

📄 zobject.java

📁 java 编写的小游戏--坦克大战
💻 JAVA
字号:
// Decompiled by DJ v2.9.9.60 Copyright 2000 Atanas Neshkov  Date: 2004-12-12 17:51:13
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   ZObject.java


public class ZObject
{

    void SetEnergy(int i)
    {
        fEnergy = i;
    }

    public void DoAction()
    {
    }

    public void SetRadius(int i)
    {
        fRadius = i;
    }

    public void SetType(int i)
    {
        fType = i;
    }

    public void SetAFace(ZPolygon zpolygon)
    {
        int i = zpolygon.fNumVertices;
        fPolygons = new ZPolygon[2];
        fPolygons[0] = new ZPolygon();
        fPolygons[1] = new ZPolygon();
        fPolygons[0].fVertices = new ZVertex[i];
        fPolygons[1].fVertices = new ZVertex[i];
        for(int j = 0; j < i; j++)
        {
            fPolygons[0].fVertices[j] = fVertices[j];
            fPolygons[1].fVertices[j] = fVertices[i - 1 - j];
        }

        fPolygons[0].fNumVertices = i;
        fPolygons[1].fNumVertices = i;
        fPolygons[0].fRed = zpolygon.fRed;
        fPolygons[0].fGreen = zpolygon.fGreen;
        fPolygons[0].fBlue = zpolygon.fBlue;
        fPolygons[0].GetLocalNormal();
        fPolygons[0].GetNormalLength();
        fPolygons[0].fObject = this;
        fPolygons[1].fRed = zpolygon.fRed;
        fPolygons[1].fGreen = zpolygon.fGreen;
        fPolygons[1].fBlue = zpolygon.fBlue;
        fPolygons[1].GetLocalNormal();
        fPolygons[1].GetNormalLength();
        fPolygons[1].fObject = this;
        fNumPolygons = 2;
        fRadius = 10;
    }

    boolean CheckCollision(ZObject zobject)
    {
        if(fStatus != 1 || zobject.fStatus != 1)
            return false;
        int i = fX - fRadius;
        int j = fX + fRadius;
        int k = fZ - fRadius;
        int l = fZ + fRadius;
        int i1 = zobject.fX - fRadius;
        int j1 = zobject.fX + fRadius;
        int k1 = zobject.fZ - fRadius;
        int l1 = zobject.fZ + fRadius;
        if(j < i1)
            return false;
        if(i > j1)
            return false;
        if(l < k1)
            return false;
        return k <= l1;
    }

    public void HandleCollisionWithBullet(ZObject zobject)
    {
        zobject.fStatus = 0;
        zobject.fMaxLifeTime = 0;
        ExplodeIntoDebris();
        if(fExplodable)
        {
            fStatus = 0;
            fShouldBeCheckForCollision = false;
        }
        fStatusTimer = 0;
        fAction = 6;
    }

    public void SetSpeed(int i)
    {
        fSpeed = fOriginalSpeed = i;
    }

    public void SetRotationSpeed(int i, int j, int k)
    {
        fXRotationSpeed = i;
        fYRotationSpeed = j;
        fZRotationSpeed = k;
    }

    boolean CheckCollision2(ZObject zobject)
    {
        int i = fX - zobject.fX;
        int j = fZ - zobject.fZ;
        if(i < 0)
            i = -i;
        if(j < 0)
            j = -j;
        int k;
        if(i < j)
            k = i;
        else
            k = j;
        int l = (i + j) - k;
        if(l < 0)
            l = -l;
        l >>= 1;
        return l < zobject.fRadius;
    }

    public void Translate(ZMatrix zmatrix)
    {
        zmatrix.Translate(fX, fY, fZ);
    }

    public void SetInitialAngle(int i, int j, int k)
    {
        fXAngle = i;
        fYAngle = j;
        fZAngle = k;
    }

    static void SetWorld(ZWorld zworld)
    {
        fWorld = zworld;
        fViewer = ZWorld.fViewer;
    }

    public void ATransform(ZMatrix zmatrix)
    {
        for(int i = 0; i < fNumVertices; i++)
        {
            fVertices[i].fAx = (int)((float)fVertices[i].fWx * zmatrix.fMatrix[0][0] + (float)fVertices[i].fWy * zmatrix.fMatrix[1][0] + (float)fVertices[i].fWz * zmatrix.fMatrix[2][0] + zmatrix.fMatrix[3][0]);
            fVertices[i].fAy = (int)((float)fVertices[i].fWx * zmatrix.fMatrix[0][1] + (float)fVertices[i].fWy * zmatrix.fMatrix[1][1] + (float)fVertices[i].fWz * zmatrix.fMatrix[2][1] + zmatrix.fMatrix[3][1]);
            fVertices[i].fAz = (int)((float)fVertices[i].fWx * zmatrix.fMatrix[0][2] + (float)fVertices[i].fWy * zmatrix.fMatrix[1][2] + (float)fVertices[i].fWz * zmatrix.fMatrix[2][2] + zmatrix.fMatrix[3][2]);
            if(fVertices[i].fAz == 0)
                fVertices[i].fAz = 1;
        }

    }

    public void ExplodeIntoPolygonPieces()
    {
        int i = fNumPolygons;
        if(i > 5)
            i = 5;
        for(int j = 0; j < i; j++)
        {
            ZExplodingObject zexplodingobject = new ZExplodingObject();
            zexplodingobject.SetVertices(fPolygons[j].fVertices, fPolygons[j].fNumVertices);
            zexplodingobject.SetAFace(fPolygons[j]);
            zexplodingobject.SetInitialTranslation(fX, 0, fZ);
            zexplodingobject.SetInitialAngle(fXAngle, fYAngle, fZAngle);
            zexplodingobject.SetType(2);
            zexplodingobject.fStatus = 0;
            zexplodingobject.fType = 3;
            zexplodingobject.fAction = 6;
            zexplodingobject.fExplodable = false;
            zexplodingobject.fCanBeHitByPlayerBullet = false;
            zexplodingobject.fShouldBeCheckForCollision = false;
            fWorld.Add(zexplodingobject);
        }

    }

    boolean CheckCollisionWhenMoving(int i, int j, int k, int l)
    {
        if(!fShouldBeCheckForCollision)
            return false;
        if(fType == 0 || fType == 3 || fStatus == 0)
            return false;
        int i1 = fX - fRadius;
        int j1 = fX + fRadius;
        int k1 = fZ - fRadius;
        int l1 = fZ + fRadius;
        if(j1 < i)
            return false;
        if(i1 > k)
            return false;
        if(l1 < j)
            return false;
        return k1 <= l;
    }

    public void SetViewerMidPos(int i, int j)
    {
        for(int k = 0; k < fNumPolygons; k++)
            fPolygons[k].SetViewerMidPos(i, j);

    }

    public void Transform(ZMatrix zmatrix)
    {
        for(int i = 0; i < fNumVertices; i++)
        {
            int j = fVertices[i].fLx;
            int k = fVertices[i].fLy;
            int l = fVertices[i].fLz;
            fVertices[i].fWx = (int)((float)j * zmatrix.fMatrix[0][0] + (float)k * zmatrix.fMatrix[1][0] + (float)l * zmatrix.fMatrix[2][0] + zmatrix.fMatrix[3][0]);
            fVertices[i].fWy = (int)((float)j * zmatrix.fMatrix[0][1] + (float)k * zmatrix.fMatrix[1][1] + (float)l * zmatrix.fMatrix[2][1] + zmatrix.fMatrix[3][1]);
            fVertices[i].fWz = (int)((float)j * zmatrix.fMatrix[0][2] + (float)k * zmatrix.fMatrix[1][2] + (float)l * zmatrix.fMatrix[2][2] + zmatrix.fMatrix[3][2]);
        }

    }

    public void SetVertices(ZVertex azvertex[], int i)
    {
        fVertices = new ZVertex[i];
        for(int j = 0; j < i; j++)
            fVertices[j] = new ZVertex(azvertex[j]);

        fNumVertices = i;
    }

    public void SetLight(ZLight zlight)
    {
        for(int i = 0; i < fNumPolygons; i++)
            fPolygons[i].SetLight(zlight);

    }

    public void SetInitialTranslation(int i, int j, int k)
    {
        fX = i;
        fY = j;
        fZ = k;
    }

    public void SetMaxLifeTime(int i)
    {
        fMaxLifeTime = i;
    }

    public void AProject()
    {
        for(int i = 0; i < fNumVertices; i++)
        {
            int j = fVertices[i].fAz;
            fVertices[i].fSx = (fViewerDistance * fVertices[i].fAx) / j;
            fVertices[i].fSy = (fViewerDistance * fVertices[i].fAy) / j;
        }

    }

    public void SetFacets(int ai[])
    {
        int i = 0;
        int j = ai[i++];
        ZPolygon azpolygon[] = new ZPolygon[100];
        int k = 0;
        for(int l = 0; l < j; l++)
        {
            int j1 = ai[i++];
            for(int k1 = 0; k1 < j1; k1++)
            {
                int l1 = ai[i++];
                azpolygon[k] = new ZPolygon();
                azpolygon[k].fVertices = new ZVertex[l1];
                for(int i2 = 0; i2 < l1; i2++)
                {
                    azpolygon[k].fVertices[i2] = fVertices[ai[i]];
                    i++;
                }

                azpolygon[k].fNumVertices = l1;
                azpolygon[k].fRed = ai[i++];
                azpolygon[k].fGreen = ai[i++];
                azpolygon[k].fBlue = ai[i++];
                azpolygon[k].GetLocalNormal();
                azpolygon[k].GetNormalLength();
                azpolygon[k].fObject = this;
                k++;
            }

            fNumPolygons += j1;
        }

        fPolygons = new ZPolygon[fNumPolygons];
        for(int i1 = 0; i1 < fNumPolygons; i1++)
            fPolygons[i1] = azpolygon[i1];

        fRadius = 10;
    }

    public void ExplodeIntoDebris()
    {
        ZVertex azvertex[] = new ZVertex[5];
        int i = 0;
        do
            azvertex[i] = new ZVertex();
        while(++i < 5);
        azvertex[0].SetLocal(-10, 10, -10);
        azvertex[1].SetLocal(10, 10, -10);
        azvertex[2].SetLocal(0, 0, -10);
        azvertex[3].SetLocal(0, 10, 0);
        int ai[] = {
            1, 4, 3, 2, 1, 0, 220, 220, 220, 3, 
            1, 2, 3, 220, 220, 220, 3, 3, 0, 1, 
            220, 220, 220, 3, 0, 3, 2, 220, 220, 220
        };
        int j = 0;
        do
        {
            ZExplodingObject zexplodingobject = new ZExplodingObject();
            zexplodingobject.SetVertices(azvertex, 5);
            zexplodingobject.SetFacets(ai);
            zexplodingobject.SetInitialTranslation(fX, fY, fZ);
            zexplodingobject.SetSpeed(5);
            zexplodingobject.SetInitialAngle(0, (int)(Math.random() * 1920D), 0);
            zexplodingobject.fStatus = 0;
            zexplodingobject.fType = 3;
            zexplodingobject.fAction = 6;
            zexplodingobject.fExplodable = false;
            zexplodingobject.fCanBeHitByPlayerBullet = false;
            zexplodingobject.fShouldBeCheckForCollision = false;
            fWorld.Add(zexplodingobject);
        } while(++j < 7);
    }

    public void Rotate(ZMatrix zmatrix)
    {
        zmatrix.Rotate(fXAngle, fYAngle, fZAngle);
    }

    public void Move()
    {
        if(fMaxLifeTime != 0x7fffffff)
            fLifeTime++;
        if(fSpeed != 0)
        {
            float f = (float)fSpeed * ZTable.fCos[fYAngle];
            float f1 = (float)fSpeed * ZTable.fSin[fYAngle];
            int i = fX;
            int j = fZ;
            fX += (int)f1;
            fZ += (int)f;
            if(fType == 1 && fStatus != 0 && fAction != 7)
            {
                for(int k = 0; k < fWorld.fNumObjects; k++)
                    if(fWorld.fObjects[k] != this && fWorld.fObjects[k].CheckCollisionWhenMoving(fX - 20, fZ - 20, fX + 20, fZ + 20))
                    {
                        fAction = 7;
                        fStatusTimer = 0;
                        fSpeed = 0;
                        fX = i;
                        fZ = j;
                        return;
                    }

                if(CheckCollisionWhenMoving(fViewer.fX - 80, fViewer.fZ - 80, fViewer.fX + 80, fViewer.fZ + 80) && fStatus != 0)
                {
                    fAction = 7;
                    fStatusTimer = 0;
                    fSpeed = 0;
                    fX = i;
                    fZ = j;
                    return;
                }
                if(fWorld.HasPassedWorldEdges(fX - fRadius, fZ - fRadius))
                {
                    fAction = 7;
                    fStatusTimer = 0;
                    fSpeed = 0;
                    fX = i;
                    fZ = j;
                    return;
                }
            }
        }
        if(fYSpeed != 0)
            fY += fYSpeed;
        if(fXRotationSpeed != 0)
        {
            fXAngle += fXRotationSpeed;
            if(fXAngle >= 1920)
                fXAngle -= 1920;
            else
            if(fXAngle < 0)
                fXAngle += 1920;
        }
        if(fYRotationSpeed != 0)
        {
            fYAngle += fYRotationSpeed;
            if(fYAngle >= 1920)
                fYAngle -= 1920;
            else
            if(fYAngle < 0)
                fYAngle += 1920;
        }
        if(fZRotationSpeed != 0)
        {
            fZAngle += fZRotationSpeed;
            if(fZAngle > 1920)
            {
                fZAngle -= 1920;
                return;
            }
            if(fZAngle < 0)
                fZAngle += 1920;
        }
    }

    public ZObject()
    {
        fMaxLifeTime = 0x7fffffff;
        fWorldXMin = 500;
        fWorldXMax = 30000;
        fWorldZMin = 500;
        fWorldZMax = 30000;
        fNumPolygons = 0;
        fX = fY = fZ = fSpeed = fXAngle = fYAngle = fZAngle = 0;
        fStatus = 0;
        fAction = 0;
        fType = 1;
        fExplodable = true;
        fCanBeHitByPlayerBullet = true;
        fShouldBeCheckForCollision = true;
    }

    static final int MAX_INTEGER = 0x7fffffff;
    static final int LIFE_TIME_INFINITE = 0x7fffffff;
    static ZWorld fWorld;
    int fNumVertices;
    int fNumPolygons;
    int fX;
    int fY;
    int fZ;
    ZPolygon fPolygons[];
    ZVertex fVertices[];
    int fXAngle;
    int fYAngle;
    int fZAngle;
    int fViewerDistance;
    static ZMatrix fMatrix = new ZMatrix();
    int fSpeed;
    int fOriginalSpeed;
    int fYSpeed;
    int fRadius;
    int fXRotationSpeed;
    int fYRotationSpeed;
    int fZRotationSpeed;
    int fLifeTime;
    int fMaxLifeTime;
    int fWorldXMin;
    int fWorldXMax;
    int fWorldZMin;
    int fWorldZMax;
    int fStatusTimer;
    static final int IDLE = 0;
    static final int MOVING = 1;
    static final int ROTATING = 2;
    static final int START_EXPLODING = 3;
    static final int EXPLODING_DOWN = 4;
    static final int EXPLODING_UP = 5;
    static final int HIT = 6;
    static final int AVOIDING_OBSTACLES = 7;
    int fAction;
    static final int DEAD = 0;
    static final int ALIVE = 1;
    int fStatus;
    static final int PLAYER_BULLET = 0;
    static final int ENEMY_BULLET = 5;
    static final int ENEMY = 1;
    static final int EXPLOSION = 2;
    static final int DEBRIS = 3;
    static final int STATIONARY = 4;
    int fType;
    boolean fExplodable;
    boolean fCanBeHitByPlayerBullet;
    boolean fCollidingWithViewer;
    boolean fShouldBeCheckForCollision;
    boolean fHasCollidedWidthPlayer;
    boolean fHasCollidedWidthOtherObject;
    static ZView fViewer;
    static final int ANGLE_360 = 1920;
    int fEnergy;

}

⌨️ 快捷键说明

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