public int numberOfAdjacentRoads(int targetXaxis, int targetYaxis)
    {
        int pathTilesAdj = 0;

        if (MapScript.findTileAtLocation((int)targetXaxis + 1, (int)targetYaxis).GetComponent <tileAttributes>().tileType == "transport")
        {
            pathTilesAdj += 1;
        }
        if (MapScript.findTileAtLocation((int)targetXaxis - 1, (int)targetYaxis).GetComponent <tileAttributes>().tileType == "transport")
        {
            pathTilesAdj += 1;
        }
        if (MapScript.findTileAtLocation((int)targetXaxis, (int)targetYaxis + 1).GetComponent <tileAttributes>().tileType == "transport")
        {
            pathTilesAdj += 1;
        }
        if (MapScript.findTileAtLocation((int)targetXaxis, (int)targetYaxis - 1).GetComponent <tileAttributes>().tileType == "transport")
        {
            pathTilesAdj += 1;
        }
        return(pathTilesAdj);
    }
Example #2
0
    private void Update()
    {
        if (tileJustPlaced == true && singleUpdateLock == false)
        {
            singleUpdateLock = true;
            Debug.Log("TilePlaced!");
            StartCoroutine(updateGameInfo());
        }

        if (transportFixNeeded == true)
        {
            transportFixNeeded = false;
            foreach (var transportTile in MapGenScript.gridTiles)
            {
                int transportTileX = Mathf.RoundToInt(transportTile.GetComponent <tileAttributes>().Xaxis);
                int transportTileY = Mathf.RoundToInt(transportTile.GetComponent <tileAttributes>().Yaxis);

                bool checkTop    = false;
                bool checkBottom = false;
                bool checkLeft   = false;
                bool checkRight  = false;

                if (transportTile.GetComponent <tileAttributes>().tileName == "path")
                {
                    if (transportTileY != MapGenScript.rows)
                    {
                        if (MapGenScript.findTileAtLocation(transportTileX, transportTileY + 1).GetComponent <tileAttributes>().tileName == "path" ||
                            MapGenScript.findTileAtLocation(transportTileX, transportTileY + 1).GetComponent <tileAttributes>().tileName == "bridge")
                        {
                            checkTop = true;
                        }
                    }
                    if (transportTileY != 1)
                    {
                        if (MapGenScript.findTileAtLocation(transportTileX, transportTileY - 1).GetComponent <tileAttributes>().tileName == "path" ||
                            MapGenScript.findTileAtLocation(transportTileX, transportTileY - 1).GetComponent <tileAttributes>().tileName == "bridge")
                        {
                            checkBottom = true;
                        }
                    }
                    if (transportTileX != 1)
                    {
                        if (MapGenScript.findTileAtLocation(transportTileX - 1, transportTileY).GetComponent <tileAttributes>().tileName == "path" ||
                            MapGenScript.findTileAtLocation(transportTileX - 1, transportTileY).GetComponent <tileAttributes>().tileName == "bridge")
                        {
                            checkLeft = true;
                        }
                    }
                    if (transportTileX != MapGenScript.columns)
                    {
                        if (MapGenScript.findTileAtLocation(transportTileX + 1, transportTileY).GetComponent <tileAttributes>().tileName == "path" ||
                            MapGenScript.findTileAtLocation(transportTileX + 1, transportTileY).GetComponent <tileAttributes>().tileName == "bridge")
                        {
                            checkRight = true;
                        }
                    }

                    // paths decision tree
                    if (checkTop == true && checkRight == true && checkBottom == true && checkLeft == true)
                    {
                        transportTile.GetComponent <SpriteRenderer>().sprite = Resources.Load("Sprites/PathX", typeof(Sprite)) as Sprite;
                    }
                    if (checkTop == true && checkRight == true && checkBottom == true && checkLeft == false)
                    {
                        transportTile.GetComponent <SpriteRenderer>().sprite = Resources.Load("Sprites/PathNES", typeof(Sprite)) as Sprite;
                    }
                    if (checkTop == true && checkRight == true && checkBottom == false && checkLeft == false)
                    {
                        transportTile.GetComponent <SpriteRenderer>().sprite = Resources.Load("Sprites/PathNE", typeof(Sprite)) as Sprite;
                    }
                    if (checkTop == true && checkRight == false && checkBottom == false && checkLeft == false)
                    {
                        transportTile.GetComponent <SpriteRenderer>().sprite = Resources.Load("Sprites/PathNS", typeof(Sprite)) as Sprite;
                    }
                    if (checkTop == false && checkRight == false && checkBottom == false && checkLeft == true)
                    {
                        transportTile.GetComponent <SpriteRenderer>().sprite = Resources.Load("Sprites/PathWE", typeof(Sprite)) as Sprite;
                    }
                    if (checkTop == false && checkRight == false && checkBottom == true && checkLeft == true)
                    {
                        transportTile.GetComponent <SpriteRenderer>().sprite = Resources.Load("Sprites/PathSW", typeof(Sprite)) as Sprite;
                    }
                    if (checkTop == false && checkRight == true && checkBottom == true && checkLeft == true)
                    {
                        transportTile.GetComponent <SpriteRenderer>().sprite = Resources.Load("Sprites/PathESW", typeof(Sprite)) as Sprite;
                    }
                    if (checkTop == false && checkRight == true && checkBottom == false && checkLeft == false)
                    {
                        transportTile.GetComponent <SpriteRenderer>().sprite = Resources.Load("Sprites/PathWE", typeof(Sprite)) as Sprite;
                    }
                    if (checkTop == false && checkRight == false && checkBottom == true && checkLeft == false)
                    {
                        transportTile.GetComponent <SpriteRenderer>().sprite = Resources.Load("Sprites/PathNS", typeof(Sprite)) as Sprite;
                    }
                    if (checkTop == true && checkRight == false && checkBottom == true && checkLeft == false)
                    {
                        transportTile.GetComponent <SpriteRenderer>().sprite = Resources.Load("Sprites/PathNS", typeof(Sprite)) as Sprite;
                    }
                    if (checkTop == false && checkRight == true && checkBottom == false && checkLeft == true)
                    {
                        transportTile.GetComponent <SpriteRenderer>().sprite = Resources.Load("Sprites/PathWE", typeof(Sprite)) as Sprite;
                    }
                    if (checkTop == true && checkRight == true && checkBottom == false && checkLeft == true)
                    {
                        transportTile.GetComponent <SpriteRenderer>().sprite = Resources.Load("Sprites/PathNEW", typeof(Sprite)) as Sprite;
                    }
                    if (checkTop == true && checkRight == false && checkBottom == true && checkLeft == true)
                    {
                        transportTile.GetComponent <SpriteRenderer>().sprite = Resources.Load("Sprites/PathNSW", typeof(Sprite)) as Sprite;
                    }
                    if (checkTop == true && checkRight == false && checkBottom == false && checkLeft == true)
                    {
                        transportTile.GetComponent <SpriteRenderer>().sprite = Resources.Load("Sprites/PathNW", typeof(Sprite)) as Sprite;
                    }
                    if (checkTop == false && checkRight == true && checkBottom == true && checkLeft == false)
                    {
                        transportTile.GetComponent <SpriteRenderer>().sprite = Resources.Load("Sprites/PathES", typeof(Sprite)) as Sprite;
                    }
                }
            }
        }
    }