Esempio n. 1
0
    void FrameUpdate()
    {
        // 这种情况是飞行道具打不中人,飞出一段距离就消失
        if (aimId == -1)
        {
            if (VInt3.Distance(initPosition, mover.position) >= distance)
            {
                mover.StopMove();
                Destroy(gameObject);
            }
        }
        // 这种情况是可以打中人,会一直跟随目标对象,直到打中为止
        else
        {
            if (aimPlayer == null)
            {
                aimPlayer = Global.entity [aimId].GetComponent <Player> ();
            }
            // 方向跟随目标
            transform.LookAt((Vector3)aimPlayer.mover.position + new Vector3(0, (float)offsetY, 0));
            // 判断是否打中目标
            if (!isHit)
            {
                if (VInt3.Distance(mover.position, aimPlayer.mover.position) < (VInt)2.0f)
                {
                    isHit = true;
                    aimPlayer.Damage(aimId, 200);
                    mover.StopMove();
                    Destroy(gameObject);
                }
            }
        }

        mover.StartMove((VInt3)transform.forward, speed);
    }
Esempio n. 2
0
        /** Total Length of the path.
         * Calculates the total length of the #vectorPath.
         * Cache this rather than call this function every time since it will calculate the length every time, not just return a cached value.
         * \returns Total length of #vectorPath, if #vectorPath is null positive infinity is returned.
         */
        public float GetTotalLength()
        {
            if (vectorPath == null)
            {
                return(float.PositiveInfinity);
            }
            float tot = 0;

            //Good Game
            //for (int i = 0; i < vectorPath.Count-1; i++) tot += Vector3.Distance(vectorPath[i], vectorPath[i+1]);
            for (int i = 0; i < vectorPath.Count - 1; i++)
            {
                tot += VInt3.Distance(vectorPath[i], vectorPath[i + 1]);
            }
            return(tot);
        }
Esempio n. 3
0
 public void StartMove(VInt3 moveVector, VInt speed)
 {
     // 保存方向向量
     dirVector = moveVector;
     // 计算下一步应该要走的位置
     targetPosition = targetPosition + moveVector * LogicFrame.frameIntervalTime * speed;
     // 计算移动速度
     speedNormal = speed;
     speedReal   = VInt3.Distance((VInt3)transform.position, targetPosition) / (LogicFrame.frameIntervalTime + (VInt)Time.deltaTime / (VInt)2.0f);
     if (moveStatus == MoveStatus.Forecast)
     {
         Debug.Log("嘻嘻 => " + speedReal.scalar);
     }
     // 移动的状态
     moveStatus = MoveStatus.Target;
 }
Esempio n. 4
0
    public void StopMove()
    {
        VInt3 currPosition = (VInt3)transform.position;

        if (moveStatus == MoveStatus.Target || moveStatus == MoveStatus.Forecast)
        {
            if (currPosition != targetPosition)
            {
                moveStatus = MoveStatus.Back;
                speedReal  = VInt3.Distance(currPosition, targetPosition) / (LogicFrame.frameIntervalTime + (VInt)Time.deltaTime / (VInt)2.0f);
            }
            else
            {
                moveStatus = MoveStatus.Stop;
            }
        }
    }
Esempio n. 5
0
    void OnAttack()
    {
        isAttack = true;
        // 判断要攻击的是哪一个队伍
        ArrayList aimList = new ArrayList();

        foreach (int uid in Global.myTeamUid)
        {
            if (this.uid == uid)
            {
                aimList = Global.otherTeamUid;
                break;
            }
        }
        foreach (int uid in Global.otherTeamUid)
        {
            if (this.uid == uid)
            {
                aimList = Global.myTeamUid;
                break;
            }
        }
        // 被攻击者 id,如果为 -1 则表示超出攻击范围
        int aimId = -1;
        // 如果当前距离和敌方所有玩家大于攻击距离则在原地攻击。否则攻击对方距离最近的非状态的玩家
        int  count       = 0;
        VInt minDistance = VInt.zero;;

        foreach (int otherUid in aimList)
        {
            Player player   = Global.entity [otherUid].GetComponent <Player> ();
            VInt   distance = VInt3.Distance(mover.position, player.mover.position);
            if (distance > atkRange)
            {
                count++;
            }
            else
            {
                if (!player.isDeath)
                {
                    if (distance < minDistance || minDistance == VInt.zero)
                    {
                        minDistance = distance;
                        aimId       = otherUid;
                    }
                }
                else
                {
                    count++;
                }
            }
        }
        if (count == Global.otherTeamUid.Count)
        {
            aimId = -1;
        }

        // 转向被攻击者
        if (aimId != -1)
        {
            transform.LookAt((Vector3)Global.entity [aimId].GetComponent <Player> ().mover.position);
        }
        // 攻击动画,控制攻击速度
        String animName       = "attack" + (combo + 1);
        VInt   animationSpeed = (VInt)animation [animName].length / ((VInt)1.0f / atkSpeedReal);

        animation [animName].speed = (float)animationSpeed;
        animation.Play(animName);
        // 攻击特效
        String     prefabPath = "Prefabs/hero" + heroCode + "/Fx_hero" + heroCode + "_attack_0" + (combo + 1);
        GameObject _attack    = Resources.Load <GameObject> (prefabPath);
        GameObject attack     = Instantiate(_attack, (Vector3)mover.position, transform.rotation);

        // 3 秒后销毁特效
        Destroy(attack, 3.0f);

        // 攻击动画进行一段时间后会进行出击
        float delay = (float)(atkTime / animationSpeed);

        LogicFrame.InvokeDelay(this, delay, "AttackHit", new object[] { aimId });

        // 控制连击次数
        if (combo < 3)
        {
            combo++;
        }
        else
        {
            combo = 0;
        }
        lastComboTime = (VInt)Time.time;
    }
