本文整理汇总了C++中sf::FloatRect::Intersects方法的典型用法代码示例。如果您正苦于以下问题:C++ FloatRect::Intersects方法的具体用法?C++ FloatRect::Intersects怎么用?C++ FloatRect::Intersects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::FloatRect
的用法示例。
在下文中一共展示了FloatRect::Intersects方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CollisionGeneral
bool Player::CollisionGeneral(const sf::FloatRect playerRect,bool &kill){
int maxHeight, minHeight, maxWidth, minWidth;
bool collision=false;
minHeight=playerRect.Top/GameConfig::g_config["tileheight"];
minWidth=playerRect.Left/GameConfig::g_config["tilewidth"];
maxHeight=(playerRect.Top+playerRect.Height-1)/GameConfig::g_config["tileheight"];
maxWidth=(playerRect.Left+playerRect.Width-1)/GameConfig::g_config["tilewidth"];
if(minHeight<0)minHeight=0;
if(maxHeight>(*m_map)->m_height)maxHeight=(*m_map)->m_height;
if(minWidth<0)minWidth=0;
if(maxWidth>(*m_map)->m_width)maxWidth=(*m_map)->m_width;
for(int y=minHeight;y<=maxHeight;y++){
for(int x=minWidth;x<=maxWidth;x++){
if(!(x>=(*m_map)->m_width or y>=(*m_map)->m_height)){
if((*m_map)->Tile(x,y).kill)kill=true;
if(((*m_map)->Tile(x,y).fall && IsPrincess() && !(*m_map)->Tile(x,y).princess)||
((*m_map)->Tile(x,y).fall && !IsPrincess() && (*m_map)->Tile(x,y).princess)||
!(*m_map)->Tile(x,y).fall){
if((*m_map)->Tile(x,y).solid && !((*m_map)->Tile(x,y).touch && (*m_map)->Tile(x,y).tile.GetColor().a==0)){
if((*m_map)->Tile(x,y).fall)(*m_map)->m_tileSet.at(x).at(y).touch=true;
sf::FloatRect theTile(x*GameConfig::g_config["tilewidth"],y*GameConfig::g_config["tileheight"],GameConfig::g_config["tilewidth"],GameConfig::g_config["tileheight"]);
if(playerRect.Intersects(theTile)||theTile.Intersects(playerRect)){
collision= true;
}
}
}
}
}
}
return collision;
}
示例2: CollisionGeneral
bool GameMob::CollisionGeneral(const sf::FloatRect entityRect){
int maxHeight, minHeight, maxWidth, minWidth;
minHeight=entityRect.Top/GameConfig::g_config["tileheight"];
minWidth=entityRect.Left/GameConfig::g_config["tilewidth"];
maxHeight=(entityRect.Top+entityRect.Height-1)/GameConfig::g_config["tileheight"];
maxWidth=(entityRect.Left+entityRect.Width-1)/GameConfig::g_config["tilewidth"];
if(minHeight<0)minHeight=0;
if(maxHeight>(*m_map)->m_height)maxHeight=(*m_map)->m_height;
if(minWidth<0)minWidth=0;
if(maxWidth>(*m_map)->m_width)maxWidth=(*m_map)->m_width;
for(int y=minHeight;y<=maxHeight;y++){
for(int x=minWidth;x<=maxWidth;x++){
if((*m_map)->Tile(x,y).solid){
sf::FloatRect theTile(x*GameConfig::g_config["tilewidth"],y*GameConfig::g_config["tileheight"],GameConfig::g_config["tilewidth"],GameConfig::g_config["tileheight"]);
if(entityRect.Intersects(theTile)||theTile.Intersects(entityRect)){
if((*m_map)->Tile(x,y).boomer && (*m_map)->Tile(x,y).color==GameConfig::ColorToNbr(GetColor()))(*m_map)->Explode(x,y);
return true;
}
}
}
}
return false;
}
示例3: CollisionHorizontal
bool Player::CollisionHorizontal(const sf::FloatRect playerRect, bool &gauche, bool &droite,int &solidLimit){
int maxHeight, minHeight, maxWidth, minWidth;
bool CollisionHorizontal=false;
minHeight=playerRect.Top/GameConfig::g_config["tileheight"];
minWidth=playerRect.Left/GameConfig::g_config["tilewidth"];
maxHeight=(playerRect.Top+playerRect.Height-1)/GameConfig::g_config["tileheight"];
maxWidth=(playerRect.Left+playerRect.Width-1)/GameConfig::g_config["tilewidth"];
if(minHeight<0)minHeight=0;
if(maxHeight>(*m_map)->m_height)maxHeight=(*m_map)->m_height;
if(minWidth<0)minWidth=0;
if(maxWidth>(*m_map)->m_width)maxWidth=(*m_map)->m_width;
for(int y=minHeight;y<=maxHeight;y++){
for(int x=minWidth;x<=maxWidth;x++){
if(!(x>=(*m_map)->m_width or y>=(*m_map)->m_height)){
if(((*m_map)->Tile(x,y).fall && IsPrincess() && !(*m_map)->Tile(x,y).princess)||
((*m_map)->Tile(x,y).fall && !IsPrincess() && (*m_map)->Tile(x,y).princess)||
!(*m_map)->Tile(x,y).fall){
if((*m_map)->Tile(x,y).solid && !((*m_map)->Tile(x,y).touch && (*m_map)->Tile(x,y).tile.GetColor().a==0)){
sf::FloatRect theTile(x*GameConfig::g_config["tilewidth"],y*GameConfig::g_config["tileheight"],GameConfig::g_config["tilewidth"],GameConfig::g_config["tileheight"]);
if(playerRect.Intersects(theTile)||theTile.Intersects(playerRect)){
CollisionHorizontal= true;
if((*m_map)->Tile(x,y).fall)(*m_map)->m_tileSet.at(x).at(y).touch=true;
if(x*GameConfig::g_config["tilewidth"]>=playerRect.Left&&x*GameConfig::g_config["tilewidth"]<=playerRect.Left+playerRect.Width){
droite=true;
solidLimit=x;
}
if((x+1)*GameConfig::g_config["tilewidth"]<=playerRect.Left+playerRect.Width&&(x+1)*GameConfig::g_config["tilewidth"]>=playerRect.Left){
gauche=true;
solidLimit=x;
}
}
}
}
}
}
}
return CollisionHorizontal;
}