コード例 #1
0
// meme principe que canMoveR
bool Player::canMoveD(sf::IntRect hitBox) const {	
	
	int tile1x, tile1y, tile2x, tile2y;
	bool t1; 
	bool t2;
	sf::Vector2<float> center = getCenter(hitBox);
	sf::Vector2<int> tileBomb;
	list<Bomb*>::iterator ite_Bomb;
	tile1y = min(max(((int)(center.y - OFFSET_y)/TILE_Size)+1,0),9);
	tile2y = tile1y;
	tile1x = min(max(((int)(center.x -(OFFSET_x+(WIDTH_Hitbox/2))) / TILE_Size),0),9);
	tile2x = min(max(((int)(center.x -(OFFSET_x-(WIDTH_Hitbox/2))) / TILE_Size),0),9);
	if (tile1y < 10){
		if (tile2y==10) tile2y--;
		//cout << tile1y <<',' <<tile1x <<','<< tile2y<<','<< tile2x <<endl;
		char type1 = map_->getTile(tile1x, tile1y);
		char type2 = map_->getTile(tile2x, tile2y);
		// Verif Bombe
		for (ite_Bomb = map_->listBomb_->begin(); ite_Bomb != map_->listBomb_->end(); ++ite_Bomb) {		
				tileBomb = (*ite_Bomb)->getTile();
				if ((tileBomb.x == tile1x) && (tileBomb.y== tile1y)) type1 = 'Z';
				if ((tileBomb.x == tile2x )&& (tileBomb.y== tile2y)) type2 = 'Z';
		}
		if (((type1 == 'V')||(type1 == 'A')||(type1 == 'B')||(type1 == 'C')) && 
			((type2 == 'V')||(type2 == 'A')||(type2 == 'B')||(type2 == 'C'))) {												
			return true;
			
		}
		else {
		//cout <<OFFSET_x+TILE_Size*tile1x<<','<< OFFSET_y+TILE_Size*tile1y<<','<<OFFSET_x+TILE_Size*((tile1x)+1)<<','<<
							//OFFSET_y+TILE_Size*((tile1y)+1)<< endl;
		//cout <<hitBox.Left<<','<<hitBox.Top<<','<<hitBox.Right<<','<<hitBox.Bottom<<','<< endl;

			t1 = hitBox.Intersects(sf::IntRect(OFFSET_x+TILE_Size*tile1x,
							OFFSET_y+TILE_Size*tile1y,
							OFFSET_x+TILE_Size*((tile1x)+1),
							OFFSET_y+TILE_Size*((tile1y)+1)));
			t2 = hitBox.Intersects(sf::IntRect(OFFSET_x+TILE_Size*tile2x,
							OFFSET_y+TILE_Size*tile2y,
							OFFSET_x+TILE_Size*((tile2x)+1),
							OFFSET_y+TILE_Size*((tile2y)+1)));
		return !( t1 || t2);
				
		}
		
	}
	return true;
	
}
コード例 #2
0
bool Player::canMoveR(sf::IntRect hitBox) const {	
	
	int tile1x, tile1y, tile2x, tile2y;
	bool t1; 
	bool t2;
	sf::Vector2<float> center = getCenter(hitBox);
	sf::Vector2<int> tileBomb;
	list<Bomb*>::iterator ite_Bomb;
	// Recuperation des deux coordonnées des deux cases à droite
	tile1x = min(max(((int)(center.x - OFFSET_x)/TILE_Size)+1,0),9);
	tile2x = tile1x;
	tile1y = min(max(((int)(center.y -(OFFSET_y+(HEIGHT_Hitbox/2))) / TILE_Size),0),9);
	tile2y = min(max(((int)(center.y -(OFFSET_y-(HEIGHT_Hitbox/2))) / TILE_Size),0),9);
	// Traitement case
	if (tile1x < 10){
		if (tile2x==10) tile2x--;
		char type1 = map_->getTile(tile1x, tile1y);
		char type2 = map_->getTile(tile2x, tile2y);
		// Verif Bombe : collision 
		for (ite_Bomb = map_->listBomb_->begin(); ite_Bomb != map_->listBomb_->end(); ++ite_Bomb) {		
				tileBomb = (*ite_Bomb)->getTile();
				if ((tileBomb.x == tile1x) && (tileBomb.y== tile1y)) type1 = 'Z';
				if ((tileBomb.x == tile2x )&& (tileBomb.y== tile2y)) type2 = 'Z';
		}
		// Si on peut franchir la case -> go
		if (((type1 == 'V')||(type1 == 'A')||(type1 == 'B')||(type1 == 'C')) && 
			((type2 == 'V')||(type2 == 'A')||(type2 == 'B')||(type2 == 'C'))) {												
			return true;
			
		}
		else {	// si collision rocher ou foin
			t1 = hitBox.Intersects(sf::IntRect(OFFSET_x+TILE_Size*tile1x,
							OFFSET_y+TILE_Size*tile1y,
							OFFSET_x+TILE_Size*((tile1x)+1),
							OFFSET_y+TILE_Size*((tile1y)+1)));
			t2 = hitBox.Intersects(sf::IntRect(OFFSET_x+TILE_Size*tile2x,
							OFFSET_y+TILE_Size*tile2y,
							OFFSET_x+TILE_Size*((tile2x)+1),
							OFFSET_y+TILE_Size*((tile2y)+1)));
		return !( t1 || t2);
				
		}
		
	}
	return true;
	
}