BeatTheStreet/src/obsticle.cpp
//Boolean function that returns true if the sprite contacts the floatrect parameter.
Boolean function that returns true if the sprite contacts the floatrect parameter.
Boolean function that returns true if the sprite contacts the floatrect parameter .
bool obsticle::playerContact(sf::FloatRect frogglobalbounds, bool boat)
{
	sf::FloatRect frContactBox;
	frContactBox.left = oSprite.getGlobalBounds().left;
	frContactBox.top = oSprite.getGlobalBounds().top + 25; 
	frContactBox.height = oSprite.getGlobalBounds().height - 50;
	frContactBox.width = oSprite.getGlobalBounds().width;
	if (!boat && frContactBox.intersects(frogglobalbounds))
	{
		return true;
	}
	else if (boat)
	{
		sf::FloatRect newfrogcenter = frogglobalbounds;
		newfrogcenter.left = frogglobalbounds.left + 24;
		newfrogcenter.width = 2;
		if (frContactBox.intersects(newfrogcenter))
		{
			return true;
		}
		else return false;
	}
	else return false;
}
bool obsticle :: playerContact ( sf :: FloatRect frogglobalbounds , bool boat ) { sf :: FloatRect frContactBox ; frContactBox . left = oSprite . getGlobalBounds ( ) . left ; frContactBox . top = oSprite . getGlobalBounds ( ) . top + 25 ; frContactBox . height = oSprite . getGlobalBounds ( ) . height - 50 ; frContactBox . width = oSprite . getGlobalBounds ( ) . width ; if ( ! boat && frContactBox . intersects ( frogglobalbounds ) ) { return true ; } else if ( boat ) { sf :: FloatRect newfrogcenter = frogglobalbounds ; newfrogcenter . left = frogglobalbounds . left + 24 ; newfrogcenter . width = 2 ; if ( frContactBox . intersects ( newfrogcenter ) ) { return true ; } else return false ; } else return false ; }
Boolean function that returns true if the sprite contacts the floatrect parameter.
Boolean function that returns true if the sprite contacts the floatrect parameter .
//Initialize floatrect for intersection and assign modified values from the obstacle sprite. //+25 so that only the bottom of the sprite intersects //-50 so that only the bottom of the sprite intersects //if the obstacle is not a boat, return true when collision occurs. //if it is a boat collision only occurs when the middle of the sprite intersects. This is so 50% of the sprite can hang off the edge of the boat //floatrect for player center //if the new floatrect intersects the boat, the player must be on board.