Пример #1
0
    public virtual void AttackDetect(Ninja plr)
    {
        bool multiHitFlag = false;
        string hitText;
        //std::stringstream log;
        bool hitflag = true;
        int atkLen;
        int spI=0;
        int spJ=0;
        int hbLen=4;
        SPoint[] plBox;
        SPoint[][] spBox;
        float[] plAng ={0, Mathf.PI/2, Mathf.PI, -Mathf.PI/2};
        int il = 0;

            il = attackBox.trackList[fHelper.atkType].iLength;//num of tracks
        AttkTrack aBox = new AttkTrack();

        int polyHit=-1;
        plBox = plr.GetHitBox();//loads victim hitbox into plBox
        //each side is made from the vertices [i] and [+1]
        int numPoly = 0; //number of polygons in a track;
        int pInd = 0;//polygon index
        SPoint[] pHdr = new SPoint[8];

        il = 1;
        if(!atkTmr.IsReady()){//only continue if an attack is out

            //attack checks

            for(int t=0;t<il;t++){//iterate through all sub tr

                //if(plr.CharName().CompareTo("PsySword")==0)
                //	int ds=2;//checkpt
                if((fHelper.seqInd!=0)&&((fHelper.seqInd-1)!=t)){
                    hitflag=false;//do nothing, for now
                }else {
                    aBox= new AttkTrack();
                    aBox.noHit=false;
                        if(attackBox.trackList[fHelper.atkType].trackType==AttkBox.FLASH){
                            if(fHelper.frame>lastFlash){

                                for(AttkVtx av = attackBox.trackList[fHelper.atkType].aVtx[0][0]; av!=null;av=av.next){
                                    if((av.frame==lastFlash)&&(av.next!=null)){
                                        lastFlash=av.next.frame;
                                        attackBox.flashAtkRdy=true;
                                        attackBox.ResetHits (fHelper.atkType);
                                        while(av.next!=null)
                                            av=av.next;
                                        //av=null;//force exit
                                    }
                                }
                            }
                        }
                    attackBox.FetchFrame(fHelper.atkType, atkTmr.GetLen(), fHelper.frame, t, new SPoint(GetPos().x, GetPos().y), fHelper.IsFacingRight(), aBox);//fetches frame into aBox

                        //aBox has its polygons separated into different tracks for efficiency
                    //make a new SPoint array, spBox, to use checkAxis.

                    hitflag=true;
                    if(aBox.noHit==false){

                        //if(plr.CharName().CompareTo("PsySword")==0)
                        //	int d2s=2;//checkpt
                        spBox=new SPoint[aBox.iLength][];
                        for(int i=0;i<aBox.iLength;i++)
                            spBox[i]=new SPoint[aBox.jLength[i]];
                        aBox.FetchSPArr(spBox);
                            if(ClashCheck(plr, spBox, aBox.atkAng)){
                            SPoint p1Vel = new SPoint(GetPos().x - plr.GetPos().x, GetPos().y - plr.GetPos().y).GetNormal();
                            float cRat = 0.2f;
                            stats.motion.vel.x = p1Vel.x*cRat;
                            stats.motion.vel.y = p1Vel.y*cRat;
                            plr.stats.motion.vel.x = -p1Vel.x*cRat;
                            plr.stats.motion.vel.y = -p1Vel.y*cRat;
                            fHelper.airborne = true;
                            plr.fHelper.airborne = true;
                            return;
                            }

                        numPoly=aBox.iLength;
                            bool hitCheck = false;
                        for(pInd=0;pInd<numPoly;pInd++){//iterate per poly
                                hitflag=true;
                            atkLen =  aBox.GetJlength(pInd);
                            for(int j = 0; j < atkLen; j++)
                                if(!CheckAxis(aBox.aVtx[pInd][j].pos, aBox.atkAng[pInd][j], plBox, spBox[pInd], hbLen, aBox.GetJlength(pInd)) ) //no axis intersection
                                    hitflag = false;

                            if(hitflag)//test on the axis of the player hit box to confirm
                                for(int j = 0; j < 4; j++)
                                    if(!CheckAxis(plBox[j], plAng[j], plBox, spBox[pInd], hbLen, aBox.GetJlength(pInd))) //no axis intersection
                                        hitflag = false;
                            if(hitflag)
                                    hitCheck=true;

                        }
                            hitflag=hitCheck;
                        //log.str(std::string());
                        /*	for(int i=0;i<aBox.iLength;i++){//tidy up
                            if(!aBox.noHit)
                                delete [] spBox[i];
                        }
                        if(aBox.iLength==0){
                            int ee = 2;
                            //log.str(std::string());
                        }
                        else if(!aBox.noHit){//make sure it was hit
                            if(aBox.iLength>1)
                                delete [] spBox;
                            else
                                delete spBox;
                            spBox=NULL;
                        }*/
                    }else
                        hitflag=false;//abandon
                    if(hitflag){
                        AttkData retOb  = new AttkData(aBox.GetJlength(t));//initilize for holding vals
                        Attack(plr, t, aBox, retOb);
                        if(!retOb.noHit){

                            plr.GetHit(retOb);
                            multiHitFlag=true;
                            t=il;//force exit; one track hit
                        }

                    }

                }
            }
        }
        //seems the ideal place to determine pushback
        //if the difference in z is less than their average width
        if((Mathf.Abs(plr.GetPos().x-GetPos().x) < (plr.stats.size.x+stats.size.x)/2  )
           &&(Mathf.Abs(plr.GetPos().y-GetPos().y) < (plr.stats.size.y+stats.size.y)/2)
           &&(!fHelper.airborne)&&(!plr.fHelper.airborne))
        if(plr.GetPos().x-GetPos().x>0){
            stats.motion.move.x-=0.1f;
            plr.stats.motion.move.x+=0.1f;}
        else{
            stats.motion.move.x+=0.1f;
            plr.stats.motion.move.x-=0.1f;}
    }