Example #1
0
void Laser::checkWorldPosition()
{
    //Remove laser shoot in case if it out game world
    if (endPoint_.x < -worldWidth_/2 || endPoint_.x >= worldWidth_/2 ||
        endPoint_.y < -worldHeight_/2 || endPoint_.y >= worldHeight_/2)
        setCollision();
}
Example #2
0
/**
 * Builds a new massObject and assigns it to a spriteManager.
 * 
 * @param	newsm	the spriteManager which should be responsible for updating and deleting this sprite
 */
massObject::massObject(spriteManager* newsm)
	: spriteObject(newsm), grounded(false), wasGrounded(false), bStasis(false)
{
	#ifdef __MDDEBUG
	className = "massObject";
	macros::debugMessage(className, "constructor");
	#endif
	setCollision(COL_SOLID);
	setCheckCollision(true);
}
Example #3
0
wp_gren_proj::wp_gren_proj(spriteManager* newsm, Player* p) : massObject(newsm), owner(p)
{
	#ifdef __MDDEBUG
	className = "wp_gren_proj";
	macros::debugMessage(className, "constructor");
	#endif
	gameManager* gm = dynamic_cast<gameManager*>(sm);
	setPallete(gm->pickupSprite.palleteID);
	//GFX warning!
	giveSprite(gm->pickupSprite.spriteData, OBJ_SIZE_16X16, 8, 8, 60);
	setBounds(2, 2, 5, -1);
	setAnim(26, 27, ANIMSPEED);
	setCollision(COL_SOLID);
	setCheckCollision(true);
	setLayer(2);
}
Example #4
0
wp_net_proj::wp_net_proj(spriteManager* newsm, Player* p) : spriteObject(newsm), owner(p)
{
	#ifdef __MDDEBUG
	className = "wp_net_proj";
	macros::debugMessage(className, "constructor");
	#endif
	gameManager *gm = dynamic_cast<gameManager*>(sm);
	setPallete(gm->FXSprite.palleteID);
	//GFX warning!
	giveSprite(gm->FXSprite.spriteData, OBJ_SIZE_32X32, 16, 16, 60);
	setBounds(-8, 8, 6, -8);
	setFrame(32);
	setCollision(COL_SOLID);
	setLayer(2);
	owner->setIgnored(this);
}
Example #5
0
wp_boomerang_proj::wp_boomerang_proj(spriteManager* newsm, Player* p, wp_boomerang* w) :
	spriteObject(newsm), weapon(w), owner(p), bReturning(false), returnx(0), returny(0)
{
	#ifdef __MDDEBUG
	className = "wp_boomerang_proj";
	macros::debugMessage(className, "constructor");
	#endif
	gameManager *gm = dynamic_cast<gameManager *>(sm);
	setPallete(gm->pickupSprite.palleteID);
	//GFX warning!
	giveSprite(gm->pickupSprite.spriteData, OBJ_SIZE_16X16, 8, 8, 60);
	setBounds(-2, 3, 3, -2);
	setAnim(20, 23, ANIMSPEED);
	setCollision(COL_SOLID);
	setLayer(2);
	#ifdef __WITHSOUND
	playSound(&gm->boomerangLoop, true);
	#endif
}
Example #6
0
void sweepPrune()
{

    std::multimap<float, int> orderedlist_x, orderedlist_y, orderedlist_z;
    //get through cubes
    for( int i=0; i<collection.size(); i++){
        orderedlist_x.insert(pair<float,int>(collection.at(i).box.min.x, i));
        orderedlist_x.insert(pair<float,int>(collection.at(i).box.max.x, i));

        orderedlist_y.insert(pair<float,int>(collection.at(i).box.min.y, i));
        orderedlist_y.insert(pair<float,int>(collection.at(i).box.max.y, i));

        orderedlist_z.insert(pair<float,int>(collection.at(i).box.min.z, i));
        orderedlist_z.insert(pair<float,int>(collection.at(i).box.max.z, i));
    }

    //bit vectors for active lists
    std::vector<int> activelist_x(collection.size()),
                     activelist_y(collection.size()),
                     activelist_z(collection.size());

    activelist_x.clear();
    activelist_y.clear();
    activelist_z.clear();

    std::multimap<int,int> paired_x, paired_y, paired_z;

    //Reminder: i runs through all the (discrete,as fixed and a priori known) values on axis.
    //          list_x[i] returns the cube corresponding to the position (hence it goes only from 1 to collection.size)

    //X
    for( std::multimap<float,int>::iterator ii = orderedlist_x.begin() ; ii != orderedlist_x.end() ; ii++ ){
        if ( (*ii).first == collection.at((*ii).second).getAABBMin().x ){ //STARTPOINT
            activelist_x.push_back( (*ii).second );
            //std::cout<<"X"<<std::endl;
            //printActives(activelist_x);
            checkPair(activelist_x, paired_x);
        }
        else { //ENDPOINT
            std::vector<int>::iterator del =  std::find(activelist_x.begin(), activelist_x.end(), ((*ii).second) );
            if(del != activelist_x.end()) activelist_x.erase(del);
        }
    }

    //collision_x.at((*ii).second) == 0 ? collision_x.at((*ii).second) ++ : collision_x.at((*ii).second) --;

    //Y
    for( std::multimap<float,int>::iterator ii = orderedlist_y.begin() ; ii != orderedlist_y.end() ; ii++ ){
        if ( (*ii).first == collection.at((*ii).second).getAABBMin().y ){ //STARTPOINT
            activelist_y.push_back( (*ii).second );
            //std::cout<<"Y"<<std::endl;
            //printActives(activelist_y);
            checkPair(activelist_y, paired_y);
        }
        else { //ENDPOINT
            std::vector<int>::iterator del =  std::find(activelist_y.begin(), activelist_y.end(), ((*ii).second) );
            if(del != activelist_y.end()) activelist_y.erase(del);
        }
    }

    //Z
    for( std::multimap<float,int>::iterator ii = orderedlist_z.begin() ; ii != orderedlist_z.end() ; ii++ ){
        if ( (*ii).first == collection.at((*ii).second).getAABBMin().z ){ //STARTPOINT
            activelist_z.push_back( (*ii).second );
            //std::cout<<"Z"<<std::endl;
            //printActives(activelist_z);
            checkPair(activelist_z, paired_z);
        }
        else { //ENDPOINT
            std::vector<int>::iterator del =  std::find(activelist_z.begin(), activelist_z.end(), ((*ii).second) );
            if(del != activelist_z.end()) activelist_z.erase(del);
        }
    }


    for(int i=0 ; i< collection.size(); i++)
            setCollision(i, false);


    std::multimap<int,int> book;


    std::multimap<int,int>::iterator found = paired_y.end();
    for( std::multimap<int,int>::iterator ix = paired_x.begin(); ix != paired_x.end(); ix++ )
        found = std::find(paired_y.begin(), paired_y.end(), *ix);

    if(found != paired_y.end()) std::cout << (*found).first << std::endl;


    for( std::multimap<int,int>::iterator ix = paired_x.begin(); ix != paired_x.end(); ix++ )
        for(std::multimap<int,int>::iterator iy = paired_y.begin();iy != paired_y.end(); iy++)
            for(std::multimap<int,int>::iterator iz = paired_z.begin();iz != paired_z.end();iz++ )
                if( equals( (*ix) , (*iy) ) && equals( (*iy), (*iz) ) ) {
                    setCollision( (*ix).first, true );
                    setCollision( (*ix).second,true );
                    book.insert( pair<int,int> ( (*ix).first, (*ix).second )); //nb: I have a "2 collides with 1". should I also include "1 collides with 2"?
                }

    for(std::multimap<int,int>::iterator it=book.begin(); it!=book.end(); it++)
        std::cout << "Body " << (*it).first << " colliding with " << (*it).second << std::endl;
}
Example #7
0
BasicMesh* MeshManager::loadMesh(const std::string& fileName, const std::string meshName)
{
	shared_ptr<GameFile> file = GameFile::openFile(fileName, "r");
	std::string readLine;
	BasicMesh* result = new BasicMesh();
	std::string collisionLine;

	while(!(file->eof()))
	{
		readLine = file->readLine();
		if(readLine.size() == 0 || readLine == "\n")
		{
			continue;
		}
		if(readLine.find(NAME_SECTION) == 0)
		{
			loadName(result, readLine);
			continue;
		}
		else if(readLine.find(VERTICES_SECTION) == 0)
		{
			loadVertices(result, readLine, file.get());
			continue;
		}
		else if(readLine.find(UVS_SECTION) == 0)
		{
			loadUvs(result, readLine, file.get());
			continue;
		}
		else if(readLine.find(NORMALS_SECTION) == 0)
		{
			loadNormals(result, readLine, file.get());
			continue;
		}
		else if(readLine.find(INDICES_SECTION) == 0)
		{
			loadIndices(result, readLine, file.get());
			continue;
		}
		else if(readLine.find(COLLISION_SECTION) == 0)
		{
			collisionLine = readLine; // it has to be calculated after all the geometry
			continue;
		}
		else
		{
			Log("Skipping unknown line in mesh file - %s", readLine.c_str());
		}
	}

	if(collisionLine.size() != 0)
	{
		setCollision(result, collisionLine);
	}
	else
	{
		// by default create box collision
		result->setCollisionType(CS_BOX);
		result->m_collisionShape = createCollisionShape(result);
	}

	return result;
}