Exemple #1
0
bool BlockMur::ToGrille(void)
{
	grille *Grille	= grille::getInstance();
	carte *Carte	= carte::getInstance();

	Coordonnees pos;
	int nbCheckOK = 0;
	int i=0;

	// on check si tous les mur sont dans une zone libre et sur la terre
	for(i=0;i<this->_nbMur;i++)
	{
		pos.Set(this->_Mur[i]->getSprite().GetPosition().x,this->_Mur[i]->getSprite().GetPosition().y);

		if(Carte->getElement(pos) == 1 && Grille->isFree(pos, 0))
		{
			nbCheckOK++;
		}
	}

	if(nbCheckOK == this->_nbMur)
	{
		nbCheckOK = 0;

		for(i=0;i<this->_nbMur;i++)
		{
			pos.Set(this->_Mur[i]->getSprite().GetPosition().x,this->_Mur[i]->getSprite().GetPosition().y);

			if(Grille->add(pos,this->_Mur[i]))
			{
				nbCheckOK++;
			}
		}

		if(nbCheckOK == this->_nbMur) return true;
	}

	return false;
}
Exemple #2
0
void BlockMur::SetPosition(int x, int y)
{
	int tmpX = x; 
	int tmpY = y;
	Coordonnees pos;

	grille *Grille = grille::getInstance();
	carte *Carte	= carte::getInstance();

	// deplace les mur en fonction de la position precedente du mur 1
	for(int i=0;i<this->_nbMur;i++)
	{
		if(i > 0)
		{
			tmpX = this->_Mur[i]->getSprite().GetPosition().x - this->prevX + x;
			tmpY = this->_Mur[i]->getSprite().GetPosition().y - this->prevY + y;
		}

		pos.Set(tmpX,tmpY);
		
		this->_Mur[i]->SetPosition(tmpX,tmpY);
				
		if( ( Carte->getElement(pos) != 1 || !Grille->isFree(pos, 0) ) && !this->_Mur[i]->getColor() )
		{
			// position mur interdit, on color en rouge
			this->_Mur[i]->setColor(true);
		}
		else if(Carte->getElement(pos) == 1 && Grille->isFree(pos, 0) && this->_Mur[i]->getColor())
		{
			// position mur ok
			this->_Mur[i]->setColor(false);
		}

	}

	// Sauvegarde la nouvelle position du mur 1
	this->prevX = x;
	this->prevY = y;
}