예제 #1
0
    private IEnumerator Fire(float waitTime)
    {
        isShotting = true;
        Transform tmp;
        Vector2   trg;

        trgP = trg = LineFuctions.RotateVecPFromI(Vector2.zero, degreeAngle, Vector2.up);
        //   Rigidbody2D rg = tr.GetComponent<Rigidbody2D>();
        //  trg = trg *powerMultiplier;
        //    rg.velocity = trg;
        // rg.velocity = new Vector2(trg.x * powerMultiplier, trg.y * powerMultiplier);
        tmp = Instantiate(tr, this.transform.position + new Vector3(trg.x * 2, trg.y * 2), this.transform.rotation, null);
        //  tmp.GetComponent<Rigidbody2D>().velocity = new Vector2(trg.x * powerMultiplier, trg.y * powerMultiplier);
        tmp.GetComponent <Rigidbody2D>().velocity = new Vector2(trg.x * powerMultiplier, trg.y * powerMultiplier);
        yield return(new WaitForSeconds(waitTime));



        isShotting          = false;
        prevPowerMultiplier = powerMultiplier;
        powerMultiplier     = 0;
        navigatorTr.GetComponent <ControlNavigator>().ChangeBobot();


        //  print("WaitAndPrint " + Time.time);
    }
예제 #2
0
    private IEnumerator Fire(float waitTime)
    {
        isShotting = true;

        Transform tmp;
        Vector2   trg;

        trg = LineFuctions.RotateVecPFromI(Vector2.zero, degreeAngle, Vector2.up);
        //   Rigidbody2D rg = tr.GetComponent<Rigidbody2D>();
        //  trg = trg *powerMultiplier;
        //    rg.velocity = trg;
        // rg.velocity = new Vector2(trg.x * powerMultiplier, trg.y * powerMultiplier);
        tmp = Instantiate(tr, this.transform.position + new Vector3(trg.x * 2, trg.y * 2), this.transform.rotation, null);
        tmp.GetComponent <Rigidbody2D>().velocity = new Vector2(trg.x * powerMultiplier, trg.y * powerMultiplier);
        yield return(new WaitForSeconds(waitTime));

        GameObject.Find("MotherOfEverything").transform.Find("Manager").GetComponent <TurnsSystem>().setChangePlayer(true);
        isShotting = false;


        //  print("WaitAndPrint " + Time.time);
    }
