Exemplo n.º 1
0
 public void UpdateMove()
 {
     lock (typeof(MoveObject))
     {
         if (!GetCollisionArea().Contains(touchX, touchY))
         {
             if (findPath != null)
             {
                 CollectionUtils.Clear(findPath);
             }
             findPath = AStarFinder
                        .Find(heuristic,
                              tiles.GetField(),
                              tiles.PixelsToTilesWidth(X()),
                              tiles.PixelsToTilesHeight(Y()),
                              tiles.PixelsToTilesWidth(touchX
                                                       - tiles.GetOffset().x),
                              tiles.PixelsToTilesHeight(touchY
                                                        - tiles.GetOffset().y), allDirection);
         }
         else if (findPath != null)
         {
             CollectionUtils.Clear(findPath);
         }
     }
 }
Exemplo n.º 2
0
 public override void OnLoad()
 {
     if (layerMap == null || original == null)
     {
         return;
     }
     if (!original.GetRectBox().Contains(endLocation.X(), endLocation.Y()))
     {
         if (useCache)
         {
             lock (pathCache)
             {
                 if (pathCache.Count > Loon.Core.LSystem.DEFAULT_MAX_CACHE_SIZE * 10)
                 {
                     pathCache.Clear();
                 }
                 Int32           key        = GetHashCode();
                 List <Vector2f> final_path = (List <Vector2f>)CollectionUtils.Get(pathCache, key);
                 if (final_path == null)
                 {
                     final_path = AStarFinder.Find(heuristic,
                                                   layerMap,
                                                   layerMap.PixelsToTilesWidth(startLocation
                                                                               .X()),
                                                   layerMap.PixelsToTilesHeight(startLocation
                                                                                .Y()),
                                                   layerMap.PixelsToTilesWidth(endLocation
                                                                               .X()),
                                                   layerMap.PixelsToTilesHeight(endLocation
                                                                                .Y()), flag);
                     CollectionUtils.Put(pathCache, key, final_path);
                 }
                 pActorPath = new List <Vector2f>();
                 CollectionUtils.AddAll(final_path, pActorPath);
             }
         }
         else
         {
             pActorPath = Loon.Action.Map.AStarFinder.Find(heuristic, layerMap,
                                                           layerMap.PixelsToTilesWidth(startLocation.X()),
                                                           layerMap.PixelsToTilesHeight(startLocation.Y()),
                                                           layerMap.PixelsToTilesWidth(endLocation.X()),
                                                           layerMap.PixelsToTilesHeight(endLocation.Y()), flag);
         }
     }
 }