void ProjectileManager::update(const float& delta, TankManager* tankMgr){
	for (std::set<Projectile*>::iterator it = projectiles.begin();it != projectiles.end();)
	{
		(*it)->update(delta, gravityValue);
		
		//check if Projectile hit anything
		Ogre::Vector3 explosionCtr = (*it)->particleSn->_getDerivedPosition();
		explosionSphere.setCenter(explosionCtr);
		Ogre::SphereSceneQuery* ssq = mSceneMgr->createSphereQuery(explosionSphere, Ogre::SceneManager::ENTITY_TYPE_MASK);
		Ogre::SceneQueryResult& result = ssq->execute();
		
		//projectile hit something
		if (result.movables.size() > 0 || explosionCtr.y < 0.5f) //if projectile hit some tank or is just above ground
		{
			Ogre::SceneQueryResultMovableList::iterator sqrItr;
			for (sqrItr = result.movables.begin(); sqrItr != result.movables.end(); ++sqrItr){
				//if tank, minus health based on the distance from the explosion center
				tankMgr->checkTankExplosion((*sqrItr)->getParentSceneNode(), explosionCtr, (*it)->dmg);
			}

			createExplosion(explosionCtr);

			destroyProjectile(*it);
			it = projectiles.erase(it); //erase projectile and get new iterator
		} else{
			++it;
		}
		
		mSceneMgr->destroyQuery(ssq);	
	}

	for (std::set<Explosion*>::iterator it = explosions.begin(); it != explosions.end();)
	{
		(*it)->existedTime += delta;

		if ((*it)->existedTime > (*it)->timeLimit)
		{
			destroyExplosion((*it));
			it = explosions.erase(it);
		} else{
			it++;
		}
	}
}
Example #2
0
bool grenade::checkCollide(float & velX, float & velY, float elapsedTime)
{
	sf::Rect<float> proj_rect	(	this->GetPosition().x + velX*elapsedTime, 
									this->GetPosition().y + velY*elapsedTime,
									this->GetWidth(),
									this->GetHeight() 
								);

	sf::ConvexShape trueRect = this->getTrueRect();

	// check out of screen bounds
	if(  proj_rect.left < 0 ||
		 (proj_rect.left + proj_rect.width) > Game::mapWidth*Game::GRID_WIDTH ||
		 proj_rect.top < 0 ||
		 (proj_rect.top + proj_rect.height) > Game::mapHeight*Game::GRID_HEIGHT 
	  )
	{
			destroyProjectile();
			return true;
	}


	// check collide with other player
	for(std::map<int,peer*>::iterator it = multiplayer::allPeers.begin(); it !=  multiplayer::allPeers.end(); ++it)
	{
		if(  this->isIntersecting(*it->second->hisPlayer) && 
			 ownerPlayerNum != it->second->hisPlayer->getPlayerNum()  && 
			 !it->second->hisPlayer->getIsRespawning()  )
		{
				destroyProjectile();
				return true;
		}
	}



	float maxX = trueRect.getPoint(0).x;
	float maxY = trueRect.getPoint(0).y;
	float minX = maxX;
	float minY = maxY;
	for (unsigned int i=1; i<trueRect.getPointCount(); i++)
	{
		sf::Vector2f point = trueRect.getPoint(i);

		if(point.x > maxX)
			maxX = point.x;

		if(point.y > maxY)
			maxY = point.y;

		if(point.x < minX)
			minX = point.x;

		if(point.y < minY)
			minY = point.y;
	}


	int i_left;
	int j_top;
	int i_right;
	int j_bottom;

	i_left =   (int) floor(minX / Game::GRID_WIDTH);
	j_top =    (int) floor(minY / Game::GRID_HEIGHT);
	i_right =  (int) floor(maxX / Game::GRID_WIDTH);
	j_bottom = (int) floor(maxY / Game::GRID_HEIGHT);

	if (i_left < 0)
		i_left = 0;
	if (i_left >= Game::mapWidth)
		i_left = Game::mapWidth-1;

	if (i_right < 0)
		i_right = 0;
	if (i_right >= Game::mapWidth)
		i_right = Game::mapWidth-1;

	if (j_top < 0)
		j_top = 0;
	if (j_top >= Game::mapHeight)
		j_top = Game::mapHeight-1;

	if (j_bottom < 0)
		j_bottom = 0;
	if (j_bottom >= Game::mapHeight)
		j_bottom = Game::mapHeight-1;

	int i;
	int j;
	for(i = i_left; i <= i_right; i++)
	{
		for(j = j_top; j <= j_bottom; j++)
		{
			if( Game::gameGrid[i][j].getCollide() )
			{
				if( this->isIntersecting (Game::gameGrid[i][j]) )
				{
					destroyProjectile();
					return true;
				}
			}
		}
	}

	return false;
}
Example #3
0
// Destroi um objeto Celula
void destroyCelula (Celula *cel) {
    if (cel == NULL) return;

    destroyProjectile (cel->proj);
    free (cel);
}