Esempio n. 6
0
        //Good Game
        //public List<Vector3> SmoothSimple (List<Vector3> path) {
        public List <VInt3> SmoothSimple(List <VInt3> path)
        {
            if (path.Count < 2)
            {
                return(path);
            }

            //Good Game
            //List<Vector3> subdivided;
            List <VInt3> subdivided;

            if (uniformLength)
            {
                // Clamp to a small value to avoid the path being divided into a huge number of segments
                maxSegmentLength = Mathf.Max(maxSegmentLength, 0.005f);

                float pathLength = 0;
                for (int i = 0; i < path.Count - 1; i++)
                {
                    //Good Game
                    //pathLength += Vector3.Distance(path[i], path[i+1]);
                    pathLength += VInt3.Distance(path[i], path[i + 1]);
                }

                int estimatedNumberOfSegments = Mathf.FloorToInt(pathLength / maxSegmentLength);
                // Get a list with an initial capacity high enough so that we can add all points
                //Good Game
                //subdivided = ListPool<Vector3>.Claim(estimatedNumberOfSegments+2);
                subdivided = ListPool <VInt3> .Claim(estimatedNumberOfSegments + 2);

                //Good Game
                float distanceAlong = 0;

                // Sample points every [maxSegmentLength] world units along the path
                for (int i = 0; i < path.Count - 1; i++)
                {
                    var start = path[i];
                    var end   = path[i + 1];

                    //Good Game
                    //float length = Vector3.Distance(start, end);
                    long length = VInt3.Distance(start, end);

                    while (distanceAlong < length)
                    {
                        //Good Game
                        //subdivided.Add(Vector3.Lerp(start, end, distanceAlong / length));
                        subdivided.Add(VInt3.Lerp(start, end, distanceAlong / length));
                        distanceAlong += maxSegmentLength;
                    }

                    distanceAlong -= length;
                }

                // Make sure we get the exact position of the last point
                subdivided.Add(path[path.Count - 1]);
            }
            else
            {
                subdivisions = Mathf.Max(subdivisions, 0);

                if (subdivisions > 10)
                {
                    Debug.LogWarning("Very large number of subdivisions. Cowardly refusing to subdivide every segment into more than " + (1 << subdivisions) + " subsegments");
                    subdivisions = 10;
                }

                int steps = 1 << subdivisions;
                //Good Game
                //subdivided = ListPool<Vector3>.Claim((path.Count-1)*steps + 1);
                subdivided = ListPool <VInt3> .Claim((path.Count - 1) *steps + 1);

                Polygon.Subdivide(path, subdivided, steps);
            }

            if (strength > 0)
            {
                for (int it = 0; it < iterations; it++)
                {
                    //Good Game
                    //Vector3 prev = subdivided[0];
                    VInt3 prev = subdivided[0];

                    for (int i = 1; i < subdivided.Count - 1; i++)
                    {
                        //Good Game
                        //Vector3 tmp = subdivided[i];
                        VInt3 tmp = subdivided[i];

                        // prev is at this point set to the value that subdivided[i-1] had before this loop started
                        // Move the point closer to the average of the adjacent points
                        //Good Game
                        //subdivided[i] = Vector3.Lerp(tmp, (prev+subdivided[i+1])/2F, strength);
                        subdivided[i] = VInt3.Lerp(tmp, (prev + subdivided[i + 1]) / 2F, strength);

                        prev = tmp;
                    }
                }
            }

            return(subdivided);
        }