示例#1
0
文件: Chunk.cpp 项目: treeman/Sat-E
void Chunk::Draw( Vec2i offset, sf::IntRect visible )
{
    // Draw stars
    for( size_t i = 0; i < stars.size(); ++i ) {
        const Vec2i &pos = stars[i].GetPos();
        if( visible.Contains( pos.x, pos.y ) ) {
            stars[i].Draw( offset );
        }
    }

    // Draw items
    for( size_t i = 0; i < items.size(); ++i ) {
        const Vec2i &pos = items[i]->GetPos();
        if( visible.Contains( pos.x, pos.y ) ) {
            items[i]->Draw( offset );
        }
    }

    // Draw outlines
    if( SETTINGS->GetValue<bool>( "bounding_box_show" ) ) {
        for( Items::iterator it = items.begin(); it != items.end(); ++it ) {
            const Vec2i &pos = (*it)->GetPos();
            if( visible.Contains( pos.x, pos.y ) ) {
                draw_outline( (*it)->BoundingBox(), offset );
            }
        }
    }
}
// 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;
	
}
示例#3
0
	void UpdateCamera()
	{
		
		CameraFocusRect.width = Camera.width * CameraFocus;
		CameraFocusRect.height = Camera.height * CameraFocus;
		CameraFocusRect.left = ((1 - CameraFocus) * Camera.width) / 2;
		CameraFocusRect.top = ((1 - CameraFocus) * Camera.height) / 2;

		if (!CameraFocusRect.contains(Player1.Center()))
		{
			if (Player1.Center().x < CameraFocusRect.left)
				Camera.left -= CameraFocusRect.left - Player1.Center().x;
			if (Player1.Center().x > (CameraFocusRect.left + CameraFocusRect.width))
				Camera.left += Player1.Center().x - (CameraFocusRect.left + CameraFocusRect.width);
			if (Player1.Center().y < CameraFocusRect.top)
				Camera.top -= CameraFocusRect.top - Player1.Center().y;
			if (Player1.Center().y >(CameraFocusRect.top + CameraFocusRect.height))
				Camera.top += Player1.Center().y - (CameraFocusRect.top + CameraFocusRect.height);
		}

		if (Camera.left < 0)
			Camera.left = 0;
		if (Camera.top < 0)
			Camera.top = 0;
		if ((Camera.left + Camera.width) > (tiles[0].size() * 64))
			Camera.left = (tiles[0].size() * 64) - Camera.width;
		if ((Camera.top + Camera.height) > (tiles[0].size() * 64))
			Camera.top = (tiles[0].size() * 64) - Camera.height;
	}
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;
	
}
示例#5
0
	bool TestPlatCollision(sf::IntRect rect)
	{
		for (int i = 0; i < tiles.size(); i++)
			for (int j = 0; j < tiles[i].size(); j++)
				if (rect.intersects(tiles[i][j]->Rect()) && tiles[i][j]->IsSolid)
					return true;
		return false;
	}
