Beispiel #1
0
    private void PopulateExits(DungeonBuilder.Node n, GameObject g, DungeonBuilder db)
    {
        GameObject[] verticalPathOptions   = Resources.LoadAll <GameObject>(RoomPath + Tileset + "/PathVertical");
        GameObject[] horizontalPathOptions = Resources.LoadAll <GameObject>(RoomPath + Tileset + "/PathHorizontal");

        List <RoomExit> roomExitPoints = g.GetComponentsInChildren <RoomExit>().ToList();

        Tuple <int, int> positionOfNode = db.nodePositions[n.spawnIndex];

        if (db.nodePositions.Any(no => n.Connections.Any(k => k.spawnIndex == no.Key) &&
                                 no.Value.Equals(new Tuple <int, int>(positionOfNode.Item1 - 1, positionOfNode.Item2))))
        {
            RoomExit exit = roomExitPoints.OrderBy(r => r.transform.localPosition.x).First();
            exit.activateTile = true;
            for (int i = (int)exit.transform.localPosition.x - 1; i >= -distanceBetweenNodes / 2; i--)
            {
                GameObject p = Instantiate(horizontalPathOptions[Random.Range(0, horizontalPathOptions.Length)]);
                objectsToDestroy.Add(p);
                p.transform.parent        = g.transform;
                p.transform.localPosition = Vector3.zero + Vector3.right * i + Vector3.up * exit.transform.localPosition.y;
            }

            if (n.nodeType == DungeonBuilder.NodeType.Boss && n.Connections.Any(no => no.nodeType == DungeonBuilder.NodeType.EndTreasure))
            {
                int endNode = n.Connections.First(no => no.nodeType == DungeonBuilder.NodeType.EndTreasure).spawnIndex;
                if (db.nodePositions[endNode].Equals(new Tuple <int, int>(positionOfNode.Item1 - 1, positionOfNode.Item2)))
                {
                    exit.activateTile = false;
                    exit.gameObject.AddComponent <PostBossItemTakey>();
                    BossEnemy boss = g.GetComponentInChildren <BossEnemy>();
                    if (boss != null)
                    {
                        boss.bossExit = exit;
                    }
                }
            }
        }

        if (db.nodePositions.Any(no => n.Connections.Any(k => k.spawnIndex == no.Key) &&
                                 no.Value.Equals(new Tuple <int, int>(positionOfNode.Item1 + 1, positionOfNode.Item2))))
        {
            RoomExit exit = roomExitPoints.OrderBy(r => r.transform.localPosition.x).Last();
            exit.activateTile = true;
            for (int i = (int)exit.transform.localPosition.x + 1; i <= distanceBetweenNodes / 2; i++)
            {
                GameObject p = Instantiate(horizontalPathOptions[Random.Range(0, horizontalPathOptions.Length)]);
                objectsToDestroy.Add(p);
                p.transform.parent        = g.transform;
                p.transform.localPosition = Vector3.zero + Vector3.right * i + Vector3.up * exit.transform.localPosition.y;
            }

            if (n.nodeType == DungeonBuilder.NodeType.Boss && n.Connections.Any(no => no.nodeType == DungeonBuilder.NodeType.EndTreasure))
            {
                int endNode = n.Connections.First(no => no.nodeType == DungeonBuilder.NodeType.EndTreasure).spawnIndex;
                if (db.nodePositions[endNode].Equals(new Tuple <int, int>(positionOfNode.Item1 + 1, positionOfNode.Item2)))
                {
                    exit.activateTile = false;
                    exit.gameObject.AddComponent <PostBossItemTakey>();
                    BossEnemy boss = g.GetComponentInChildren <BossEnemy>();
                    if (boss != null)
                    {
                        boss.bossExit = exit;
                    }
                }
            }
        }

        if (db.nodePositions.Any(no => n.Connections.Any(k => k.spawnIndex == no.Key) &&
                                 no.Value.Equals(new Tuple <int, int>(positionOfNode.Item1, positionOfNode.Item2 - 1))))
        {
            RoomExit exit = roomExitPoints.OrderBy(r => r.transform.localPosition.y).First();
            exit.activateTile = true;
            for (int i = (int)exit.transform.localPosition.y - 1; i >= -distanceBetweenNodes / 2; i--)
            {
                GameObject p = Instantiate(verticalPathOptions[Random.Range(0, verticalPathOptions.Length)]);
                objectsToDestroy.Add(p);
                p.transform.parent        = g.transform;
                p.transform.localPosition = Vector3.zero + Vector3.up * i + Vector3.right * exit.transform.localPosition.x;
            }

            if (n.nodeType == DungeonBuilder.NodeType.Boss && n.Connections.Any(no => no.nodeType == DungeonBuilder.NodeType.EndTreasure))
            {
                int endNode = n.Connections.First(no => no.nodeType == DungeonBuilder.NodeType.EndTreasure).spawnIndex;
                if (db.nodePositions[endNode].Equals(new Tuple <int, int>(positionOfNode.Item1, positionOfNode.Item2 - 1)))
                {
                    exit.activateTile = false;
                    exit.gameObject.AddComponent <PostBossItemTakey>();
                    BossEnemy boss = g.GetComponentInChildren <BossEnemy>();
                    if (boss != null)
                    {
                        boss.bossExit = exit;
                    }
                }
            }
        }

        if (db.nodePositions.Any(no => n.Connections.Any(k => k.spawnIndex == no.Key) &&
                                 no.Value.Equals(new Tuple <int, int>(positionOfNode.Item1, positionOfNode.Item2 + 1))))
        {
            RoomExit exit = roomExitPoints.OrderBy(r => r.transform.localPosition.y).Last();
            exit.activateTile = true;
            for (int i = (int)exit.transform.localPosition.y + 1; i <= distanceBetweenNodes / 2; i++)
            {
                GameObject p = Instantiate(verticalPathOptions[Random.Range(0, verticalPathOptions.Length)]);
                objectsToDestroy.Add(p);
                p.transform.parent        = g.transform;
                p.transform.localPosition = Vector3.zero + Vector3.up * i + Vector3.right * exit.transform.localPosition.x;
            }

            if (n.nodeType == DungeonBuilder.NodeType.Boss && n.Connections.Any(no => no.nodeType == DungeonBuilder.NodeType.EndTreasure))
            {
                int endNode = n.Connections.First(no => no.nodeType == DungeonBuilder.NodeType.EndTreasure).spawnIndex;
                if (db.nodePositions[endNode].Equals(new Tuple <int, int>(positionOfNode.Item1, positionOfNode.Item2 + 1)))
                {
                    exit.activateTile = false;
                    exit.gameObject.AddComponent <PostBossItemTakey>();
                    BossEnemy boss = g.GetComponentInChildren <BossEnemy>();
                    if (boss != null)
                    {
                        boss.bossExit = exit;
                    }
                }
            }
        }
    }
