Example #1
0
    private void notifyParts()
    {
        MapPartController southPartController = southPart.GetComponent <MapPartController>();
        MapPartController northPartController = northPart.GetComponent <MapPartController>();

        southPartController.setNorthPart(northPartController); //ova linija obavještava početni komad (južni) da je sjeverno od njega stvoren novi dio (sjeverni).
                                                               //Ta metoda je bitna za povezivanje dijelova mape (konkretno - ovom linijom točke na sjevernom rubu
                                                               //južnog dijela će biti spojene s točkama na južnom rubu sjevernog dijela).
                                                               //Kad ove metode ne bi bile pozvane, pješaci ne bi mogli prelaziti s jednih dijelova mape na druge.

        northPartController.setSouthPart(southPartController); //analogno prethodnoj liniji
    }
 /// <summary>
 /// Sets the north adjacent map part. When it is determined what map part is to the north 
 /// of this one, link method is invoked, and waypoints that are on the north 
 /// side of this map part get the reference to the waypoints that are on the south side 
 /// of the north adjacent part.
 /// </summary>
 /// <param name="northPart">Reference to the script that controlls the map part to the north 
 /// of this one.</param>
 public void setNorthPart(MapPartController northPart)
 {
     this.northPart = northPart;
     link(northPart, "southLink", "northLink");
 }
 /// <summary>
 /// Sets the east adjacent map part. When it is determined what map part is to the east 
 /// of this one, link method is invoked, and waypoints that are on the east 
 /// side of this map part get the reference to the waypoints that are on the west side 
 /// of the east adjacent part.
 /// </summary>
 /// <param name="eastPart">Reference to the script that controlls the map part to the east 
 /// of this one.</param>
 public void setEastPart(MapPartController eastPart)
 {
     this.eastPart = eastPart;
     link(eastPart, "westLink", "eastLink");
 }
 /// <summary>
 /// This method is invoked once a new map part is generated next to this one. Waypoints on 
 /// the edge of the new part (source part) will be linked to the waypoints on this part if 
 /// their link types match. For example, a new north part (source part) contains waypoints 
 /// of type southLink (newLinkType). Those waypoints are linked to waypoints on this part 
 /// that are of type northLink (thisLinkType).
 /// </summary>
 /// <param name="sourcePart">Script that holds references to new waypoints.</param>
 /// <param name="newLinkType">Waypoints of this type on the source part will get linked to the 
 /// waypoints of thisLinkType on this part.</param>
 /// <param name="thisLinkType">Waypoints of this type on this map part will be linked to the 
 /// waypoints on source part of type newLinkType.</param>
 private void link(MapPartController sourcePart, string newLinkType, string thisLinkType)
 {
     List<Transform> newWaypoints = new List<Transform>();
     foreach(Transform waypoint in sourcePart.transform.Find("Waypoints")) {
         PointDescriptor pointScript = waypoint.GetComponent<PointDescriptor>();
         switch(newLinkType) {
             case "northLink":
                 if(pointScript.isNorthLink) {
                     newWaypoints.Add(waypoint);
                 }
                 break;
             case "eastLink":
                 if(pointScript.isEastLink) {
                     newWaypoints.Add(waypoint);
                 }
                 break;
             case "southLink":
                 if(pointScript.isSouthLink) {
                     newWaypoints.Add(waypoint);
                 }
                 break;
             case "westLink":
                 if(pointScript.isWestLink) {
                     newWaypoints.Add(waypoint);
                 }
                 break;
         }
     }
     Transform waypoints = transform.Find("Waypoints");
     foreach(Transform waypoint in waypoints) {
         PointDescriptor pointScript = waypoint.GetComponent<PointDescriptor>();
         switch(thisLinkType) {
             case "northLink":
                 if(pointScript.isNorthLink) {
                     addNewWaypointsToCurrentOne(newWaypoints, pointScript);
                 }
                 break;
             case "eastLink":
                 if(pointScript.isEastLink) {
                     addNewWaypointsToCurrentOne(newWaypoints, pointScript);
                 }
                 break;
             case "southLink":
                 if(pointScript.isSouthLink) {
                     addNewWaypointsToCurrentOne(newWaypoints, pointScript);
                 }
                 break;
             case "westLink":
                 if(pointScript.isWestLink) {
                     addNewWaypointsToCurrentOne(newWaypoints, pointScript);
                 }
                 break;
         }
     }
 }
 /// <summary>
 /// Sets the west adjacent map part. When it is determined what map part is to the west 
 /// of this one, link method is invoked, and waypoints that are on the west 
 /// side of this map part get the reference to the waypoints that are on the east side 
 /// of the west adjacent part.
 /// </summary>
 /// <param name="westPart">Reference to the script that controlls the map part to the west 
 /// of this one.</param>
 public void setWestPart(MapPartController westPart)
 {
     this.westPart = westPart;
     link(westPart, "eastLink", "westLink");
 }
 /// <summary>
 /// Sets the south adjacent map part. When it is determined what map part is to the south 
 /// of this one, link method is invoked, and waypoints that are on the south 
 /// side of this map part get the reference to the waypoints that are on the north side 
 /// of the south adjacent part.
 /// </summary>
 /// <param name="southPart">Reference to the script that controlls the map part to the south 
 /// of this one.</param>
 public void setSouthPart(MapPartController southPart)
 {
     this.southPart = southPart;
     link(southPart, "northLink", "southLink");
 }
    private void iscrtajMapu()
    {
        bool playerPostoji = false;
        GameObject ovaj = GameObject.Find("WG_SpawnPoint");
        mapaBlokova = new GameObject[velicina_mape, velicina_mape];
        for (int i = 0; i < velicina_mape; i++)
            for (int j = 0; j < velicina_mape; j++)
            {
                GameObject noviBlok;
                Vector3 pomak = new Vector3((j) * velicina_blokova, 0, (i) * velicina_blokova);
                Quaternion zakret;

                switch (mapa[i][j].id)
                {
                    //  0: " "  1: "╨"  2: "╞"  3: "╚"
                    //  4: "╥"  5: "║"  6: "╔"  7: "╠"
                    //  8: "╡"  9: "╝"  10: "═" 11: "╩"
                    //  12: "╗" 13: "╣" 14: "╦" 15: "╬"
                    case 1: noviBlok = U[0];  break;
                    case 2: noviBlok = R[0];  break;
                    case 3: noviBlok = UR[0];  break;
                    case 4: noviBlok = D[0];  break;
                    case 5: noviBlok = UD[0]; break;
                    case 6: noviBlok = RD[0];  break;
                    case 7: noviBlok = URD[0];  break;
                    case 8: noviBlok = L[0];  break;
                    case 9: noviBlok = UL[0];  break;
                    case 10: noviBlok = RL[0];  break;
                    case 11: noviBlok = URL[0];  break;
                    case 12: noviBlok = DL[0];  break;
                    case 13: noviBlok = UDL[0];  break;
                    case 14: noviBlok = RDL[0];  break;
                    case 15: noviBlok = URDL[0];  break;

                    default:
                        noviBlok = null;
                        break;
                }
                if (!playerPostoji && mapa[i][j].id == 5)
                {
                    noviBlok = UD[UD.Length - 1];
                    playerPostoji = true;
                    playerxold = playerx = j;
                    playeryold = playery = i;
                }else if (!playerPostoji && mapa[i][j].id == 10)
                {
                    noviBlok = RL[RL.Length - 1];
                    playerPostoji = true;
                    playerxold = playerx = j;
                    playeryold = playery = i;
                }
                else if (Random.value < 0.25)
                {
                    float slucajan = Random.value;
                    if (slucajan == 1) slucajan = (float)0.99;
                    if (mapa[i][j].id == 10 && RL.Length > 2)
                    {

                        int broj = (int)(slucajan * (RL.Length - 2) + 1);
                        noviBlok = RL[broj];
                    }
                    if (mapa[i][j].id == 5 && UD.Length > 2)
                    {
                        int broj = (int)(slucajan * (UD.Length - 2) + 1);
                        noviBlok = UD[broj];
                    }
                }

                zakret = Quaternion.Euler(0, 0, 0);
                if (noviBlok != null)
                {
                    mapaBlokova[i, j] = ((GameObject)GameObject.Instantiate(noviBlok, pomak, zakret));
                    mapaBlokova[i, j].transform.parent = ovaj.transform;
                    //mapaBlokova[i, j].SetActive(false);
                }
            }

        MapPartController[,] matricaSkripti = new MapPartController[velicina_mape, velicina_mape];

        for (int i = 0; i < velicina_mape; i++)
            for (int j = 0; j < velicina_mape; j++)
                if (mapa[i][j].id > 0)
                    matricaSkripti[i, j] = mapaBlokova[i, j].GetComponent<MapPartController>();

        for (int i = 0; i < velicina_mape; i++)
            for (int j = 0; j < velicina_mape; j++)
            {

                if (mapa[i][j].id > 0)
                {
                    if (i > 0 && mapa[i - 1][j].id > 0)
                    {
                        matricaSkripti[i, j].setSouthPart(matricaSkripti[i - 1, j]);

                    }
                    if (i < velicina_mape - 1 && mapa[i + 1][j].id > 0)
                    {
                        matricaSkripti[i, j].setNorthPart(matricaSkripti[i + 1, j]);

                    }
                    if (j > 0 && mapa[i][j - 1].id > 0)
                    {
                        matricaSkripti[i, j - 1].setEastPart(matricaSkripti[i, j]);
                    }
                    if (j < velicina_mape - 1 && mapa[i][j + 1].id > 0)
                    {
                        matricaSkripti[i, j + 1].setWestPart(matricaSkripti[i, j]);
                    }

                }
            }

        foreach (elementZgrade zgrada in zgrade)
        {
            Vector3 position = new Vector3(((zgrada.x2 + zgrada.x1) / 2) * velicina_blokova, zgrada.visina*50 / 2, ((zgrada.y2 + zgrada.y1) / 2 * velicina_blokova));
            GameObject cube = ((GameObject)GameObject.Instantiate(prefabZgrada, position, Quaternion.Euler(0,0,0)));
            cube.transform.localScale = new Vector3((zgrada.x2 - zgrada.x1 + 1) * velicina_blokova, zgrada.visina*50, ((zgrada.y2 - zgrada.y1 + 1) * velicina_blokova));
            cube.transform.parent = ovaj.transform;
        }
    }
