Ejemplo n.º 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;
}
Ejemplo n.º 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;
}
Ejemplo n.º 3
0
/*
Move the object pointed to to postion where(in asc11 spaces)
*/
int WorldManager::moveObject(Object *p_o, Position where){
	GraphicsManager &graphics_manager = GraphicsManager::getInstance();

	if (p_o->isSolid()){ //collisions only matter for solid objects
		bool doMove = true;
		//Get collisions
		ObjectList list = isCollision(p_o, where);
		//if we have collided with something
		if (!list.isEmpty()){
			
			//Itereate accross list
			ObjectListIterator li = ObjectListIterator(&list);
			while (!li.isDone()){
				Object *p_temp_o = li.currentObject();

				//Create collision event
				EventCollision collision(p_o, p_temp_o, where);

				//send to both objects
				p_o->eventHandler(&collision);
				p_temp_o->eventHandler(&collision);

				//if both objects are hard move fails
				if (p_o->getSolidness() == HARD && p_temp_o->getSolidness() == HARD){
					doMove = false;
				}


				li.next();
			}// end iterator while

			if (!doMove){
				return -1;
			}

		}// end list is not empty ( no collision
	}//Object not solid



	p_o->setPosition(where);


	//Check to see if moving out of bounds
	if (where.getX() < 0
		|| (where.getX() >= graphics_manager.getHorizontal())
		|| where.getY() < 0
		|| (where.getY() >= graphics_manager.getVertical())){
		EventOut ov = EventOut();
		p_o->eventHandler(&ov);
	}

	return 0;
}
Ejemplo n.º 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;
}
Ejemplo n.º 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();
	}
}
Ejemplo n.º 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();

        }
    }
}
Ejemplo n.º 7
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();
}
Ejemplo n.º 8
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;
}