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


C++ WorldObject::getsurface方法代码示例

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


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

示例1: perform_collision_bullet

void CollisionManager::perform_collision_bullet(vector<WorldObject*> victims,
        vector<Projectile*> bullets) {
    vector<WorldObject*>::iterator victims_it;
    vector<Projectile*>::iterator bullets_it;

    if (bullets.size() < 1) {
        return;
    }

    if (victims.size() < 1) {
        return;
    }

    for (victims_it = victims.begin(); victims_it != victims.end(); victims_it++) {
        WorldObject* victim = (*victims_it);

        if (!victim->getcollisionable()) {
            continue;
        }

        // check collision for each bullet
        for (bullets_it = bullets.begin(); bullets_it != bullets.end(); bullets_it++) {
            Projectile* bullet = (*bullets_it);

            if ((bullet->getx() >= (victim->getx() - MAX_DISTANCE_FOR_COLLISION))
                    && (bullet->gety() >= (victim->gety() - MAX_DISTANCE_FOR_COLLISION))) {

                int bullet_min_x = bullet->getx();
                int bullet_min_y = bullet->gety();
                int bullet_max_x = bullet->getx() + bullet->getwidth();
                int bullet_max_y = bullet->gety() + bullet->getheight();

                int victim_min_x = victim->getx();
                int victim_min_y = victim->gety();
                int victim_max_x = victim->getx() + victim->getsurface()->w;
                int victim_max_y = victim->gety() + victim->getsurface()->h;

                if (((bullet_max_x > victim_min_x) &&
                        (bullet_max_y > victim_min_y) &&
                        (bullet_min_x < victim_max_x) &&
                        (bullet_min_y < victim_max_y)) ||
                        (bullet_min_x < 0 ||
                         bullet_max_x > DrawEngine::get_screen_width() ||
                         bullet_min_y < 0 ||
                         bullet_max_y > DrawEngine::get_screen_height())) {

                    // remove the bullet
                    GarbageCollector::add_deletion_queue(bullet);
                }
            }

            if ((bullet->getx() > (bullet->getorgx() + 300)) ||
                    (bullet->gety() > (bullet->getorgy() + 300))) {
                // if the bullet has been fired over 300 px, lets delete
                GarbageCollector::add_deletion_queue(bullet);
            }
        }
    }
}
开发者ID:seivan,项目名称:zombie_cpp_sdl,代码行数:59,代码来源:CollisionManager.cpp

示例2: perform_collision_detection

KeyAction* CollisionManager::perform_collision_detection(
    vector<WorldObject*> victims, MovableObject* ai, KeyAction* key_action) {
    vector<WorldObject*>::iterator it;

    // loop through all objects in the world, and detect a collision (if one exists)
    for (it = victims.begin(); it != victims.end(); it++) {
        WorldObject* victim = *it;

        if (!victim->getcollisionable())
            continue;

        if (((ai->getx() >= (victim->getx() - MAX_DISTANCE_FOR_COLLISION))
                && (ai->gety() >= (victim->gety() - MAX_DISTANCE_FOR_COLLISION)))
                || (ai->getx() < 0)
                || (ai->gety() < 0)
                || ((ai->getx() + ai->getsurface()->w) > DrawEngine::get_screen_width())
                || ((ai->gety() + ai->getsurface()->h) > DrawEngine::get_screen_height())) {

            // get the size and position of victim
            int victim_height = victim->getsurface()->h;
            int victim_width = victim->getsurface()->w;

            int victim_max_x = victim->getx() + victim_width;
            int victim_max_y = victim->gety() + victim_height;

            int ai_min_x = ai->getx();
            int ai_min_y = ai->gety();
            int ai_max_x = ai->getx() + ai->getsurface()->w;
            int ai_max_y = ai->gety() + ai->getsurface()->h;

            if ((((ai_max_x > victim->getx())
                    && (ai_min_x < victim_max_x)
                    && (ai_max_y > victim->gety())
                    && (ai_min_y < victim_max_y)))
                    || ((ai_min_x < 0)
                        || (ai_max_x > DrawEngine::get_screen_width())
                        || (ai_min_y < 0)
                        || (ai_max_y > DrawEngine::get_screen_height()))) {

                // we have a collision
                if ((((ai_max_x > (victim->getx() + ai->getmovespeed()))
                        && ((ai_min_y < (victim_max_y - ai->getmovespeed()))
                            && (ai_max_y > (victim->gety() + ai->getmovespeed())))))
                        || (ai_min_x < 0)) {
                    key_action->player_direction &= ~KeyAction::LEFT;
                }

                if (((ai_max_x >= victim->getx()
                        && (ai_min_x < (victim_max_x - ai->getmovespeed()))
                        && (ai_min_y < (victim_max_y - ai->getmovespeed())
                            && (ai_max_y > (victim->gety() + ai->getmovespeed())))))
                        ||(ai_max_x > DrawEngine::get_screen_width())) {
                    key_action->player_direction &= ~KeyAction::RIGHT;
                }

                if (((ai_min_y < victim_max_y
                        && (ai_min_y > victim->gety())
                        && (ai_min_x < (victim_max_x - ai->getmovespeed())
                            && (ai_max_x > (victim->getx() + ai->getmovespeed())))))
                        || (ai_min_y < 0)) {
                    key_action->player_direction &= ~KeyAction::UP;
                }

                if (((ai_max_y > victim->gety()
                        && (ai_min_y < (victim_max_y - ai->getmovespeed()))
                        && (ai_min_x < (victim_max_x - ai->getmovespeed())
                            && (ai_max_x > (victim->getx() + ai->getmovespeed())))))
                        || (ai_max_y > DrawEngine::get_screen_height())) {
                    key_action->player_direction &= ~KeyAction::DOWN;
                }
            }
        }

        victim = NULL;
    }

    return key_action;
}
开发者ID:seivan,项目名称:zombie_cpp_sdl,代码行数:78,代码来源:CollisionManager.cpp


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