Example #1
0
void Player::CheckCollisionWith(Player* iSecond)
{
	Projectile* first = NULL; 
	Projectile* second = NULL;

	for(int i=0; i<mProjectiles.size(); ++i)
	{
		first = mProjectiles[i];
		bool collision = false;
		for(int j=0; j<iSecond->GetProjectilesSize() && !collision; ++j)
		{
			second = iSecond->GetProjectileAt(j);
			if(Distance(first->GetPos(), second->GetPos()) < first->GetRadius() + second->GetRadius())
			{
				//Collision: for the moment remove
				if((mID != iSecond->GetID()))
				{
					collision = true;
					RemoveProjectileAt(i);
					iSecond->RemoveProjectileAt(j);
					--i;
					--j;
				}
				else if(mID == iSecond->GetID() && i != j)
				{
					collision = true;
					RemoveProjectileAt(i);
					//////////////// NB: in this case first and second ARE the same player.
					// Then we are removing TWO bullets of his.
					// If we remove first bullet at index i, with i>j:
					//
					// Before erase
					// [][][][][j][][][i] 
					// 
					// After erase
					// [][][][][j][][]   -----------> projectile after erase has still got index "j"
					//
					//
					// If index  i<j:
					// 
					// Before erase
					// [][i][][j]
					//
					// After erase
					// [][][j]         -----------> projectile after erase has got index "j - 1"


					if(i>j)
						iSecond->RemoveProjectileAt(j);
					else
						iSecond->RemoveProjectileAt(j-1);
				}
			}

		}

	}

}
Example #2
0
void Projectile::Add(Body *parent, Equip::Type type, const vector3d &pos, const vector3d &baseVel, const vector3d &dirVel)
{
	Projectile *p = new Projectile();
	p->m_parent = parent;
	p->m_type = Equip::types[type].tableIndex;
	p->SetFrame(parent->GetFrame());
	
	parent->GetRotMatrix(p->m_orient);
	p->SetPosition(pos);
	p->m_baseVel = baseVel;
	p->m_dirVel = dirVel;
	p->m_radius = p->GetRadius();
	Pi::game->GetSpace()->AddBody(p);
}