当前位置: 首页>>代码示例>>C++>>正文


C++ Area::achou_caminho方法代码示例

本文整理汇总了C++中Area::achou_caminho方法的典型用法代码示例。如果您正苦于以下问题:C++ Area::achou_caminho方法的具体用法?C++ Area::achou_caminho怎么用?C++ Area::achou_caminho使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Area的用法示例。


在下文中一共展示了Area::achou_caminho方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: andando

void Monstro::andando() {
    //debug("La vai");
    //char str[200];

    int fator_larg = TILE_W;
    int fator_alt = TILE_H;
    int htiles = SCREEN_W / fator_larg;
    //int vtiles = SCREEN_H / fator_alt;

    int cx = this->x + (this->larg / 2);
    int cy = this->y + (this->alt / 2);
    int meu_x = cx / fator_larg;
    int meu_y = cy / fator_alt;
    int meu_vertice = meu_y * htiles + meu_x;

    int quero_vertice = (quero_x == -1 || quero_y == -1) ? -1 : quero_y * htiles + quero_x;
    int cqx = quero_x * fator_larg;
    int cqy = quero_y * fator_alt;

    /*sprintf(str, "Meu vertice eh %d, %d, %d e %d e meu destino eh %d",
            meu_vertice1, meu_vertice2, meu_vertice3, meu_vertice4, quero_vertice);
    debug(str);*/

    if (quero_vertice != -1 && meu_vertice != quero_vertice && (cqx != x || cqy != y)) {
        int mx = limitar(cqx - x, -2, 2);
        int my = limitar(cqy - y, -2, 2);
        mover(mx, my);
        return;
    }

    PathFinder *p = destinos();
    Area *a = (p == NULL ? NULL : new Area(meu_vertice, p->get_grid()));
    if (p != NULL) delete p;

    if (a == NULL || !a->achou_caminho()) {
        //debug("Sem destino");
        return;
    }

    std::list<int> caminho = a->caminho();
    std::list<int>::iterator it = caminho.begin();
    while (it != caminho.end() && *it == meu_vertice) {
        it++;
    }
    if (it == caminho.end()) {
        delete a;
        chegou();
        return;
    }
    int vertice_destino = *it;
    delete a;

    //sprintf(str, "Meu novo destino eh %d (x=%d, y=%d)", vertice_destino, vertice_destino % htiles, vertice_destino / htiles);
    //debug(str);

    quero_x = vertice_destino % htiles;
    quero_y = vertice_destino / htiles;
    int delta_x = limitar((quero_x * fator_larg) - x, -2, 2);
    int delta_y = limitar((quero_y * fator_alt) - y, -2, 2);

    if (!mover(delta_x, delta_y)) {
        quero_x = meu_x;
        quero_y = meu_y;
    }
}
开发者ID:amarillion,项目名称:TINS-Is-not-speedhack-2010,代码行数:65,代码来源:monstro.cpp


注:本文中的Area::achou_caminho方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。