Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        Vector3 newPos = (transform.position + (movement * speed * Time.deltaTime));

        int checker = 0;

        int delta = 1;

        while (!PlayerMovement.ValidToMoveTo(newPos) && (++checker < 500))
        {
            TryNextDir(delta);
            delta++;

            newPos = (transform.position + (movement * speed * Time.deltaTime));
        }

        if ((checker == 500) || (!PlayerMovement.ValidToMoveTo(newPos)))
        {
            MWRDebug.Log("Spritz Error!!!", MWRDebug.DebugLevels.INFLOOP1);
        }

        Line           moveLine = new Line(transform.position, newPos);
        PlayerMovement pm       = GameObject.Find("Player").GetComponent <PlayerMovement>();

        if (pm.DrawingLineIntersects(moveLine))
        {
            pm.Dead();
        }

        Line currentVec = new Line(transform.position, newPos);

        pm.KillIfDrawingLineIntersects(currentVec);

        transform.position = newPos;
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        timeSinceLastChange += Time.deltaTime;

        if (timeSinceLastChange > changeTime)
        {
            timeSinceLastChange -= changeTime;
            movement             = GetRandomUnitVector(ref angle, maxAngle);
        }

        Vector3 newPos = (position + (movement * speed * Time.deltaTime));

        int checker = 0;

        while (!PlayerMovement.ValidToMoveTo(newPos) && (++checker < 500))
        {
            movement = GetRandomUnitVector(out angle);
            newPos   = (position + (movement * speed * Time.deltaTime));
        }

        if (checker == 500)
        {
            MWRDebug.Log("QixError1!!!", MWRDebug.DebugLevels.INFLOOP1);
        }

        Line           moveLine = new Line(position, newPos);
        PlayerMovement pm       = GameObject.Find("Player").GetComponent <PlayerMovement>();

        if (pm.DrawingLineIntersects(moveLine))
        {
            pm.Dead();
        }

        position = newPos;

        norm = DynamicLines.GetNormal(ref movement).normalized;

        start = position + norm * len;
        end   = position - norm * len;

        Line currentVec = new Line(start, end);

        pm.KillIfDrawingLineIntersects(currentVec);

        timeSinceLastEnque += Time.deltaTime;

        if (timeSinceLastEnque > enquePeriod)
        {
            timeSinceLastEnque -= enquePeriod;
            lineQueue.Enqueue(currentVec);

            while (lineQueue.Count > maxQueueLength)
            {
                lineQueue.Dequeue();
            }
        }

        GetComponent <MeshFilter>().mesh = DynamicLines.GetMesh(lineQueue.ToArray(), 0.01f);
    }
Exemplo n.º 3
0
    private void NewWay()
    {
        MWRDebug.Log("New rects");



        List <Rect> sourceRects;
        float       z = 0.03f;



        int verticesOffset;
        int uvOffset;
        int triangleOffset;

        if ((newRectList != null) && true)
        {
            // OK, adding entries
            //mesh =  GetComponent<MeshFilter>().mesh;

            //vertices = mesh.vertices;
            //uv = mesh.uv;
            //triangles = mesh.triangles;

            verticesOffset = vertices.Length;
            uvOffset       = uv.Length;
            triangleOffset = triangles.Length;

            System.Array.Resize(ref vertices, vertices.Length + newRectList.Count * 4);
            System.Array.Resize(ref uv, uv.Length + newRectList.Count * 4);
            System.Array.Resize(ref triangles, triangles.Length + newRectList.Count * 6);

            //verticesOffset = vertices.Length;
            //uvOffset = uv.Length;
            //triangleOffset = triangles.Length;

            //vertices = new Vector3[newRectList.Count * 4];
            //uv = new Vector2[newRectList.Count * 4];
            //triangles = new int[newRectList.Count * 6];



            sourceRects = newRectList;
        }
        else
        {
            // OK, completely new list

            mesh = new Mesh();

            vertices  = new Vector3[rects.Count * 4];
            uv        = new Vector2[rects.Count * 4];
            triangles = new int[rects.Count * 6];

            verticesOffset = 0;
            uvOffset       = 0;
            triangleOffset = 0;

            sourceRects = rects;

            score = 0.0f;
        }

        Rect rect;

        for (int ii = 0; ii < sourceRects.Count; ii++)
        {
            rect = sourceRects[ii];

            vertices[verticesOffset + ii * 4 + 0] = new Vector3(rect.xMax, rect.yMax, z);
            vertices[verticesOffset + ii * 4 + 1] = new Vector3(rect.xMax, rect.yMin, z);
            vertices[verticesOffset + ii * 4 + 2] = new Vector3(rect.xMin, rect.yMax, z);
            vertices[verticesOffset + ii * 4 + 3] = new Vector3(rect.xMin, rect.yMin, z);

            uv[uvOffset + ii * 4 + 0] = new Vector2(1, 1);
            uv[uvOffset + ii * 4 + 1] = new Vector2(1, 0);
            uv[uvOffset + ii * 4 + 2] = new Vector2(0, 1);
            uv[uvOffset + ii * 4 + 3] = new Vector2(0, 0);

            triangles[triangleOffset + ii * 6 + 0] = (verticesOffset + 4 * ii + 0);
            triangles[triangleOffset + ii * 6 + 1] = (verticesOffset + 4 * ii + 1);
            triangles[triangleOffset + ii * 6 + 2] = (verticesOffset + 4 * ii + 2);
            triangles[triangleOffset + ii * 6 + 3] = (verticesOffset + 4 * ii + 2);
            triangles[triangleOffset + ii * 6 + 4] = (verticesOffset + 4 * ii + 1);
            triangles[triangleOffset + ii * 6 + 5] = (verticesOffset + 4 * ii + 3);

            score += (rect.width * rect.height);
        }

        mesh.vertices  = vertices;
        mesh.uv        = uv;
        mesh.triangles = triangles;
        mesh.RecalculateNormals();

        ScoreManager.Score = score;

        GetComponent <MeshFilter>().mesh = mesh;

        newRects = false;
    }
