コード例 #1
0
    private void ChangePavilon()
    {
        Pavilon randomPavilon;

        // Pick new one until different barriers is picked
        do
        {
            randomPavilon = PickRandomPavilon(listOfAllPavilons);
        } while (randomPavilon == currentPavilon);

        currentPavilon = randomPavilon;
        Debug.Log("Current pavilon: " + currentPavilon.GetPavilonName());
    }
コード例 #2
0
    // Use this for initialization
    void Start()
    {
        teethPavilon = new TeethPavilon(listOfTeethBarriers);
        seaPavilon = new SeaPavilon(listOfSeaBarriers);
        spacePavilon = new SpacePavilon(listOfSpaceBarriers);
        // TODO: Initialize other pavilons by their type (PavilonType : Pavilon)

        // Load all barriers and their initial position
        // TODO: Add other pavilons to the list of all pavilons
        listOfAllPavilons = new List<Pavilon>() { teethPavilon, seaPavilon, spacePavilon };

        foreach (var pavilon in listOfAllPavilons)
        {
            foreach (var barrier in pavilon.GetBarriers())
            {
                barrier.SetActive(false);
                pavilon.LoadInitialPosition(barrier);
            }
        }

        /* Choose current pavilon and the first barrier.
        We always want to start with the first barrier of the teeth pavilon
        which has good starting conditions (some space at the beginning), but
        first we must choose any barrier prior to the first one to act as a "scenery". */
        currentPavilon = teethPavilon;
        //firstBarrier = currentPavilon.GetBarriers().First();
        firstBarrier = PickRandomBarrier(currentPavilon.GetBarriers().Skip(1).ToList());

        // Get screen width and height + world coordinates of axis x
        int screenPixelWidth = Camera.main.pixelWidth;
        int screenPixelHeight = Camera.main.pixelHeight;
        worldCoordX = Camera.main.ScreenToWorldPoint(new Vector2(screenPixelWidth, screenPixelHeight))[0];

        // Set first barrier and its length
        firstBarrier.SetActive(true);
        queueOfBarriers = new Queue<GameObject>();
        queueOfBarriers.Enqueue(firstBarrier);
        barrierLengthInCurrentPavilon = currentPavilon.GetBarrierLength();

        // First barrier must be shifted a bit to the left; translate the first barrier to suitable position
        firstBarrier.transform.Translate(new Vector2(Camera.main.transform.position[0] - firstBarrier.transform.position.x - 20f,
                                                     Camera.main.transform.position[1]));
        lastBarrier = firstBarrier;

        // Set second barrier just to be sure; generate next barriers with Update()
        GenerateBarrier(currentPavilon.GetBarriers().First());
        GenerateBarrier();

        // Two barriers generated so far
        currentObstacleRepetition = 3;
        xGenerationOffset = 5;
    }