Example #8
0
 /// <summary>
 /// Sets the west adjacent map part. When it is determined what map part is to the west
 /// of this one, link method is invoked, and waypoints that are on the west
 /// side of this map part get the reference to the waypoints that are on the east side
 /// of the west adjacent part.
 /// </summary>
 /// <param name="westPart">Reference to the script that controlls the map part to the west
 /// of this one.</param>
 public void setWestPart(MapPartController westPart)
 {
     this.westPart = westPart;
     link(westPart, "eastLink", "westLink");
 }
Example #9
0
 /// <summary>
 /// Sets the south adjacent map part. When it is determined what map part is to the south
 /// of this one, link method is invoked, and waypoints that are on the south
 /// side of this map part get the reference to the waypoints that are on the north side
 /// of the south adjacent part.
 /// </summary>
 /// <param name="southPart">Reference to the script that controlls the map part to the south
 /// of this one.</param>
 public void setSouthPart(MapPartController southPart)
 {
     this.southPart = southPart;
     link(southPart, "northLink", "southLink");
 }
Example #10
0
 /// <summary>
 /// Sets the east adjacent map part. When it is determined what map part is to the east
 /// of this one, link method is invoked, and waypoints that are on the east
 /// side of this map part get the reference to the waypoints that are on the west side
 /// of the east adjacent part.
 /// </summary>
 /// <param name="eastPart">Reference to the script that controlls the map part to the east
 /// of this one.</param>
 public void setEastPart(MapPartController eastPart)
 {
     this.eastPart = eastPart;
     link(eastPart, "westLink", "eastLink");
 }
