Пример #1
0
    /// <summary>
    /// 获取离自身最近的墙对象(炸弹人用)
    /// </summary>
    /// <param name="self"></param>
    /// <returns></returns>
    public TileEntity GetWallEntityNearest(TileEntity self)
    {
        var allEntities = IsoMap.Instance.GetAllEntitiesByOwner(self.GetTargetOwner());

        int        selfx   = self.GetTilePos().x;
        int        selfy   = self.GetTilePos().y;
        int        mindiff = 999999;
        TileEntity target  = null;

        foreach (var entity in allEntities)
        {
            if (entity.IsDead())
            {
                continue;
            }

            if (entity.entityType == EntityType.Wall)
            {
                Vector2 c    = entity.GetCurrentPositionCenter();
                int     x    = (int)c.x;
                int     y    = (int)c.y;
                int     diff = Math.Abs(selfx - x) + Math.Abs(selfy - y);
                if (diff <= mindiff)
                {
                    mindiff = diff;
                    target  = entity;
                }
            }
        }

        return(target);
    }