Exemplo n.º 4
0
    private void OldWay()
    {
        MWRDebug.Log("New rects");

        float score = 0.0f;

        Mesh  mesh = new Mesh();
        float z    = 0.03f;

        List <Vector3> verticesList = new List <Vector3>();
        List <Vector2> uvList       = new List <Vector2>();
        List <int>     triangleList = new List <int>();

        int rectCount = 0;

        foreach (var rect in rects)
        {
            MWRDebug.Log("Rect + " + rectCount);
            MWRDebug.Log("Rect:" + " " + rect.xMin + " " + rect.xMax + " " + rect.yMin + " " + rect.yMax);

            verticesList.Add(new Vector3(rect.xMax, rect.yMax, z));
            verticesList.Add(new Vector3(rect.xMax, rect.yMin, z));
            verticesList.Add(new Vector3(rect.xMin, rect.yMax, z));
            verticesList.Add(new Vector3(rect.xMin, rect.yMin, z));

            uvList.Add(new Vector2(1, 1));
            uvList.Add(new Vector2(1, 0));
            uvList.Add(new Vector2(0, 1));
            uvList.Add(new Vector2(0, 0));

            triangleList.Add(4 * rectCount + 0);
            triangleList.Add(4 * rectCount + 1);
            triangleList.Add(4 * rectCount + 2);
            triangleList.Add(4 * rectCount + 2);
            triangleList.Add(4 * rectCount + 1);
            triangleList.Add(4 * rectCount + 3);

            rectCount++;
            score += (rect.width * rect.height);
        }

        ScoreManager.Score = score;

        Vector3[] vertices  = verticesList.ToArray();
        Vector2[] uv        = uvList.ToArray();
        int[]     triangles = triangleList.ToArray();

        mesh.vertices  = vertices;
        mesh.uv        = uv;
        mesh.triangles = triangles;
        mesh.RecalculateNormals();

        MWRDebug.Log("V" + mesh.vertexCount + "," + mesh.vertices.Length);
        MWRDebug.Log("U" + mesh.uv.Length);
        MWRDebug.Log("T" + mesh.triangles.Length);

        GetComponent <MeshFilter>().mesh = mesh;

        newRects    = false;
        newRectList = null;
    }
Exemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        if (newLines)
        {
            Mesh  mesh = new Mesh();
            float w    = 0.01f;

            List <Vector3> verticesList = new List <Vector3>();
            List <Vector2> uvList       = new List <Vector2>();
            List <int>     trianleList  = new List <int>();

            Vector3 start, end;
            int     lineCounter = 0;

            foreach (var line in lines)
            {
                start = line.start;
                end   = line.end;

                if (start.x < end.x)
                {
                    //MWRDebug.Log("xxx1:" + lineCounter);
                    verticesList.Add(end + new Vector3(w, w, 0.0f));
                    verticesList.Add(end + new Vector3(w, -w, 0.0f));
                    verticesList.Add(start + new Vector3(-w, w, 0.0f));
                    verticesList.Add(start + new Vector3(-w, -w, 0.0f));
                }
                else if (start.x > end.x)
                {
                    //MWRDebug.Log("xxx2:" + lineCounter);
                    verticesList.Add(start + new Vector3(w, w, 0.0f));
                    verticesList.Add(start + new Vector3(w, -w, 0.0f));
                    verticesList.Add(end + new Vector3(-w, w, 0.0f));
                    verticesList.Add(end + new Vector3(-w, -w, 0.0f));
                }
                else if (start.y < end.y)
                {
                    //MWRDebug.Log("xxx3:" + lineCounter);
                    verticesList.Add(end + new Vector3(w, w, 0.0f));
                    verticesList.Add(start + new Vector3(w, -w, 0.0f));
                    verticesList.Add(end + new Vector3(-w, w, 0.0f));
                    verticesList.Add(start + new Vector3(-w, -w, 0.0f));
                }
                else
                {
                    //MWRDebug.Log("xxx4:" + lineCounter);
                    verticesList.Add(start + new Vector3(w, w, 0.0f));
                    verticesList.Add(end + new Vector3(w, -w, 0.0f));
                    verticesList.Add(start + new Vector3(-w, w, 0.0f));
                    verticesList.Add(end + new Vector3(-w, -w, 0.0f));
                }

                uvList.Add(new Vector2(1, 1));
                uvList.Add(new Vector2(1, 0));
                uvList.Add(new Vector2(0, 1));
                uvList.Add(new Vector2(0, 0));

                trianleList.Add(4 * lineCounter + 0);
                trianleList.Add(4 * lineCounter + 1);
                trianleList.Add(4 * lineCounter + 2);
                trianleList.Add(4 * lineCounter + 2);
                trianleList.Add(4 * lineCounter + 1);
                trianleList.Add(4 * lineCounter + 3);

                lineCounter++;
            }

            Vector3[] vertices  = verticesList.ToArray();
            Vector2[] uv        = uvList.ToArray();
            int[]     triangles = trianleList.ToArray();

            mesh.vertices  = vertices;
            mesh.uv        = uv;
            mesh.triangles = triangles;
            mesh.RecalculateNormals();

            MWRDebug.Log("V" + mesh.vertexCount + "," + mesh.vertices.Length);
            MWRDebug.Log("U" + mesh.uv.Length);
            MWRDebug.Log("T" + mesh.triangles.Length);

            GetComponent <MeshFilter>().mesh = mesh;

            newLines = false;
        }
    }
Exemplo n.º 6
0
 public void Dead()
 {
     MWRDebug.Log("KILLED BY QIX", MWRDebug.DebugLevels.ALWAYS);
     ScoreManager.Dead = true;
 }
Exemplo n.º 7
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");
    }
Exemplo n.º 8
0
 void LogTimeDelta(string s)
 {
     MWRDebug.Log("Time " + (Time.realtimeSinceStartup - startTime) + ": " + s + "++++++++++++++++++++++++++");
 }
Exemplo n.º 9
0
    // Update is called once per frame
    void Update()
    {
        //MWRDebug.Log("Fuse update");

        if (dead)
        {
            MWRDebug.Log("Dead");
            return;
        }

        PlayerMovement mov = GameObject.Find("Player").GetComponent <PlayerMovement>();

        var lines = mov.GetDrawingLinesInclLive().ToArray();

        if (lines.Length == 0)
        {
            //MWRDebug.Log("No line");
            inMotion        = false;
            givingHeadStart = false;
            gameObject.GetComponent <Renderer>().enabled = false;
        }
        else if (!givingHeadStart)
        {
            MWRDebug.Log("Giving headstart");
            givingHeadStart = true;
            startWaitTime   = Time.time;
        }
        else if ((!inMotion) && ((Time.time - startWaitTime) > headstart))
        {
            MWRDebug.Log("Starting");
            gameObject.GetComponent <Renderer>().enabled = true;
            inMotion = true;

            transform.position = lines[0].start;
            lineIndex          = 0;
        }

        if (inMotion)
        {
            MWRDebug.Log("In motion");

            float distToMove = speed * Time.deltaTime;

            int checker = 0;
            while ((distToMove >= 0.0f) && (++checker < 5))
            {
                Vector3 toEndOfLine     = lines[lineIndex].end - transform.position;
                float   distToEndOfLine = toEndOfLine.magnitude;

                MWRDebug.Log("Dists " + distToEndOfLine + " vs. " + distToMove + ".  Indices " + lineIndex + " vs. " + lines.Length);

                if (distToEndOfLine > distToMove)
                {
                    MWRDebug.Log("End of line too far");
                    transform.position += toEndOfLine.normalized * distToMove;
                    break;
                }
                else
                {
                    MWRDebug.Log("Can reach end of line");

                    transform.position = lines[lineIndex].end;
                    distToMove        -= distToEndOfLine;

                    if (lineIndex == (lines.Length - 1))
                    {
                        MWRDebug.Log("Fused!");
                        dead = true;
                        ScoreManager.Dead = true;
                        break;
                    }
                    else
                    {
                        MWRDebug.Log("Move to next segment");
                        lineIndex++;
                    }
                }
            }

            if (checker == 5)
            {
                MWRDebug.Log("FuseERRROR", MWRDebug.DebugLevels.INFLOOP1);
            }
        }
    }
