Beispiel #1
0
    /// <summary>
    /// randomly chooses neighboured floes to create a path.
    /// begins with the floe on which the player is standing.
    /// chosen floes get a pathId and their parameter "isGoodFloe" becomes true
    /// </summary>
    private void CreatePath()
    {
        int            nextPath = 0;
        int            lastID   = 0;
        List <IceFloe> tempList = new List <IceFloe>();

        // if floe list is not empty
        if (floeList.Count != 0)
        {
            // first floe in the path is the startFloe
            startFloe.SetIsGoodFloe(true);
            pathList.Add(startFloe);
            usedFieldsList.Add(startFloe.GetID());
            startPosition = startFloe.GetPosition();

            int counter = 1;

            for (int x = 0; x <= 2000; x++)
            {
                for (int j = 0; j < floeList.Count; j++)
                {
                    if (startPosition == pathList[0].GetPosition())
                    {
                        // compare distance with a value that is relativ to the spawnDistance (sp.d.= 0.8 -> value = 1)
                        if (Vector3.Distance(startPosition, floeList[j].GetPosition()) <= (spawnDistance * 1.25f))
                        {
                            tempList.Add(floeList[j]);
                            usedFieldsList.Add(j);
                        }
                    }
                    else if (!usedFieldsList.Contains(j))
                    {
                        if (Vector3.Distance(startPosition, floeList[j].GetPosition()) <= (spawnDistance * 1.25f))
                        {
                            tempList.Add(floeList[j]);
                            usedFieldsList.Add(j);
                        }
                    }
                }

                // randomly choose which floe to add to the path
                nextPath = Random.Range(0, tempList.Count - 1);
                if (nextPath < tempList.Count)
                {
                    if (!pathList.Contains(tempList[nextPath]))
                    {
                        pathList.Add(tempList[nextPath]);
                        counter++;
                    }
                    startPosition = tempList[nextPath].GetPosition();
                }
                tempList.Clear();

                if (counter >= maxPathLength)
                {
                    break;
                }
            }

            // set isGood tags and pathID of all floes in pathList
            foreach (IceFloe iceFloe in pathList)
            {
                iceFloe.SetIsGoodFloe(true);
                iceFloe.SetPathID(lastID);
                if (paintPath)
                {
                    iceFloe.ChangeColor(true);
                }
                lastID++;
            }

            finalPathFloeID = pathList.Count - 1;
            print("Path with " + pathList.Count + " floes created.");
        }
        else
        {
            print("CreatePath(): floe list is empty");
        }
    }
Beispiel #2
0
    /// <summary>
    /// reaction to the step on a floe
    /// </summary>
    /// <param name="floe">entered floe</param>
    void FloeEnter(IceFloe floe)
    {
        int pathID = floe.GetPathID();

        if (iceFloePathList != null)
        {
            // enter good floe
            if (floe.GetIsGoodFloe())
            {
                // enter final floe
                if (pathID == iceFloeManager.finalPathFloeID)
                {
                    currentFloeID = floe.GetID();
                    currentFloe   = iceFloeManager.GetFloeList()[pathID];
                    Finish();
                }

                // player moved to the next floe -> change color (only after level 1)
                else if (pathID != currentFloeID && currentLevel > 1)
                {
                    // beginning of the path
                    if (currentFloeID == 0 || currentFloeID == 1)       // whole path was visible at the beginning, because player was standing on the first floe
                    {
                        for (int i = pathID + 1; i < iceFloePathList.Count - 1; i++)
                        {
                            iceFloePathList[i].ChangeColor(false);      // hide the color of all other path floes (except of the first two)
                        }

                        iceFloePathList[pathID].ChangeColor(true);      // change color of the floe the player stepped on to "good"

                        if (pathID + currentLevel < iceFloePathList.Count)
                        {
                            iceFloePathList[pathID + currentLevel].ChangeColor(true);  // show the color of the floe after the next (gap becomes bigger with higher level)
                        }
                    }

                    // somewhere in between the path
                    else
                    {
                        iceFloePathList[pathID].ChangeColor(true);                          // change color of the floe the player stepped on to "good"
                        if (pathID + currentLevel - 1 < iceFloePathList.Count - 1)
                        {
                            iceFloePathList[pathID + currentLevel - 1].ChangeColor(false);    // hide the color of the next floe
                            if (pathID + currentLevel < iceFloePathList.Count)
                            {
                                iceFloePathList[pathID + currentLevel].ChangeColor(true);   // show the color of the floe after the next (gap becomes bigger with higher level)
                            }
                        }
                    }
                }
                waitingForDeath = false;
            }

            // enter bad floe -> die
            else
            {
                waitingForDeath = true;
            }

            currentFloeID = floe.GetID();
            currentFloe   = iceFloeManager.GetFloeList()[floe.GetID()];
        }
    }