当前位置: 首页>>代码示例>>C#>>正文


C# SPoint.SqDistFromOrigin方法代码示例

本文整理汇总了C#中SPoint.SqDistFromOrigin方法的典型用法代码示例。如果您正苦于以下问题:C# SPoint.SqDistFromOrigin方法的具体用法?C# SPoint.SqDistFromOrigin怎么用?C# SPoint.SqDistFromOrigin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SPoint的用法示例。


在下文中一共展示了SPoint.SqDistFromOrigin方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdatePos

 public void UpdatePos()
 {
     SPoint vec = new SPoint();
     vec.y=target.y-at.y;
     vec.x=target.x-at.x;
     if(distTarget<minDist)
         distTarget=minDist;
     float movDistSq = vec.SqDistFromOrigin();
     float decel=0.5f;
     if(movDistSq>panSpeed*panSpeed){//moving too fast
         float dir = Mathf.Atan2(vec.y, vec.x);
         vec.x=Mathf.Cos(dir)*panSpeed;
         vec.y=Mathf.Sin(dir)*panSpeed;
         at.x+=vec.x*decel;
         at.y+=vec.y*decel;
     }else{
         at.x+=vec.x*decel;
         at.y+=vec.y*decel;
     }
     if(distTarget>dist)
         if(distTarget>dist+zoomSpeed)
             dist+=zoomSpeed;
     else
         dist=distTarget;
     else
         if(distTarget<dist-zoomSpeed)
             dist-=zoomSpeed;
     else
         dist=distTarget;
 }
开发者ID:cWalters2,项目名称:NeonNinja,代码行数:30,代码来源:CameraController.cs

示例2: InterpCorner

 protected AttkVtx InterpCorner(AttkVtx[] arrV, int arrLen, SPoint oPos)
 {
     AttkVtx rtnVtx = new AttkVtx();
     float dist = 0;
     float distSum=0;
     SPoint tPos = new SPoint();
     for(int i = 0; i< arrLen;i++){
         tPos.x = arrV[i].pos.x-oPos.x;//tranlated for ease of calculations
         tPos.y = arrV[i].pos.y-oPos.y;
         dist=Mathf.Sqrt(tPos.SqDistFromOrigin());
         distSum+=dist;
     }//now average out verts
     for(int i = 0; i< arrLen;i++){
         tPos.x = arrV[i].pos.x-oPos.x;//tranlated for ease of calculations
         tPos.y = arrV[i].pos.y-oPos.y;
         dist=Mathf.Sqrt(tPos.SqDistFromOrigin());
         rtnVtx.mag+=(dist/distSum)*arrV[i].mag;
         rtnVtx.dir+=(dist/distSum)*arrV[i].dir;
         rtnVtx.dmg+=(dist/distSum)*arrV[i].dmg;
         rtnVtx.wgt+=(dist/distSum)*arrV[i].wgt;
     }
     return rtnVtx;
 }
开发者ID:cWalters2,项目名称:ShSoul,代码行数:23,代码来源:Fighter.cs

