当前位置: 首页>>代码示例>>C++>>正文


C++ FloatRect::Intersects方法代码示例

本文整理汇总了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;
 }
开发者ID:PhiBabin,项目名称:LD21---Escape,代码行数:32,代码来源:Player.cpp

示例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;
 }
开发者ID:PhiBabin,项目名称:Toisin,代码行数:25,代码来源:GameMob.cpp

示例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;
 }
开发者ID:PhiBabin,项目名称:LD21---Escape,代码行数:40,代码来源:Player.cpp


注:本文中的sf::FloatRect::Intersects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。