예제 #3
0
    public void InitCollision(Vector2 pt, float dmgRadius)
    {
        IndexableCyclicalLinkedList <Vertex> lst = GetVertLst();



        int prevIdx;
        int pointIdx = LineFuctions.GetClosestPointIdx(lst, pt);
        LinkedListNode <Vertex> prev, nxt, ctr, closest;

        ctr     = LineFuctions.GetClosestPointVert(lst, pt);
        closest = ctr;
        // prev = ctr.Previous;
        if (ctr.Next != null)
        {
            nxt = ctr.Next;
        }
        else
        {
            nxt = lst.First;
        }
        prevIdx = pointIdx - 1;

        //co gdy circledmg zakrewa wszystkie punkty?....

        //

        //to teraz maja idx bierzesz dwie intersekcje a potem dla tych intersekcji sprawdzasz dystans do segmentow
        //dzieki temu bedzieszi wiedzil jaki odcienek dzielic.



        Vector2[] intersection;
        //form first line seg
        intersection = null;



        List <Vertex> VertToRemoveLst;

        VertToRemoveLst = new List <Vertex>();
        int someIdx = lst.Count;
        LinkedListNode <Vertex> prevT, nxtT, ctrT;

        ctrT = ctr;
        // int a = 0;

        List <LineSegmentWithAngle>          lineSegsOuter;
        List <LineSegmentInnerWithIntersect> intersectionLineSeg;
        List <IntersectionWithVert>          intersctionVertLst;

        intersctionVertLst  = new List <IntersectionWithVert>();
        lineSegsOuter       = new List <LineSegmentWithAngle>();
        intersectionLineSeg = new List <LineSegmentInnerWithIntersect>();


        // return;
        bool areWeOnBeginning = true;

        while (1 == 1)//going counter clock wise by vertexes
        {
            string temp            = "we check now ctr:" + ctr.Value.Index.ToString() + "on " + ctr.Value.Position.ToString() + " and " + nxt.Value.Index.ToString() + "on " + nxt.Value.Position.ToString();
            string temp1           = "czy odleglosc od contact point :" + pt.ToString() + " do " + ctr.Value.Position.ToString() + " = " + LineFuctions.Distance(pt, ctr.Value.Position).ToString();
            float  ctr_next_radius = (float)LineFuctions.Distance(ctr.Value.Position, nxt.Value.Position) + dmgRadius;
            string temp2           = "jest wieksza od dystansy z ctr do nxt plus dmgRadius" + ctr_next_radius.ToString();

            if (ctr == closest && areWeOnBeginning)
            {
                areWeOnBeginning = false;
            }

            if (LineFuctions.Distance(pt, ctr.Value.Position) > LineFuctions.Distance(ctr.Value.Position, nxt.Value.Position) + dmgRadius)//if to far to calc
            {
            }
            else
            {
                intersection = LineFuctions.Intersection(pt.x, pt.y, dmgRadius, ctr.Value.Position, nxt.Value.Position);
                if (LineFuctions.Distance(ctr.Value.Position, pt) < dmgRadius)
                {
                    VertToRemoveLst.Add(ctr.Value);
                }
                if (intersection != null)
                {
                    if (intersection.Length == 1)
                    {
                        //  lst.AddBefore(nxt, new LinkedListNode<Vertex>(new Vertex(intersection[0], someIdx++)));
                        if (LineFuctions.Distance(nxt.Value.Position, pt) < dmgRadius)
                        {
                            //odcinek wchodzacy w dmgRadius push.
                            intersectionLineSeg.Add(new LineSegmentInnerWithIntersect(ctr.Value, nxt.Value, ctr, nxt, intersection[0], true));
                            //zapamietac intersekcje  wychodzącę.
                            //pod koniec alg lecisz od wychodzacej dopuki nie masz intersekcji.
                            //powinno dzialac dobrze x171113
                            Vector2[] circleIntersection;
                            circleIntersection = new Vector2[2];
                            Vector2 tempRotatedVec = intersection[0];
                            bool    weHaveSecondCircleIntersect = false;
                            //   float tempAngle = AngleBetweenVectorsDe(nxt.Value.Position, ctr.Value.Position);
                            //  while(!weHaveSecondCircleIntersect)// check is have lenght already?
                            //   {
                            //      circleIntersection[0] = intersection[0];
                            //      RotateVecPFromI(contact.point, 20, tempRotatedVec);
                            //kuzwa nie da rady tak trzeba wyliczyc wszystkie intersekcje i zapameitywac gdzie byly z jakimi odcinkami i potem na podstawie
                            //tych info dodawac te vertexy.
                            //patrzysz jeszcze czy to jest intersekcja wejsciowa czy wyjsciowa.
                            //mozna dwie listy bo potem tylko szukasz intersekcji wyjsciowych.
                            //to lecisz to tych intesekcjach z odcinkami wedle clockwise i bierzesz pierwsza ktora jest pod wzgledem wielkosci konta.
                            //czyli wyjsciowa intersekcja odcninkowa z najmniejszym katem clockwise co do obecnej wejsciowej.
                            //  }
                            //addbefore nxt until in
                        }
                        else
                        {
                            lineSegsOuter.Add(new LineSegmentWithAngle(ctr.Value, nxt.Value));
                            // intersectionLineSeg.Add(new LineSegmentInnerWithIntersect(ctr.Value, nxt.Value,intersection[0], false));
                        }
                        //  if (Distance(ctr.Value.Position, contact.point) < dmgRadius)
                        //   {
                        //      VertToRemoveLst.Add(ctr.Value);
                        // kiedy remove bo jak mamy kilka vertow np 3 w kole to jak?
                        // rozkmin ten usuwa tylko dwoch.
                        //   }
                        // VertToRemoveLst.Add(ctr.Value);
                        //  break;
                    }
                    else
                    {
                        if (LineFuctions.FirstIsCloserThenSecond(intersection[0], intersection[1], nxt.Value.Position))
                        {
                            //     lst.AddBefore(nxt, new LinkedListNode<Vertex>(new Vertex(intersection[0], someIdx++)));
                            intersectionLineSeg.Add(new LineSegmentInnerWithIntersect(ctr.Value, nxt.Value, ctr, nxt, intersection[1], true));
                            lineSegsOuter.Add(new LineSegmentWithAngle(ctr.Value, nxt.Value));    // previus ctr to nxt

                            //       lst.AddBefore(nxt.Previous, new LinkedListNode<Vertex>(new Vertex(intersection[1], someIdx++)));
                            //  areWeHaveTwoIntesect = true;
                            //  break;
                        }
                        else
                        {
                            //     lst.AddBefore(nxt, new LinkedListNode<Vertex>(new Vertex(intersection[1], someIdx++)));
                            //      lst.AddBefore(nxt.Previous, new LinkedListNode<Vertex>(new Vertex(intersection[0], someIdx++)));
                            intersectionLineSeg.Add(new LineSegmentInnerWithIntersect(ctr.Value, nxt.Value, ctr, nxt, intersection[0], true));
                            lineSegsOuter.Add(new LineSegmentWithAngle(ctr.Value, nxt.Value));
                            // areWeHaveTwoIntesect = true;
                            // break;
                        }
                    }
                }
                else
                {
                    // i tak trzbea leciec po wszystkich bo jak beda plaskie polygony to bedzie uj
                    // a jak lecisz po wszystkich to wtedy nie mozesz breakowac jak juz masz intersekcje z dmgRadius.
                }
            }

            ctr = nxt;

            if (nxt.Next == null)
            {
                nxt = lst.First;
            }
            else
            {
                nxt = nxt.Next;
            }

            if (ctr == closest && !areWeOnBeginning)
            {
                break;
            }


            //ctr = closest;
        }



        while (intersectionLineSeg.Count > 0)
        {
            LineSegmentInnerWithIntersect trg = intersectionLineSeg[0];
            float angleOftrg   = LineFuctions.Angle(trg.A.Position - trg.B.Position);
            float angleOfOuter = LineFuctions.Angle(lineSegsOuter[0].A.Position - lineSegsOuter[0].B.Position);
            LinkedListNode <Vertex> tmp;


            bool    weHaveIntersect = false;
            Vector2 intersecVector  = trg.intersection;
            Vector2 ctrV;
            ctrV = intersecVector;
            float basicAngle = LineFuctions.Angle(trg.intersection - pt);
            foreach (LineSegmentWithAngle i in lineSegsOuter)
            {
                i.angle -= basicAngle;
                if (i.angle < 0)
                {
                    i.angle += Mathf.PI * 2;
                }
            }
            //float tempAngle = AngleBetweenVectorsDe(nxt.Value.Position, ctr.Value.Position);
            //  objListOrder.Sort((x, y) => x.OrderDate.CompareTo(y.OrderDate));
            lineSegsOuter.OrderByDescending(x => x.angle);
            float crossingX, crossingY;
            // lineSegsOuter.Sort()
            tmp  = lst.AddAfter(trg.aLink, new Vertex(trg.intersection, someIdx++));
            ctrV = LineFuctions.RotateVecPFromI(pt, -2, ctrV);
            while (!weHaveIntersect)// check is have lenght already?
            {
                Vector2 nxtV;

                LineSegmentWithAngle nearestLineSeg = lineSegsOuter[0];
                nxtV = LineFuctions.RotateVecPFromI(pt, -30, ctrV); // czy obraca w dobra strone?
                if (LineFuctions.Get_line_intersection(ctrV.x, ctrV.y, nxtV.x, nxtV.y, nearestLineSeg.A.Position.x,
                                                       nearestLineSeg.A.Position.y, nearestLineSeg.B.Position.x, nearestLineSeg.B.Position.y, out crossingX, out crossingY) == 0)
                {
                    ctrV = nxtV;
                    nxtV = LineFuctions.RotateVecPFromI(pt, -30, ctrV);
                    tmp  = lst.AddAfter(tmp, new Vertex(ctrV, someIdx++));
                }
                else
                {
                    tmp             = lst.AddAfter(tmp, new Vertex(new Vector2(crossingX, crossingY), someIdx++));
                    weHaveIntersect = true;
                    intersectionLineSeg.RemoveAt(0);
                }

                //gizmosLineSegs.Add(new LineSegment(new Vertex(ctrV,/*idx*/ 1000), new Vertex(nxtV,/*idx*/ 1000)));
                // lst.ad


                //kuzwa nie da rady tak trzeba wyliczyc wszystkie intersekcje i zapameitywac gdzie byly z jakimi odcinkami i potem na podstawie
                //tych info dodawac te vertexy.
                //patrzysz jeszcze czy to jest intersekcja wejsciowa czy wyjsciowa.
                //mozna dwie listy bo potem tylko szukasz intersekcji wyjsciowych.
                //to lecisz to tych intesekcjach z odcinkami wedle clockwise i bierzesz pierwsza ktora jest pod wzgledem wielkosci konta.
                //czyli wyjsciowa intersekcja odcninkowa z najmniejszym katem clockwise co do obecnej wejsciowej.
            }
        }



        for (int i = 0; i < VertToRemoveLst.Count; i++)
        {
            lst.Remove(VertToRemoveLst[i]);
        }



        for (int i = 0; i < lst.Count; i++)
        {
            Debug.Log(lst[i].Value);
        }



        ApplyNewPointsFromLst(lst);
    }