예제 #1
0
    private Vector3 m_LineStartPoint;     // 線引き中に被弾した場合、線引き開始地点に戻すために使用


    void Awake()
    {
        m_Marker = GameObject.FindWithTag("Marker").GetComponent <Marker>();
        m_Map    = GameObject.FindWithTag("Map").GetComponent <Map>();

        //m_Map.PreareMap();
        m_Qix = GameObject.FindWithTag("Qix").GetComponent <Qix>();
    }
예제 #2
0
    private float FloodFill(int w,
                            int h,
                            bool[,] vsides,
                            bool[,] hsides,
                            List <Rect> drawRects,
                            int fillx1,
                            int filly1,
                            out bool containsBaddy,
                            Qix theQix)
    {
        float            nArea = 0.0f;
        Queue <IntTuple> queue = new Queue <IntTuple>();

        bool[,] floodRects = new bool[w - 1, h - 1];
        queue.Enqueue(new IntTuple(fillx1, filly1));

        containsBaddy = false;

        while (queue.Count > 0)
        {
            IntTuple tuple = queue.Dequeue();
            if (!floodRects[tuple.x, tuple.y])
            {
                floodRects[tuple.x, tuple.y] = true;
                Rect rect = new Rect(xVector3s[tuple.x], yVector3s[tuple.y], xVector3s[tuple.x + 1] - xVector3s[tuple.x], yVector3s[tuple.y + 1] - yVector3s[tuple.y]);
                drawRects.Add(rect);

                if (!containsBaddy && rect.Contains(theQix.position))
                {
                    containsBaddy = true;
                }

                nArea += ((xVector3s[tuple.x + 1] - xVector3s[tuple.x]) * (yVector3s[tuple.y + 1] - yVector3s[tuple.y]));

                if ((tuple.x > 0) && (!vsides[tuple.x - 1, tuple.y]))
                {
                    // Can move left
                    JustLog("Left->(" + (tuple.x - 1) + "," + tuple.y + ")");
                    queue.Enqueue(new IntTuple(tuple.x - 1, tuple.y));
                }

                if ((tuple.x < (w - 2)) && (!vsides[tuple.x, tuple.y]))
                {
                    // Can move right
                    JustLog("Right->(" + (tuple.x + 1) + "," + tuple.y + ")");
                    queue.Enqueue(new IntTuple(tuple.x + 1, tuple.y));
                }

                if ((tuple.y > 0) && (!hsides[tuple.x, tuple.y - 1]))
                {
                    // Can move down
                    JustLog("Down->(" + tuple.x + "," + (tuple.y - 1) + ")");
                    queue.Enqueue(new IntTuple(tuple.x, tuple.y - 1));
                }

                if ((tuple.y < (h - 2)) && (!hsides[tuple.x, tuple.y]))
                {
                    // Can move up
                    JustLog("Up->(" + tuple.x + "," + (tuple.y + 1) + ")");
                    queue.Enqueue(new IntTuple(tuple.x, tuple.y + 1));
                }
            }
        }
        return(nArea);
    }
예제 #3
0
    void FillDrawnArea()
    {
        SetLogStartTime();
        LogTimeDelta("Start");

        // Get dimensions
        int w = xVector3s.Count;
        int h = yVector3s.Count;

        // Work out edges.
        // @@ Issue: includes irrelevant internal edges
        bool[,] vsides = new bool[w - 1, h];
        bool[,] hsides = new bool[w, h - 1];
        MapLinesToSides(vsides, hsides, drawingLines);
        MapLinesToSides(vsides, hsides, lines);

        // Work out where our floo start Vector3s are.
        int fillx1;
        int filly1;
        int fillx2;
        int filly2;

        ExtractFloodStartVector3s(out fillx1, out filly1, out fillx2, out filly2);

        // Flood fill from each of the two places.
        List <Rect> drawRects1 = new List <Rect>();
        List <Rect> drawRects2 = new List <Rect>();
        float       area1      = 0.0f;
        float       area2      = 0.0f;

        bool baddyIn1;
        bool baddyIn2;

        Qix theQix = GameObject.Find("TheQix").GetComponent <Qix>();

        area1 = FloodFill(w, h, vsides, hsides, drawRects1, fillx1, filly1, out baddyIn1, theQix);
        area2 = FloodFill(w, h, vsides, hsides, drawRects2, fillx2, filly2, out baddyIn2, theQix);

        // Fill the appropriate area.
        // @@ Issue: we just do the smallest here - it should be the one without the baddy

        if (false)
        {
            if (area1 < area2)
            {
                DrawRects.AddRects(drawRects1);
            }
            else
            {
                DrawRects.AddRects(drawRects2);
            }
        }
        else
        {
            bool dump = false;

            if (!baddyIn1 && !baddyIn2)
            {
                MWRDebug.Log("In neither", MWRDebug.DebugLevels.INFLOOP1);
                dump = true;
            }
            else if (baddyIn1 && baddyIn2)
            {
                MWRDebug.Log("In both", MWRDebug.DebugLevels.INFLOOP1);
                dump = true;
            }

            if (dump)
            {
                string s = "Qix at " + theQix.position + "\r\n";

                s += "Rects1...(" + baddyIn1 + ")\r\n";

                foreach (Rect r in drawRects1)
                {
                    s += r;
                    s += (r.Contains(theQix.position));
                }

                s += "Rects2...(" + baddyIn2 + ")\r\n";

                foreach (Rect r in drawRects2)
                {
                    s += r;
                    s += (r.Contains(theQix.position));
                }

                MWRDebug.DumpToTraceFile(s);
            }

            if (baddyIn2)
            {
                AddRectsToDeadZone(drawRects1);
            }
            else
            {
                AddRectsToDeadZone(drawRects2);
            }
        }

        LogTimeDelta("End");
    }