Ejemplo n.º 1
0
    /*
     * soll sich vom start nach rechts bewegen      => beforzugt abigen richting rechts
     * nocht aus dem bilschrim kommen               => beforzugt beim abbigen reichting mitte
     * nur dei bestimmte anzual an ecken machen     => random + length / ecken
     */

    private void Generate()
    {
        placer.PlacePathHiddenAt(StartX, StartY);

        lastX = StartX;
        lastY = StartY;

        nowX = StartX;
        nowY = StartY;

        int dirX = 1, dirY = 0;

        for (lengthMade = 1; lengthMade <= maxLenght; lengthMade++)
        {
            Debug.Log(lengthMade);
            if (ToMakeTurn() && !neededForceRotate)
            {
                cornersMade++;
                Debug.Log("turn");

                if (ToTurnLeft())
                {
                    if (dirX == 1)
                    {
                        dirY = 1;
                        dirX = 0;
                    }
                    else if (dirX == -1)
                    {
                        dirY = -1;
                        dirX = 0;
                    }
                    else if (dirY == 1)
                    {
                        dirY = 0;
                        dirX = -1;
                    }
                    else if (dirY == -1)
                    {
                        dirY = 0;
                        dirX = 1;
                    }
                }
                else
                {
                    if (dirX == 1)
                    {
                        dirY = -1;
                        dirX = 0;
                    }
                    else if (dirX == -1)
                    {
                        dirY = 1;
                        dirX = 0;
                    }
                    else if (dirY == 1)
                    {
                        dirY = 0;
                        dirX = 1;
                    }
                    else if (dirY == -1)
                    {
                        dirY = 0;
                        dirX = -1;
                    }
                }
            }

            if (neededForceRotate)
            {
                neededForceRotate = false;
            }

            lastX = nowX;
            lastY = nowY;

            nowX += dirX;
            nowY += dirY;

            if (!placer.CheckBound(nowX + dirX, nowY + dirY))
            {
                neededForceRotate = true;
                Debug.Log("FUCKFFFFFFFFFFFFFFFFFFFFF");
                if (lastY == nowY)
                {
                    if (nowX < 0)
                    {
                        nowY += -1 - dirY;
                        dirY  = -1;
                    }
                    else
                    {
                        nowY += 1 - dirY;
                        dirY  = 1;
                    }

                    nowX += -dirX;
                    dirX  = 0;
                }
                else
                {
                    if (placer.CheckBound(nowX + 2, nowY - dirY))
                    {
                        nowX += 1 - dirX;
                        dirX  = 1;
                    }
                    else
                    {
                        nowX += -1 - dirX;
                        dirX  = -1;
                    }
                    nowY -= dirY;
                    dirY  = 0;
                }
            }

            placer.PlacePathHiddenAt(nowX, nowY);
        }

        placer.PalceTile(nowX, nowY, "G");
        placer.SetActive(StartX, StartY);

        placer.Show();
    }