コード例 #1
0
ファイル: SFMLfunctions.hpp プロジェクト: 0mN1/MultiVerse
bool SimpleCollision(Sprite s1, Sprite s2)
{
    if(s1.GetPosition().x - s1.GetCenter().x < s2.GetPosition().x + s2.GetSize().x  - s2.GetCenter().x
            && s1.GetPosition().x + s1.GetSize().x - s1.GetCenter().x > s2.GetPosition().x - s2.GetCenter().x
            && s1.GetPosition().y - s1.GetCenter().y < s2.GetPosition().y + s2.GetSize().y - s2.GetCenter().y
            && s1.GetPosition().y + s1.GetSize().y - s1.GetCenter().y > s2.GetPosition().y - s2.GetCenter().y)
        return true;
    else
        return false;
}
コード例 #2
0
ファイル: SFMLfunctions.hpp プロジェクト: 0mN1/MultiVerse
bool PPCollisionWR(Sprite Sprite1,Sprite Sprite2,float AlphaLimit = 50.f)
{
    float xmin1 = Sprite1.GetPosition().x - Sprite1.GetCenter().x;
    float ymin1 = Sprite1.GetPosition().y - Sprite1.GetCenter().y;
    float xmin2 = Sprite2.GetPosition().x - Sprite2.GetCenter().x;
    float ymin2 = Sprite2.GetPosition().y - Sprite2.GetCenter().y;

    float xmax1 = xmin1 + Sprite1.GetSize().x;
    float ymax1 = ymin1 + Sprite1.GetSize().y;
    float xmax2 = xmin2 + Sprite2.GetSize().x;
    float ymax2 = ymin2 + Sprite2.GetSize().y;

    float xmin = max(xmin1, xmin2);
    float ymin = max(ymin1, ymin2);
    float xmax = min(xmax1, xmax2);
    float ymax = min(ymax1, ymax2);

    //if(xmax <= xmin || ymax <= ymin) { return false; }

    for(int y = int(ymin); y < ymax; ++y)
    {
        for(int x = int(xmin); x < xmax; ++x)
        {
            float x1 = x - xmin1, y1 = y - ymin1;
            float x2 = x - xmin2, y2 = y - ymin2;

            Vector2f Point1 =
                RotatePoint(Vector2f(x1,y1),
                            Sprite1.GetCenter(),
                            -Sprite1.GetRotation());

            Vector2f Point2 =
                RotatePoint(Vector2f(x2,y2),
                            Sprite2.GetCenter(),
                            -Sprite2.GetRotation());

            if(Point1.x > 0 && Point1.y > 0 && Point2.x > 0 && Point2.y > 0
                    && Point1.x < Sprite1.GetSize().x && Point1.y < Sprite1.GetSize().y
                    && Point2.x < Sprite2.GetSize().x && Point2.y < Sprite2.GetSize().y)
            {
                Color color1 = Sprite1.GetPixel(int(Point1.x),int(Point1.y));
                Color color2 = Sprite2.GetPixel(int(Point2.x),int(Point2.y));

                if (color1.a >= AlphaLimit && color2.a >= AlphaLimit)
                {
                    return true;
                }
            }
        }
    }

    return false;
}
コード例 #3
0
ファイル: SFMLfunctions.hpp プロジェクト: 0mN1/MultiVerse
bool PPCollision(Sprite Sprite1,Sprite Sprite2,float AlphaLimit = 50.f)
{
    float xmin1 = Sprite1.GetPosition().x - Sprite1.GetCenter().x;
    float ymin1 = Sprite1.GetPosition().y - Sprite1.GetCenter().y;
    float xmin2 = Sprite2.GetPosition().x - Sprite2.GetCenter().x;
    float ymin2 = Sprite2.GetPosition().y - Sprite2.GetCenter().y;

    float xmax1 = xmin1 + Sprite1.GetSize().x;
    float ymax1 = ymin1 + Sprite1.GetSize().y;
    float xmax2 = xmin2 + Sprite2.GetSize().x;
    float ymax2 = ymin2 + Sprite2.GetSize().y;

    float xmin = max(xmin1, xmin2);
    float ymin = max(ymin1, ymin2);
    float xmax = min(xmax1, xmax2);
    float ymax = min(ymax1, ymax2);

    if(xmax <= xmin || ymax <= ymin) {
        return false;
    }

    for(int y = int(ymin); y < ymax; y += 5)
    {
        for(int x = int(xmin); x < xmax; x += 5)
        {
            float x1 = x - xmin1, y1 = y - ymin1;
            float x2 = x - xmin2, y2 = y - ymin2;

            if(x1 > 0 && y1 > 0 && x2 > 0 && y2 > 0
                    && x1 < Sprite1.GetSize().x && y1 < Sprite1.GetSize().y
                    && x2 < Sprite2.GetSize().x && y2 < Sprite2.GetSize().y)
            {
                Color color1 = Sprite1.GetPixel(int(x1),int(y1));
                Color color2 = Sprite2.GetPixel(int(x2),int(y2));

                if (color1.a >= AlphaLimit && color2.a >= AlphaLimit)
                {
                    return true;
                }
            }
        }
    }

    return false;
}
コード例 #4
0
ファイル: SFMLfunctions.hpp プロジェクト: 0mN1/MultiVerse
bool PPCollision(Vector2f point, Sprite & s, float AlphaLimit = 20.f)
{
    point -= s.GetPosition() - s.GetCenter();

    if(point.x >= 0 && point.x < s.GetSize().x
            && point.y >= 0 && point.y < s.GetSize().y
            && s.GetPixel((int)point.x, (int)point.y).a > AlphaLimit)
        return true;
    else
        return false;
}
コード例 #5
0
ファイル: Direction.cpp プロジェクト: heyuqi/GD
void Direction::UnserializeFrom(const gd::SerializerElement & element)
{
    SetTimeBetweenFrames(element.GetDoubleAttribute("timeBetweenFrames", 1, "tempsEntre"));
    SetLoop(element.GetBoolAttribute("looping", false, "boucle"));

    const gd::SerializerElement & spritesElement = element.GetChild("sprites", 0, "Sprites");
    spritesElement.ConsiderAsArrayOf("sprite", "Sprite");
    for (unsigned int i = 0; i < spritesElement.GetChildrenCount(); ++i)
    {
        const gd::SerializerElement & spriteElement = spritesElement.GetChild(i);
        Sprite sprite;

        sprite.SetImageName(spriteElement.GetStringAttribute("image"));
        OpenPointsSprites(sprite.GetAllNonDefaultPoints(), spriteElement.GetChild("points", 0, "Points"));

        OpenPoint(sprite.GetOrigin(), spriteElement.GetChild("originPoint" , 0, "PointOrigine"));
        OpenPoint(sprite.GetCenter(), spriteElement.GetChild("centerPoint" , 0, "PointCentre"));
        sprite.SetDefaultCenterPoint(spriteElement.GetChild("centerPoint" , 0, "PointCentre").GetBoolAttribute("automatic", true));

        if (spriteElement.HasChild("CustomCollisionMask"))
            sprite.SetCollisionMaskAutomatic(!spriteElement.GetChild("CustomCollisionMask").GetBoolAttribute("custom", false));
        else
            sprite.SetCollisionMaskAutomatic(!spriteElement.GetBoolAttribute("hasCustomCollisionMask", false));

        std::vector<Polygon2d> mask;
        const gd::SerializerElement & collisionMaskElement = spriteElement.GetChild("customCollisionMask", 0, "CustomCollisionMask");
        collisionMaskElement.ConsiderAsArrayOf("polygon", "Polygon");
        for (unsigned int j = 0; j < collisionMaskElement.GetChildrenCount(); ++j)
        {
            Polygon2d polygon;

            const gd::SerializerElement & polygonElement = collisionMaskElement.GetChild(j);
            polygonElement.ConsiderAsArrayOf("vertice", "Point");
            for (unsigned int k = 0; k < polygonElement.GetChildrenCount(); ++k)
            {
                const gd::SerializerElement & verticeElement = polygonElement.GetChild(k);

                polygon.vertices.push_back(sf::Vector2f(verticeElement.GetDoubleAttribute("x"),
                    verticeElement.GetDoubleAttribute("y")));
            }

            mask.push_back(polygon);
        }
        sprite.SetCustomCollisionMask(mask);

        sprites.push_back(sprite);
    }
};
コード例 #6
0
ファイル: SFMLfunctions.hpp プロジェクト: 0mN1/MultiVerse
Vector2f LowerRight(Sprite & sprite)
{
    return sprite.GetPosition() + sprite.GetSize() - sprite.GetCenter();
}
コード例 #7
0
ファイル: SFMLfunctions.hpp プロジェクト: 0mN1/MultiVerse
Vector2f UpperLeft(Sprite & sprite)
{
    return sprite.GetPosition() - sprite.GetCenter();
}