예제 #1
0
//Update world
void WorldManager::update() {
    LogManager &l_m = LogManager::getInstance();
    ObjectList allObjects = getAllObjects();
    ObjectListIterator li = ObjectListIterator(&allObjects);


    //Move objects with Velocity
    li.first();
    while (!li.isDone()) {
        int x = li.currentObject()->getXVelocityStep();
        int y = li.currentObject()->getYVelocityStep();

        if (x != 0 || y != 0) {
            Position old_position = li.currentObject()->getPos();
            Position new_position = Position(old_position.getX() + x, old_position.getY() + y);
            moveObject(li.currentObject(), new_position);
            l_m.writeLog("Object moved");
        }
        li.next();
    }

    li.setList(&deletions);

    //Delete all marked objects
    li.first();
    while (!li.isDone()) {
        l_m.writeLog("updating object %d", li.currentObject()->getId());
        delete(li.currentObject());
        li.next();
    }
    //clear list for next update phase
    deletions.clear();
}
예제 #2
0
//Set view to center window on Object
//Set to NULL to stop following
//Return -1 on failure;
int WorldManager::setViewFollowing(Object *p_new_view_following) {
    LogManager &l_m = LogManager::getInstance();
    bool found = false;
    //set to null to turn 'off' following

    if (p_new_view_following == NULL) {
        p_view_following = NULL;
    }

    ObjectListIterator li = ObjectListIterator(&updates);

    //Delete all marked objects
    li.first();
    while (!li.isDone()) {
        if (li.currentObject() == p_new_view_following)
            found = true;
        li.next();
    }
    if (!found) {
        l_m.writeLog("WorldManager::SetViewFollowing() ERROR! Object not found.");
        return -1;
    }
    p_view_following = p_new_view_following;
    l_m.writeLog("p_new_view_following = %d", p_new_view_following->getId());
    setViewPosition(p_view_following->getPos());
    return 0;
}
예제 #3
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;
}
예제 #4
0
Adventurer* PartyManager::getPartyMember(string name){
	ObjectListIterator oli = ObjectListIterator(&party);

	for(oli.first(); !oli.isDone(); oli.next()){
		Adventurer* a = (Adventurer *) oli.getCurrent();
		if(a->getName() == name){
			return a;
		}
	}

	Adventurer* empty;
	return empty;
}
예제 #5
0
/*
ask all objects to draw themselvs
*/
void WorldManager::draw(){

	ObjectListIterator *li = new ObjectListIterator(&updates);
	//for loop that enforeces drawing by alttitude
	for (int alt = 0; alt < MAX_ALTTITUDE; alt++){
		while (!li->isDone()){	
			if (li->currentObject()->getAltitude() == alt){
				Object tmp_obj = *li->currentObject();
				li->currentObject()->draw();
			}
			li->next();
		}
		li->first();
	}
}
예제 #6
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();

        }
    }
}
예제 #7
0
//Move Object
//If no collision with solid, move okay, else don't move
//If p_o is Spectral, move ok.
//Return 0 if move ok, else -1 if collision is solid
int WorldManager::moveObject(Object *p_o, Position where) {
    if (p_o->isSolid()) { //Need to be solid for collisions
        //Get Collisions
        ObjectList list = isCollision(p_o, where);

        if (!list.isEmpty()) {
            boolean do_move = true;  //Assume we can move

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

                //Create Collision event
                EventCollision c(p_o, p_temp_o, where);

                //Send to both objects
                p_o->eventHandler(&c);
                p_temp_o->eventHandler(&c);

                //If both Hard, then cannot move
                if (p_o->getSolidness() == HARD && p_temp_o->getSolidness() == HARD)
                    do_move = false; //Can't move
                //If object won't move onto soft objects, check for that
                if (p_o->getNoSoft() && p_temp_o->getSolidness() == SOFT)
                    do_move = false;

                li.next();
            } //End while
            if (do_move == false)
                return -1;
        }
    }

    //Get world bounds
    GraphicsManager &gp_m = GraphicsManager::getInstance();
    int maxHori = boundary.getHorizontal();
    int maxVert = boundary.getVertical();

    //Check if object is moving out of world
    if ((p_o->getPos().getX() > 0)
            && (p_o->getPos().getX() < maxHori) // X is within bounds  AND
            && (p_o->getPos().getY() > 0)
            && (p_o->getPos().getY() < maxVert) //Y is within bounds AND
            &&
            (where.getX() < 0
             || where.getX() > maxHori
             || where.getY() < 0
             || where.getY() > maxVert)) //Any part of new location is out of bounds
    {
        EventOut ov = EventOut();
        p_o->eventHandler(&ov);
    }
    //No collision between 2 hard objects, so move object
    p_o->setPos(where);

    if (p_view_following == p_o)
        setViewPosition(p_o->getPos());

    return 0;
}