コード例 #1
0
//Return list of Objects collided with at Position "where"
//Collisions only with solid objects
//Does not consider if p_o is solid or not.
ObjectList WorldManager::isCollision(Object *p_o, Position where) {
    Utility u;
    //Make empty list
    ObjectList collision_list;

    ObjectListIterator li = ObjectListIterator(&updates);
    li.first();
    while (!li.isDone()) {
        Object *p_temp_o = li.currentObject();

        if (p_temp_o != p_o) {
            //World position bounding box for object at where
            Box b = u.getWorldBox(p_o, where);

            //World position bounding box for other object
            Box b_temp = u.getWorldBox(p_temp_o);

            if (u.boxIntersectsBox(b, b_temp) && p_temp_o->isSolid()) {
                collision_list.insert(p_temp_o); //Add object because of collision
            } //No solid collision
        } //Object cannot collide with itself
        li.next();
    }//End while
    return collision_list;
}
コード例 #2
0
void WorldManager::draw() {
    ObjectList allObjects = getAllObjects();
    ObjectListIterator li = ObjectListIterator(&allObjects);
    Utility u = Utility();
    for (int alt = 0; alt <= MAX_ALTITUDE; alt++) {
        li.first();
        while (!li.isDone()) {
            if (li.currentObject()->getAltitude() == alt) {

                //Bounding box coordinates are relative to Object
                //so convert to world coordinates
                Box temp_box = u.getWorldBox(li.currentObject());
                if (u.boxIntersectsBox(temp_box, view)) {
                    li.currentObject()->draw();
                }
            }
            li.next();

        }
    }
}