Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
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;
 }
Ejemplo n.º 3
0
 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;
 }