Exemplo n.º 10
0
    // Update is called once per frame
    void Update()
    {
        float distanceToTravel = speed * Time.deltaTime;

        Init();

        if (!initialized)
        {
            return;
        }

        int loopy = 0;

        do
        {
            loopy++;

            MWRDebug.Log("Loopy: " + loopy, MWRDebug.DebugLevels.INFLOOP1);
            MWRDebug.Log("Distance: " + distanceToTravel, MWRDebug.DebugLevels.INFLOOP1);
            MWRDebug.Log("Dir: " + dir, MWRDebug.DebugLevels.INFLOOP1);
            MWRDebug.Log("Line: " + currentLine.start + "->" + currentLine.end, MWRDebug.DebugLevels.INFLOOP1);

            switch (dir)
            {
            case Direction.StartToEnd:
            {
                float   distToEnd = 0.0f;
                Vector3 end       = Vector3.zero;

                distToEnd = (currentLine.end - transform.position).magnitude;

                // Can't reach the end
                if (distToEnd < distanceToTravel)
                {
                    pm.KillIfPlayerInLine(new Line(transform.position, currentLine.end));

                    distanceToTravel  -= distToEnd;
                    transform.position = currentLine.end;

                    MWRDebug.Log("Need new line!", MWRDebug.DebugLevels.INFLOOP1);

                    foreach (Line line in pm.lines)
                    {
                        if (line.ContainsBound(currentLine.end) && (line != currentLine))
                        {
                            currentLine = line;

                            if ((line.end - transform.position).magnitude < (line.start - transform.position).magnitude)
                            {
                                // Go to the long way
                                dir = Direction.EndToStart;
                            }
                            else
                            {
                                dir = Direction.StartToEnd;
                            }

                            MWRDebug.Log("Found Line: " + line.start + "->" + line.end, MWRDebug.DebugLevels.INFLOOP1);
                            break;
                        }
                    }
                }
                else
                {
                    Vector3 newPos = (transform.position + distanceToTravel * (currentLine.end - transform.position).normalized);

                    pm.KillIfPlayerInLine(new Line(transform.position, newPos));
                    transform.position = newPos;

                    distanceToTravel = 0.0f;
                }
            }

            break;

            case Direction.EndToStart:
            {
                float   distToEnd = 0.0f;
                Vector3 end       = Vector3.zero;

                distToEnd = (currentLine.start - transform.position).magnitude;

                // Can't reach the end
                if (distToEnd < distanceToTravel)
                {
                    pm.KillIfPlayerInLine(new Line(transform.position, currentLine.start));

                    distanceToTravel  -= distToEnd;
                    transform.position = currentLine.start;

                    foreach (Line line in pm.lines)
                    {
                        if (line.ContainsBound(currentLine.start) && (line != currentLine))
                        {
                            currentLine = line;

                            if ((line.end - transform.position).magnitude < (line.start - transform.position).magnitude)
                            {
                                // Go to the long way
                                dir = Direction.EndToStart;
                            }
                            else
                            {
                                dir = Direction.StartToEnd;
                            }
                        }

                        break;
                    }
                }
                else
                {
                    Vector3 newPos = (transform.position + distanceToTravel * (currentLine.start - transform.position).normalized);

                    pm.KillIfPlayerInLine(new Line(transform.position, newPos));
                    transform.position = newPos;

                    distanceToTravel = 0.0f;
                }
            }

            break;
            }
        } while ((distanceToTravel > 0.0f) && (loopy < 5));

        if (loopy == 5)
        {
            MWRDebug.Log("Oh dear", MWRDebug.DebugLevels.INFLOOP1);
        }
    }