Example #1
0
    bool UpdateMiddleEraseMesh()
    {
        if (oldPosition == null)
        {
            return(false);
        }

        Vector2D pos    = new Vector2D(GetMousePosition());
        Vector2D oldPos = new Vector2D(oldPosition);

        if (Vector2D.Distance(pos, oldPos) < size)
        {
            return(false);
        }

        Polygon2D middlePolygon = new Polygon2D();

        double rotation = Vector2D.Atan2(pos, oldPos) - Mathf.PI / 2;

        Vector2D push = Vector2D.Zero();

        push.Push(rotation, size);

        middlePolygon.AddPoint(pos + push);
        middlePolygon.AddPoint(pos - push);
        middlePolygon.AddPoint(oldPos - push);
        middlePolygon.AddPoint(oldPos + push);

        eraseBrushMiddle = new EraseBrush(null, middlePolygon);

        return(true);
    }
Example #2
0
    public bool Update(Vector2D pos)
    {
        float scroll         = Input.GetAxis("Mouse ScrollWheel");
        float newPolygonSize = polygonSize + scroll;

        if (newPolygonSize > 0.05f)
        {
            polygonSize = newPolygonSize;
        }

        mouseDown = true;

        if (Input.GetMouseButtonDown(0))
        {
            Polygon2D.defaultCircleVerticesCount = polygonEdgeCount;
            slicePolygon = Polygon2D.Create(polygonType, polygonSize);

            Polygon2D polygon = new Polygon2D();
            polygon.pointsList = new List <Vector2D>(slicePolygon.pointsList);
            polygon.ToOffsetItself(pos);

            EraseBrush EraseBrush = new EraseBrush(null, polygon);

            Destruction2D.DestroyByPolygonAll(EraseBrush, destructionLayer);

            return(true);
        }
        else
        {
            return(false);
        }
    }
Example #3
0
    static public bool DestroyByPolygonAll(EraseBrush eraseBrush, Destruction2DLayer layer = null)
    {
        bool slicingDetected = false;

        if (layer == null)
        {
            layer = Destruction2DLayer.Create();
        }
        foreach (Destruction2D gObject in GetListLayer(layer))
        {
            if (gObject.DestroyByPolygon(eraseBrush))
            {
                slicingDetected = true;
            }
        }
        return(slicingDetected);
    }
Example #4
0
    public void OnCollisionEnter2D(Collision2D col)
    {
        Polygon2D polygon = Polygon2DList.CreateFromGameObject(gameObject)[0];

        // or
        //Polygon2D.Create(Polygon2D.PolygonType.Pentagon, 1);
        polygon = polygon.ToScale(new Vector2(5, 5));
        polygon = polygon.ToWorldSpace(transform);

        EraseBrush EraseBrush = new EraseBrush(null, polygon);

        Destruction2D.DestroyByPolygonAll(EraseBrush, Destruction2DLayer.Create());

        Destruction2D.AddModifierAll(modifierTexture, gameObject.transform.position, new Vector2(5, 5), 0, Destruction2DLayer.Create());

        Destroy(gameObject);
    }
Example #5
0
 public DestructionEvent(EraseBrush newEraseBrush)
 {
     eraseBrush = newEraseBrush;
 }
Example #6
0
    public bool DestroyByPolygon(EraseBrush EraseBrush)
    {
        //CrumbsEffect.isSlicing = false;

        if (EraseBrush.GetWorldShape().pointsList.Count < 3)
        {
            return(false);
        }

        List <Polygon2D> polys = shape.GetWorld();

        if (polys.Count > 0)
        {
            bool touch   = false;
            bool outside = false;

            foreach (Polygon2D p in polys)
            {
                if (Math2D.PolyCollidePoly(EraseBrush.GetWorldShape(), p) == true)
                {
                    touch = true;
                }

                if (EraseBrush.GetWorldShape().PolyInPoly(p) == false)
                {
                    outside = true;
                }
            }



            if (touch == false)
            {
                return(false);
            }
            // CrumbsEffect.isSlicing = true;
            if (outside == false)
            {
                Destroy(gameObject);
                return(true);
            }
        }
        else
        {
            Polygon2D bound = GetBoundPolygon();
            bool      touch = false;

            bound.ToWorldSpaceItself(transform);

            if (Math2D.PolyCollidePoly(EraseBrush.GetWorldShape(), bound) == true)
            {
                touch = true;
            }

            if (touch == false)
            {
                return(false);
            }
        }

        eraseEvents.Add(new DestructionEvent(EraseBrush));

        if (textureType == TextureType.SpriteShape)
        {
            buffer.renderCamera.enabled = true;
        }
        else
        {
            Destruction2DManager.RequestBufferEvent(this);
        }
        return(true);
    }
Example #7
0
    public void DestroyByComplexCut(ComplexCut complexCut)
    {
        EraseBrush erase = new EraseBrush(null, new Polygon2D(complexCut.GetPointsList()));

        DestroyByPolygon(erase);
    }
Example #8
0
    public void DestroyByLinearCut(LinearCut linearCut)
    {
        EraseBrush erase = new EraseBrush(null, new Polygon2D(linearCut.GetPointsList()));

        DestroyByPolygon(erase);
    }
Example #9
0
    public void DestroyByCollider(Collider2D collider)
    {
        EraseBrush erase = new EraseBrush(null, Polygon2DList.CreateFromGameObject(collider.gameObject)[0].ToWorldSpace(collider.transform));

        DestroyByPolygon(erase);
    }