示例3: ColDetect

    protected bool ColDetect(Ninja plr)
    {
        if (gameWon) {

        if(Input.anyKey){
                Application.LoadLevel ("menu");
                foreach (GameObject o in Object.FindObjectsOfType<GameObject>()) {
                    Destroy(o);}
                Application.LoadLevel ("menu");
            }
        return false;
        }

        bool hitflag=false;
        int polyIndex = -1;//to keep record of which polygon caused the collision
        int hitIndex = -1;//to keep record of which side of the polygon caused collision
        SPoint[] plBox, plLast;
        bool retFlag=false;//holds the return value
        //this loads plBox[] and plLast[] with the player's hitboc this
        //and last frame respectively
        int hbLen=4;
        SPoint posDiff = new SPoint(plr.GetPos().x-plr.GetLastPos().x, plr.GetPos().y-plr.GetLastPos().y);
        if(posDiff.SqDistFromOrigin()!=0){
            plBox = plr.GetCurrentColBox();
            plLast=plr.GetCurrentColBox();
            hbLen = 6;
            for(int i=0;i<hbLen;i++){
                plLast[i].x-=posDiff.x;
                plLast[i].y-=posDiff.y;
            }
        }else{
            plBox = plr.GetHitBox();
            plLast=plr.GetHitBox();
            hbLen=4;
        }
        if((plr.GetPos().x>9)&&(plr.GetPos().x-posDiff.x<9))
            hbLen= hbLen;

        SPoint hld;
        float[] plAng = new float[hbLen];
        for(int i=0;i<hbLen-1;i++){
            plAng[i]= new SPoint(plBox[i].x-plBox[i+1].x,plBox[i].y-plBox[i+1].y).GetDir();
        }
        plAng[hbLen-1] = new SPoint(plBox[hbLen-1].x-plBox[0].x,plBox[hbLen-1].y-plBox[0].y).GetDir();
        // FillCollisionBox(plBox, plr->GetPos(), plr->stats.size.y, plr->stats.size.x);
        // FillCollisionBox(plLast, plr->stats.motion.lastPos, plr->stats.size.y, plr->stats.size.x);
        //set up angles here for easy acces along with the hitboxes above.

        for(int i = 0; i < tBox.iLength; i++){
            hitflag = true;//assume true, then prove false.
            for(int j = 0; j < tBox.GetJlength(i); j++)
            if(!plr.CheckAxis(tBox.GetSPoint(i, j), tBox.GetAng(i, j), plBox,tBox.pBounds[i], hbLen, tBox.jLength[i])){ //no axis intersection
                hitflag = false;
                j=tBox.GetJlength(i);//exit loop early
            }
            if(hitflag)//possible collision; check against other polygon axise
            for(int j = 0; j < hbLen; j++){
                if(!plr.CheckAxis(plBox[j], plAng[j], plBox, tBox.pBounds[i], hbLen, tBox.jLength[i])){ //no axis intersection
                    hitflag = false;
                    j=hbLen;//exit loop early
                }
            }
            if(hitflag){//all checks are done, collision is sure
                polyIndex = i;//keep record of the last polygon caused the flag
                i=tBox.iLength;//Collision detected, end loop early
            }

        }

        SPoint prV=new SPoint();
        SPoint pCtr;

                //extra added to detect and destroy any projectiles on-screen
        int cv;
        bool pHitFlag = true;

        float flAng = 1.55f;
        if(polyIndex!=-1){
            //hitflag = true;//force to true to return
            retFlag=true;
            //see which side has collided
            for(int i = 0; i < tBox.GetJlength(polyIndex); i++){
                if(!plr.CheckAxis(tBox.GetSPoint(polyIndex, i), tBox.GetAng(polyIndex, i), plLast, tBox.pBounds[polyIndex], hbLen, tBox.jLength[polyIndex])){
                    hitIndex = i;
                    i=tBox.GetJlength(polyIndex);//end loop prematurely
                }
            }
            bool pAxisFlag=false;
            if(hitIndex == -1){
                for(int i  = 0; i < hbLen; i++){//check player angs to find the axis
                    if(!plr.CheckAxis(plLast[i], plAng[i], plLast, tBox.pBounds[polyIndex], hbLen, tBox.jLength[polyIndex]) ){
                        hitIndex = i;
                        pAxisFlag = true;
                    }
                }//do collision detection again for this particular index on the polygon
            }//to get the exit vector

            SPoint axP = new SPoint();
            if(hitIndex>=0){

//.........这里部分代码省略.........
开发者ID:cWalters2,项目名称:NeonNinja,代码行数:101,代码来源:Stage.cs

示例4: GroundTrack

    public bool GroundTrack(Ninja plr)
    {
        //specialized collision detection function
        //ensures the Ninja keeps flush with the floor
        bool hitflag = true;
        bool indflag = true;
        bool pAxisFlag = false;
        float hitInd = -1;
        int polyIndex = -1;
        SPoint[] plBox = new SPoint[4];
        SPoint[] plLast = new SPoint[4];
        for(int i=0;i<4;i++){
            plBox[i]=new SPoint();
            plLast[i]=new SPoint();
        }
        float[] plAng = {0, Mathf.PI/2, Mathf.PI, -Mathf.PI/2};
        int hbLen=4;

                //modified from colision detect to move the player down

        FillCollisionBox(plBox, new SPoint(plr.GetPos().x, plr.GetPos().y-plr.stats.size.y/2), plr.stats.size.y, plr.stats.size.x);
        FillCollisionBox(plLast, new SPoint(plr.GetPos().x, plr.GetPos().y+plr.stats.size.y/2), plr.stats.size.y, plr.stats.size.x);
        //holds default angles

        for(int i = 0; i < tBox.iLength; i++){
            hitflag = true;
            for(int j = 0; j < tBox.GetJlength(i); j++)
                if(!plr.CheckAxis(tBox.GetSPoint(i, j), tBox.GetAng(i, j), plBox,tBox.pBounds[i], hbLen, tBox.jLength[i]) ) //no axis intersection
                    hitflag = false;
            if(hitflag)
                for(int j = 0; j < 4; j++)
                    if(!plr.CheckAxis(plBox[j], plAng[j], plBox,tBox.pBounds[i], hbLen, tBox.jLength[i]) ) //no axis intersection
                        hitflag = false;
            if(hitflag)
                polyIndex = i;
        }
        int hitIndex = -1;
        if(polyIndex >= 0){
            hitflag = true;
            float moveDist = 0;
            for(int i = 0; i < tBox.GetJlength(polyIndex); i++){
                if(!plr.CheckAxis(tBox.GetSPoint(polyIndex, i), tBox.GetAng(polyIndex, i), plLast,tBox.pBounds[polyIndex], hbLen, tBox.jLength[polyIndex])){
                    hitIndex = i;
                }
            }
            if(hitIndex == -1){
                //check player angs to find the axis
                for(int i  = 0; i < 4; i++){
                    if(!plr.CheckAxis(plLast[i], plAng[i], plLast, tBox.pBounds[polyIndex], hbLen, tBox.jLength[polyIndex]) ){
                        hitIndex = i;
                        pAxisFlag = true;
                    }
                }
            }

            bool floorHit = false;
            SPoint floorVec=new SPoint(0,0);
            plr.stats.motion.pos.y-=plr.stats.size.y/2;
            if(!pAxisFlag)
                floorVec = ExitDist(polyIndex, tBox.GetSPoint(polyIndex, hitIndex), tBox.GetAng(polyIndex, hitIndex), plr, -1);
            else
                floorVec = ExitDist(polyIndex, plBox[hitIndex], plAng[hitIndex], plr, -1);
            float wallAng = Mathf.Atan2(floorVec.y, floorVec.x)-Mathf.PI/2;
            float wallDist=Mathf.Sqrt(floorVec.SqDistFromOrigin());
            if((floorVec.x==0)&&(floorVec.y==0))
                plr.stats.motion.pos.y+=plr.stats.size.y/2;
            else if(Mathf.Cos(wallAng)!=0){
                plr.stats.motion.pos.y+=(wallDist)/Mathf.Cos(wallAng);
                floorHit=true;
            }
            else{
                plr.stats.motion.pos.y+=plr.stats.size.y/2;
                floorHit=true;
            }
            if((floorHit)&&(!plr.fHelper.airborne)){
                plr.Land(tBox.GetAng(polyIndex, hitIndex));

                return true;
            }
        }
        return false;
    }
开发者ID:cWalters2,项目名称:NeonNinja,代码行数:82,代码来源:Stage.cs


注:本文中的SPoint.SqDistFromOrigin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。