Esempio n. 1
0
 /// <summary>
 /// 显示指引指针
 /// </summary>
 /// <param name="pos">指针出现的位置</param>
 public void ShowGuide(Coord pos)
 {
     if (CurFloorNode.InFloor(pos) && pos.CompareTo(Coord.Empty) != 0)
     {
         this.GuidePoint.Exist    = true;
         this.GuidePoint.Location = Common.GetPointFromCoord(pos);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 检测某位置在某方向在楼层地图上是否是可以通行的
        /// </summary>
        /// <param name="pos">坐标</param>
        /// <param name="dir">方向</param>
        /// <returns>返回一个布尔值,如果不可通行,为false</returns>
        private bool Passable(Coord pos, Direction dir)
        {
            //如果pos是结束位置,为了获取通向其的路径,需要临时标示为通行
            if (pos.CompareTo(TargetPos) == 0)
            {
                return(true);
            }

            //需要检测其他约定需要跳过的图块
            if (CurFloor.EventMap[pos.Row, pos.Col] != null && CurFloor.EventMap[pos.Row, pos.Col].Exist && CurFloor.EventMap[pos.Row, pos.Col].EventName.CompareTo("楼梯") == 0)
            {
                return(false);
            }

            return(CurFloor.IsPassable(pos, dir));
        }
Esempio n. 3
0
        /// <summary>
        /// 获取楼层对象中两点之间的路径(用坐标队列表示)
        /// </summary>
        /// <returns>返回从起点到终点的移动方向的队列,如果没有通行的路线,返回null</returns>
        public Queue <Coord> Compute()
        {
            if (!InMap(StartPos) || !InMap(TargetPos))
            {
                return(null);
            }

            //设置起始搜索路径开始搜索
            PathQueue.Enqueue(StartPath);

            //只要搜索队列中存在一条路径,就继续搜索
            while (PathQueue.Count > 0)
            {
                //从路径队列中获取当前搜索的路线
                Queue <Coord> curPath = PathQueue.Dequeue();

                //从当前路线中获取当前的搜索点
                Coord curPos = curPath.ElementAt(curPath.Count - 1);

                //检查是否为终点坐标,如果搜索到终点,退出循环
                if (curPos.CompareTo(TargetPos) == 0)
                {
                    TargetPath = curPath;
                    break;
                }

                //向四个方向扩展搜索
                foreach (var searchDirection in Around)
                {
                    Coord newPos = curPos;
                    newPos.Offset(searchDirection);

                    //如果新的搜索点未曾搜索过,加入队列以待之后的搜索
                    if (InMap(newPos) && !Passed[newPos.Row, newPos.Col] && Passable(newPos, searchDirection))
                    {
                        Passed[newPos.Row, newPos.Col] = true;

                        Queue <Coord> newPath = new Queue <Coord>(curPath);
                        newPath.Enqueue(newPos);
                        PathQueue.Enqueue(newPath);
                    }
                }
            }

            return(TargetPath);
        }
Esempio n. 4
0
        /// <summary>
        /// 帮助可移动对象移动一个单位的距离,并触发相应的地图事件
        /// </summary>
        public void Move()
        {
            //要计算的最终目标地点
            Point desSite = PreSite;

            //记录之前的坐标,用于与新坐标进行比较
            Coord preStation = this.Mover.Station;

            //如果前方可以通行,直接前进
            if (ObstacleFree)
            {
                desSite = NextSite;
            }
            //如果临界,调整位置使人物走到障碍物的边界而不跨越障碍物
            else if (Critical)
            {
                desSite = MoveToCrisisLine();
            }
            //如果被障碍物遮挡,但前方可以通行,则滑动人物越过障碍物
            else if (Passable)
            {
                desSite = Slide();
            }
            //无法移动,触发事件
            else if (CanTrigger)
            {
                MotaWorld.GetInstance().MapManager.TriggerEvent(FaceToPos, TouchMethod.ImmediatelyTouch, Caller);
            }

            this.Mover.Location = desSite;

            //位置不同时触发新位置上的事件
            if (preStation.CompareTo(this.Mover.Station) != 0 && CanTrigger)
            {
                MotaWorld.GetInstance().MapManager.TriggerEvent(this.Mover.Station, TouchMethod.StationTouch, Caller);
            }
        }
Esempio n. 5
0
 /// <summary>
 /// 显示指引指针
 /// </summary>
 /// <param name="pos">指针出现的位置</param>
 public void ShowGuide(Coord pos)
 {
     if (CurFloorNode.InFloor(pos) && pos.CompareTo(Coord.Empty) != 0)
     {
         this.GuidePoint.Exist = true;
         this.GuidePoint.Location = Common.GetPointFromCoord(pos);
     }
 }
Esempio n. 6
0
        /// <summary>
        /// 检测某位置在某方向在楼层地图上是否是可以通行的
        /// </summary>
        /// <param name="pos">坐标</param>
        /// <param name="dir">方向</param>
        /// <returns>返回一个布尔值,如果不可通行,为false</returns>
        private bool Passable(Coord pos, Direction dir)
        {
            //如果pos是结束位置,为了获取通向其的路径,需要临时标示为通行
            if (pos.CompareTo(TargetPos) == 0)
            {
                return true;
            }

            //需要检测其他约定需要跳过的图块
            if (CurFloor.EventMap[pos.Row, pos.Col] != null && CurFloor.EventMap[pos.Row, pos.Col].Exist && CurFloor.EventMap[pos.Row, pos.Col].EventName.CompareTo("楼梯") == 0)
            {
                return false;
            }

            return CurFloor.IsPassable(pos, dir);
        }