Example #1
0
/**
 * Returns a vector of Rects corresponding to the tiles
 * that are colliding with the given box
 */
std::vector<Rect> MovementMap::GetCollidingTiles(const Rect& box)
{
    std::vector<Rect> collidingTiles;
    // Check the upper point
    if (!IsZero(box.GetX()+box.GetW()/2, box.GetY()))
        collidingTiles.push_back(TileToRect(box.GetX(), box.GetY()));
    // Check the right point
    if (!IsZero(box.GetX()+box.GetW(), box.GetY()+box.GetH()/2))
        collidingTiles.push_back(TileToRect(box.GetX()+box.GetW(), box.GetY()));
    // Check the left point
    if (!IsZero(box.GetX(), box.GetY()+box.GetH()/2))
        collidingTiles.push_back(TileToRect(box.GetX(), box.GetY()+box.GetH()));
    // Check the lower point
    if (!IsZero(box.GetX()+box.GetW()/2, box.GetY()+box.GetH()))
        collidingTiles.push_back(TileToRect(box.GetX()+box.GetW(), box.GetY()+box.GetH()));
//    for (int i = 0; i < collidingTiles.size(); i++)
//    {
//        std::cout << std::endl;
//        std::cout << "(" << collidingTiles[i].GetX() << "," << collidingTiles[i].GetY() << ")" << std::endl;
//        std::cout << "Width: " << collidingTiles[i].GetW() << " Height: " << collidingTiles[i].GetH() << std::endl;
//    }
    return collidingTiles;
}
Example #2
0
void TILEMAP::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
    if (!texture) return;

    sf::Sprite sprite(*texture);
    sf::IntRect rect;

    for (unsigned int y=0; y<height; y++)
    {
        for (unsigned int x=0; x<width; x++)
        {
            if ( TileToRect( (tile[x][y]), rect) )
            {
                sprite.setTextureRect(rect);
                sprite.setPosition(x*tileSize, y*tileSize);
                target.draw(sprite);
            }
        }
    }
}