Example #11
0
    private MapPartController westPart  = null; //west adjacent map part

    /// <summary>
    /// Sets the north adjacent map part. When it is determined what map part is to the north
    /// of this one, link method is invoked, and waypoints that are on the north
    /// side of this map part get the reference to the waypoints that are on the south side
    /// of the north adjacent part.
    /// </summary>
    /// <param name="northPart">Reference to the script that controlls the map part to the north
    /// of this one.</param>
    public void setNorthPart(MapPartController northPart)
    {
        this.northPart = northPart;
        link(northPart, "southLink", "northLink");
    }
Example #12
0
    /// <summary>
    /// This method is invoked once a new map part is generated next to this one. Waypoints on
    /// the edge of the new part (source part) will be linked to the waypoints on this part if
    /// their link types match. For example, a new north part (source part) contains waypoints
    /// of type southLink (newLinkType). Those waypoints are linked to waypoints on this part
    /// that are of type northLink (thisLinkType).
    /// </summary>
    /// <param name="sourcePart">Script that holds references to new waypoints.</param>
    /// <param name="newLinkType">Waypoints of this type on the source part will get linked to the
    /// waypoints of thisLinkType on this part.</param>
    /// <param name="thisLinkType">Waypoints of this type on this map part will be linked to the
    /// waypoints on source part of type newLinkType.</param>
    private void link(MapPartController sourcePart, string newLinkType, string thisLinkType)
    {
        List <Transform> newWaypoints = new List <Transform>();

        foreach (Transform waypoint in sourcePart.transform.Find("WayPoints"))
        {
            PointDescriptor pointScript = waypoint.GetComponent <PointDescriptor>();
            switch (newLinkType)
            {
            case "northLink":
                if (pointScript.isNorthLink)
                {
                    newWaypoints.Add(waypoint);
                }
                break;

            case "eastLink":
                if (pointScript.isEastLink)
                {
                    newWaypoints.Add(waypoint);
                }
                break;

            case "southLink":
                if (pointScript.isSouthLink)
                {
                    newWaypoints.Add(waypoint);
                }
                break;

            case "westLink":
                if (pointScript.isWestLink)
                {
                    newWaypoints.Add(waypoint);
                }
                break;
            }
        }
        Transform waypoints = transform.Find("WayPoints");

        foreach (Transform waypoint in waypoints)
        {
            PointDescriptor pointScript = waypoint.GetComponent <PointDescriptor>();
            switch (thisLinkType)
            {
            case "northLink":
                if (pointScript.isNorthLink)
                {
                    addNewWaypointsToCurrentOne(newWaypoints, pointScript);
                }
                break;

            case "eastLink":
                if (pointScript.isEastLink)
                {
                    addNewWaypointsToCurrentOne(newWaypoints, pointScript);
                }
                break;

            case "southLink":
                if (pointScript.isSouthLink)
                {
                    addNewWaypointsToCurrentOne(newWaypoints, pointScript);
                }
                break;

            case "westLink":
                if (pointScript.isWestLink)
                {
                    addNewWaypointsToCurrentOne(newWaypoints, pointScript);
                }
                break;
            }
        }
    }