示例#6
0
void ButtonMenu::onClickListener(GameState::GameStates &state, sf::IntRect rect){
	for(int i = 0; i < m_buttons.size(); i++){
		if(rect.intersects(m_buttons[i]->getButtonRect())){
			state = m_buttons[i]->getGameState();
		}else{
			m_buttons[i]->setColor(sf::Color::Blue);
		}
	}
}
示例#7
0
void ButtonMenu::mouseOver(sf::IntRect rect){

	for(int i = 0; i < m_buttons.size(); i++){
		if(rect.intersects(m_buttons[i]->getButtonRect())){
			m_buttons[i]->setColor(sf::Color::Magenta);
		}else{
			m_buttons[i]->setColor(sf::Color::Blue);
		}
	}
}
示例#8
0
bool MouseHandler::IsOver(sf::IntRect rect)
{
	if(rect.contains(MousePosition.x, MousePosition.y)){
		return true;
	}
	else
	{
		return false;
	}
}
示例#9
0
  sf::IntRect ParseIntRect(const std::string theValue, const sf::IntRect theDefault)
  {
    sf::IntRect anResult = theDefault;

    // Try to find the first comma
    size_t anComma1Offset = theValue.find_first_of(',');
    if(anComma1Offset != std::string::npos)
    {
#if (SFML_VERSION_MAJOR < 2)
      sf::Int32 anLeft = ParseInt32(theValue.substr(0,anComma1Offset), theDefault.Left);
#else
      sf::Int32 anLeft = ParseInt32(theValue.substr(0,anComma1Offset), theDefault.left);
#endif
      // Try to find the next comma
      size_t anComma2Offset = theValue.find_first_of(',',anComma1Offset+1);
      if(anComma2Offset != std::string::npos)
      {
#if (SFML_VERSION_MAJOR < 2)
        sf::Int32 anTop = ParseInt32(theValue.substr(anComma1Offset+1,anComma2Offset), theDefault.Top);
#else
        sf::Int32 anTop = ParseInt32(theValue.substr(anComma1Offset+1,anComma2Offset), theDefault.top);
#endif
        // Try to find the next comma
        size_t anComma3Offset = theValue.find_first_of(',',anComma2Offset+1);
        if(anComma3Offset != std::string::npos)
        {
#if (SFML_VERSION_MAJOR < 2)
          // Get the width and height values
          sf::Int32 anWidth = ParseInt32(theValue.substr(anComma2Offset+1,anComma3Offset), theDefault.GetWidth());
          sf::Int32 anHeight = ParseInt32(theValue.substr(anComma3Offset+1), theDefault.GetHeight());

          // Now that all 4 values have been parsed, return the color found
          anResult.Left = anLeft;
          anResult.Top = anTop;
          anResult.Right = anLeft+anWidth;
          anResult.Bottom = anTop+anHeight;
#else
          // Get the width and height values
          sf::Int32 anWidth = ParseInt32(theValue.substr(anComma2Offset+1,anComma3Offset), theDefault.width);
          sf::Int32 anHeight = ParseInt32(theValue.substr(anComma3Offset+1), theDefault.height);

          // Now that all 4 values have been parsed, return the color found
          anResult.left = anLeft;
          anResult.top = anTop;
          anResult.width = anWidth;
          anResult.height = anHeight;
#endif
        }
      }
    }

    // Return the result found or theDefault assigned above
    return anResult;
  }
示例#10
0
  std::string ConvertIntRect(const sf::IntRect theRect)
  {
    // Use StringStream class to convert theRect to a string
    std::stringstream anResult;

    // Add theRect to the stringstream
#if (SFML_VERSION_MAJOR < 2)
    anResult << theRect.Top << ", ";
    anResult << theRect.Left << ", ";
    anResult << theRect.GetWidth() << ", ";
    anResult << theRect.GetHeight();
#else
    anResult << theRect.top << ", ";
    anResult << theRect.left << ", ";
    anResult << theRect.width << ", ";
    anResult << theRect.height;
#endif

    // Return the string result created by stringstream
    return anResult.str();
  }
示例#11
0
bool DeathWall::checkIfHitDeathBlock(sf::IntRect playerRect){
	for(Wall::size_type i = 0; i < deathWall.size(); i++){
		sf::IntRect rect;
		rect.left = static_cast <int>(deathWall[i]->getX());
		rect.top = static_cast <int>(deathWall[i]->getY());
		rect.width = static_cast <int>(deathWall[i]->getWidth());
		rect.height = static_cast <int>(deathWall[i]->getHeight());

		if(playerRect.intersects(rect))
			return true;
	}
	return false;
}
///////////////
// INTERSECT //
///////////////
void SelectionController::intersectSelection(const sf::IntRect& rect, const std::vector<nSet::o_line>& conf_l) {
	if (isSelected()) {
		intersectSelection(rect, static_cast<sf::Image*>(NULL));
		setInverted(false);

		pos_lines = new nSet::positionned_olines(*pos_lines);
		FOR_I_INV (pos_lines->lines.size())
			if (!rect.contains(pos_lines->lines[i].x, pos_lines->lines[i].y))
				pos_lines->lines.erase(pos_lines->lines.begin() + i);
		pos_lines->lines.insert(pos_lines->lines.end(), conf_l.begin(), conf_l.end());
		pos_lines->pos = getPosition();
	
		if (!reline()) {
			UNDO->push(*new SelecUpdated(this, *image_selec, pos_lines->pos, *pos_lines, inverted));
			emit selectionUpdated(3);
		}
	}
	else