Exemplo n.º 1
0
    public bool ProjectileDetect(Projectile p)
    {
        SPoint pCtr, prV;
        bool pHitFlag=false;
        for (int i = 0; i < tBox.iLength; i++) {
            float[] prAngs = new float[tBox.GetJlength (i)];
            pCtr = new SPoint (p.pos.x, p.pos.y);
            int pJl = tBox.GetJlength (i) - 1;
            float lastAng = Mathf.Atan2 ((tBox.pBounds [i] [pJl].y - pCtr.y), (tBox.pBounds [i] [pJl].x - pCtr.x));
            pHitFlag = true;
            for (int j = 0; j < tBox.GetJlength(i); j++){
                if (!p.CheckAxis(tBox.GetSPoint(i, j), tBox.GetAng(i, j), p.pos, tBox.pBounds[i], tBox.jLength[i]))
                { //no axis intersection
                    pHitFlag = false;
                    j = tBox.GetJlength(i);//exit loop early
                }
            }
                /*for (int j = 0; j < tBox.GetJlength(i); j++) {
                    prV = new SPoint (tBox.pBounds [i] [j].x - pCtr.x, tBox.pBounds [i] [j].y - pCtr.y);
                    prAngs [j] = Mathf.Atan2 (prV.y, prV.x);
                    if ((lastAng > prAngs [j]) && (lastAng -prAngs [j]  < Mathf.PI )){
                        pHitFlag = false;

                    }
                    if ((lastAng < prAngs [j]) && (lastAng -prAngs [j]  < - Mathf.PI )){
                        pHitFlag = false;

                    }

                    lastAng = prAngs [j];
                }*/
                if (pHitFlag){

                return true;
            }

        }
        return pHitFlag;
    }