Esempio n. 1
0
        //选择要去的目标位置.
        void SelectTargetPos()
        {
            if (LockShip != null && TrackAction.IsTracking == false)
            {
                Vector2 targetDir = LockShip.GetPosition() - this.GetPosition();
                targetDir = new Vector2(targetDir.Y, -targetDir.X);
                Maths.Normalize(ref targetDir);

                //根据0~180的随机角度旋转targetDir
                targetDir.TurnTo(targetDir, Maths.Rnd.Next(314) * 0.01f);

                targetDir = targetDir * keepDisFromEnemy + LockShip.GetPosition();
                BattleScene.SceneSizeLimit(ref targetDir);
                TrackPos(targetDir);
            }
        }
Esempio n. 2
0
        //=================

        //TODO: AI攻击!
        void AttckNow()
        {
            //更新手动瞄准方向
            if (LockShip != null)
            {
                this.AimDir = LockShip.GetPosition() - this.GetPosition();
                Maths.Normalize(ref this.AimDir);
            }
            else
            {
                this.AimDir = Vector2.Zero;
            }

            //根据射程随机选择武器
            if (LockShip != null)
            {
                this.Weapon.RndShoot(disFromEnemy);
            }
        }
Esempio n. 3
0
        //选择/更新锁定目标
        void SelectTarget()
        {
            //随机锁定半径内的敌人
            if (this.LockShip == null)
            {
                for (int i = 0; i < CanLockEnemys.Count; i++)
                {
                    if (Vector2.DistanceSquared(CanLockEnemys [i].GetPosition(),
                                                this.GetPosition()) < lockRadius &&
                        CanLockEnemys [i].status != ObjectStatus.Die)
                    {
                        if (Maths.Rnd.Next(1, 4) == 2)
                        {                        //1/3的几率锁定此敌人
                            this.LockShip = CanLockEnemys [i];
                        }
                    }
                }
            }
            else
            {            //锁定更新
                disFromEnemy = Vector2.DistanceSquared(LockShip.GetPosition(),
                                                       this.GetPosition());
                if (disFromEnemy > lockRadius)
                {                  //超出范围就解锁
                    this.LockShip = null;
                }
            }

            //清除死亡的敌人
            if (this.LockShip != null && this.LockShip.status
                == ObjectStatus.Die)
            {
                this.LockShip = null;
            }
            for (int i = 0; i < this.CanLockEnemys.Count; i++)
            {
                if (this.CanLockEnemys[i].status == ObjectStatus.Die)
                {
                    this.CanLockEnemys.RemoveAt(i);
                }
            }
        }