Beispiel #2
0
    // Start is called before the first frame update
    public void LoadGame()
    {
        if (Application.isPlaying)
        {
            for (int level = 0; level < 4; level++)
            {
                DungeonBuilder db = new DungeonBuilder(4 + level, 10 + level * 3);

                Debug.Log(string.Format("Created node map with {0} nodes!", db.NodeMap.Count));

                for (int i = 0; i < db.NodeMap.Count; i++)
                {
                    DungeonBuilder.Node n           = db.NodeMap[i];
                    GameObject[]        RoomOptions = { };

                    if (n.nodeType == DungeonBuilder.NodeType.Entrance)
                    {
                        RoomOptions = Resources.LoadAll <GameObject>(RoomPath + Tileset + "/Entrance");

                        if (RoomOptions.Length <= 0)
                        {
                            Debug.LogError("No rooms found in the [" + RoomPath + Tileset + "/Entrance] Folder!");
                        }
                    }
                    else if (n.nodeType == DungeonBuilder.NodeType.Shop)
                    {
                        RoomOptions = Resources.LoadAll <GameObject>(RoomPath + Tileset + "/Shop");

                        if (RoomOptions.Length <= 0)
                        {
                            Debug.LogError("No rooms found in the [" + RoomPath + Tileset + "/Shop] Folder!");
                        }
                    }
                    else if (n.nodeType == DungeonBuilder.NodeType.Normal)
                    {
                        RoomOptions = Resources.LoadAll <GameObject>(RoomPath + Tileset + string.Format("/{0}Exits", 4));                       //need to add logic for room direction-y stuff to get the <4 to work again... bluh

                        if (RoomOptions.Length <= 0)
                        {
                            Debug.LogError("No rooms found in the [" + RoomPath + Tileset + string.Format("/{0}Exits", n.Connections.Length) + "] Folder!");
                        }
                    }
                    else if (n.nodeType == DungeonBuilder.NodeType.Boss)
                    {
                        RoomOptions = Resources.LoadAll <GameObject>(RoomPath + Tileset + "/Boss");

                        if (RoomOptions.Length <= 0)
                        {
                            Debug.LogError("No rooms found in the [" + RoomPath + Tileset + "Boss" + "] Folder!");
                        }
                    }
                    else if (n.nodeType == DungeonBuilder.NodeType.Treasure)
                    {
                        RoomOptions = Resources.LoadAll <GameObject>(RoomPath + Tileset + "/Treasure");

                        if (RoomOptions.Length <= 0)
                        {
                            Debug.LogError("No rooms found in the [" + RoomPath + Tileset + "Treasure" + "] Folder!");
                        }
                    }
                    else if (n.nodeType == DungeonBuilder.NodeType.EndTreasure)
                    {
                        RoomOptions = Resources.LoadAll <GameObject>(RoomPath + Tileset + "/SuperTreasure");

                        if (RoomOptions.Length <= 0)
                        {
                            Debug.LogError("No rooms found in the [" + RoomPath + Tileset + "Treasure" + "] Folder!");
                        }
                    }

                    GameObject       g        = Instantiate(RoomOptions[Random.Range(0, RoomOptions.Length)]);
                    Tuple <int, int> position = db.nodePositions[n.spawnIndex];
                    g.transform.position = Vector3.zero + Vector3.right * position.Item1 * distanceBetweenNodes + Vector3.up * position.Item2 * distanceBetweenNodes + Vector3.right * 500 * level;
                    objectsToDestroy.Add(g);
                    BossItemDecideyTime bossItemLev = g.GetComponent <BossItemDecideyTime>();
                    if (bossItemLev != null)
                    {
                        bossItemLev.currentLevel = level;
                    }
                    LevelTeleport teleport = g.GetComponentInChildren <LevelTeleport>();
                    if (teleport != null)
                    {
                        teleport.level = level;
                    }

                    PopulateExits(n, g, db);
                }
            }
        }
    }