示例#1
0
        public Overworld GenerateOverworld()
        {
            validMachineTiles = new List <Vector2>();
            thisOverworld     = Instantiate(overworldPrefab, transform);
            thisOverworld.InitializeWorld(8, 8);

            GenerateTown(thisOverworld);
            //PlaceShrines(thisOverworld);
            GenerateTerrainCells(thisOverworld); //Assign difficulty levels

            validMachineTiles = GenerateValidMachineTilesList(thisOverworld);
            int numDungeons = 0;

            if (validMachineTiles.Count > 0)
            {
                while (numDungeons < maxDungeons) //(thisOverworld.CellMap.GetLength(0) * thisOverworld.CellMap.GetLength(1)) / 32) {
                {
                    numDungeons += GenerateDungeonCells(thisOverworld);
                    if (validMachineTiles.Count < 1)
                    {
                        numDungeons = maxDungeons;
                    }
                }
            }
            //AssignItemLocations(thisOverworld);   //These are assigned to wilderness cells; 1-star equipment item guarded by powerful creature; one entrance
            //AssignWitchHouse(thisOverworld);    //Her house moves every day at midnight; any 'empty' space
            //
            //GenerateCellObjects(thisOverworld);
            //Debug.Log("Cells Generated!");
            //AssignDoors(thisOverworld);
            //Debug.Log("Doors added and dungeon cleaned up!");
            //SaveOverworld();

            return(thisOverworld);
        }
示例#2
0
        public void GenerateCellObjects(Overworld world)
        {
            for (int Y = 0; Y < world.CellMap.GetLength(0); Y++)
            {
                for (int X = 0; X < world.CellMap.GetLength(1); X++)
                {
                    if (!world.CellMap[Y, X].GetComponent <Cell>().isMachine)
                    {
                        //DoorList = new List<Tile>();
                        world.CellMap[Y, X].InitializeTiles();
                        world.CellMap[Y, X] = RandomFillDungeon(world.CellMap[Y, X]);
                        world.CellMap[Y, X] = SimulateDungeonGrowth(world.CellMap[Y, X]);
                        //GenerateMachine(machinePrefab, exampleMap);
                        //PlaceDoors(cell);
                        //CleanUpDungeon(world.CellMap[Y, X]);
                        //PlaceBridges(exampleMap);
                        //PlaceChests(exampleMap);
                        //PlaceMonsters(exampleMap);
                        //PlaceTraps(exampleMap);

                        Debug.Log("Cell created!");
                    }
                }
            }
        }
示例#3
0
        string WorldToString(Overworld world)
        {
            string returnString = string.Join(" ", new string[] { "Width:",
                                                                  world.CellMap.GetLength(1).ToString(),
                                                                  "\tHeight:",
                                                                  world.CellMap.GetLength(0).ToString(),
                                                                  "\t% Walls:",
                                                                  System.Environment.NewLine });

            List <string> mapSymbols = new List <string>();

            mapSymbols.Add("#");    //Forest
            mapSymbols.Add("O");    //Beach
            mapSymbols.Add("@");    //Cave
            mapSymbols.Add("%");    //Swamp
            mapSymbols.Add("M");    //Mountain

            for (int Y = 0; Y < world.CellMap.GetLength(0); Y++)
            {
                for (int X = 0; X < world.CellMap.GetLength(1); X++)
                {
                    if (!world.CellMap[Y, X].GetComponent <Cell>().isMachine)
                    {
                        returnString += mapSymbols[(int)world.CellMap[Y, X].GetComponent <Cell>().thisCellType];
                    }
                    else
                    {
                        returnString += "$";    //Machine
                    }
                }
                returnString += System.Environment.NewLine;
            }
            return(returnString);
        }
示例#4
0
        public void AssignDoors(Overworld world)
        {
            Debug.Log("Assigning Doors");

            for (int Y = 0; Y < world.CellMap.GetLength(0); Y++)
            {
                for (int X = 0; X < world.CellMap.GetLength(1); X++)
                {
                    if (!world.CellMap[Y, X].isMachine)
                    {
                        //check if out of bounds; turn off doors for cells pointing in that direction
                        if (Y - 1 < 0)
                        {
                            world.CellMap[Y, X].Directions[0] = false;
                        }
                        else
                        {
                            world.CellMap[Y, X].Directions[0] = world.CellMap[Y - 1, X].Directions[2];
                        }

                        if (Y + 1 > world.CellMap.GetLength(0) - 1)
                        {
                            world.CellMap[Y, X].Directions[2] = false;
                        }
                        else
                        {
                            world.CellMap[Y, X].Directions[2] = world.CellMap[Y + 1, X].Directions[0];
                        }

                        if (X - 1 < 0)
                        {
                            world.CellMap[Y, X].Directions[1] = false;
                        }
                        else
                        {
                            world.CellMap[Y, X].Directions[1] = world.CellMap[Y, X - 1].Directions[3];
                        }

                        if (X + 1 > world.CellMap.GetLength(1) - 1)
                        {
                            world.CellMap[Y, X].Directions[3] = false;
                        }
                        else
                        {
                            world.CellMap[Y, X].Directions[3] = world.CellMap[Y, X + 1].Directions[0];
                        }

                        world.CellMap[Y, X] = PlaceDoors(world.CellMap[Y, X]);
                        ClearPathBetweenDoors(world.CellMap[Y, X]);
                    }
                }
            }
        }
示例#5
0
        public void GenerateTileObjects(Overworld world)
        {
            //PrintMap();

            for (int Y = 0; Y < world.CellMap.GetLength(0); Y++)
            {
                for (int X = 0; X < world.CellMap.GetLength(1); X++)
                {
                    GenerateTilesInCell(world.CellMap[Y, X].GetComponent <Cell>());
                }
            }
        }
示例#6
0
 public void CleanUpOverworld(Overworld world)
 {
     for (int Y = 0; Y < world.CellMap.GetLength(0); Y++)
     {
         for (int X = 0; X < world.CellMap.GetLength(1); X++)
         {
             if (!world.CellMap[Y, X].GetComponent <Cell>().isMachine)
             {
                 GenerateLake(world.CellMap[Y, X]);
                 ConvertOrphanTiles(world.CellMap[Y, X]);
                 RemoveDiagonals(world.CellMap[Y, X], 10);
                 Debug.Log("Overworld cleaned up!");
             }
         }
     }
 }
示例#7
0
 void GenerateTerrainCells(Overworld world)
 {
     for (int Y = 0; Y < world.CellMap.GetLength(0); Y++)
     {
         for (int X = 0; X < world.CellMap.GetLength(1); X++)
         {
             if (world.CellMap[Y, X] == null)
             {
                 GameObject newCell = Instantiate(GetCellPrefabByName("Forest"), CellCoordToScene(X, Y), Quaternion.identity, world.transform);
                 world.CellMap[Y, X] = newCell.GetComponent <Cell>();
                 world.CellMap[Y, X].GetComponent <Cell>().DifficultyLevel    = 0;
                 world.CellMap[Y, X].GetComponent <Cell>().OverworldLocationX = X;
                 world.CellMap[Y, X].GetComponent <Cell>().OverworldLocationY = Y;
             }
         }
     }
 }
示例#8
0
        List <Vector2> GenerateValidMachineTilesList(Overworld world)
        {
            List <Vector2> checkTiles = new List <Vector2>();
            bool           cellPass   = true;

            Debug.Log("Generating new valid machine tiles list!");

            for (int Y = 0; Y < world.CellMap.GetLength(0) - 1; Y++)
            {
                for (int X = 0; X < world.CellMap.GetLength(1) - 1; X++)
                {
                    cellPass = true;

                    for (int i = -1; i < 2; i++)
                    {
                        for (int j = -1; j < 2; j++)
                        {
                            if (Y + i > world.CellMap.GetLength(0) - 1 || X + j > world.CellMap.GetLength(0) - 1)
                            {
                                cellPass = false;                                                                                       // Y + i < -1 || X + j < 0 ||
                            }
                            else if (Y + i >= 0 && X + j >= 0 && Y + i <= world.CellMap.GetLength(0) - 1 && X + j <= world.CellMap.GetLength(0) - 1)
                            {
                                if (world.CellMap[Y + i, X + j].GetComponent <Cell>().isMachine)
                                {
                                    cellPass = false;
                                }
                            }
                            //if ((Y + i > world.CellMap.GetLength(0)-1) || (X + j > world.CellMap.GetLength(1) - 1)) cellPass = false;
                        }
                    }

                    if (cellPass)
                    {
                        checkTiles.Add(new Vector2(X, Y));
                    }
                }
            }
            if (checkTiles.Count < 1)
            {
                Debug.Log("No valid machine tiles!");
            }

            return(checkTiles);
        }
示例#9
0
        int GenerateDungeonCells(Overworld world)
        {
            if (validMachineTiles.Count < 1)
            {
                Debug.Log("No valid machine tiles! " + System.DateTime.Now);
                return(0);
            }

            int randomInd   = Random.Range(0, validMachineTiles.Count - 1);
            int randomTileX = Mathf.RoundToInt(validMachineTiles[randomInd].x);
            int randomTileY = Mathf.RoundToInt(validMachineTiles[randomInd].y);

            for (int i = -1; i < 2; i++)
            {
                for (int j = -1; j < 2; j++)
                {
                    if (randomTileY + i >= 0 && randomTileX + j >= 0 && randomTileY + i <= world.CellMap.GetLength(0) - 1 && randomTileX + j <= world.CellMap.GetLength(0) - 1)
                    {
                        if (world.CellMap[randomTileY + i, randomTileX + j].isMachine)
                        {
                            validMachineTiles.RemoveAt(randomInd);
                            Debug.Log("Not a valid machine tile! " + System.DateTime.Now);
                            return(0);
                        }
                    }
                }
            }

            CellType machineCellType = world.CellMap[randomTileY, randomTileX].GetComponent <Cell>().thisCellType;

            world.CellMap[randomTileY, randomTileX] = Instantiate(GetCellPrefabByName("Machine"), CellCoordToScene(randomTileX, randomTileY), Quaternion.identity, world.transform).GetComponent <Cell>();
            world.CellMap[randomTileY, randomTileX].gameObject.SetActive(false);
            //world.CellMap[randomTileY, randomTileX + 1] = Instantiate(GetCellPrefabByName("Placeholder"), CellCoordToScene(randomTileX, randomTileY), Quaternion.identity, transform);
            //world.CellMap[randomTileY + 1, randomTileX] = Instantiate(GetCellPrefabByName("Placeholder"), CellCoordToScene(randomTileX, randomTileY), Quaternion.identity, transform);
            //world.CellMap[randomTileY + 1, randomTileX + 1] = Instantiate(GetCellPrefabByName("Placeholder"), CellCoordToScene(randomTileX, randomTileY), Quaternion.identity, transform);
            world.CellMap[randomTileY, randomTileX].GetComponent <Cell>().thisCellType = machineCellType;
            //world.CellMap[randomTileY, randomTileX + 1].GetComponent<Cell>().thisCellType = machineCellType;
            //world.CellMap[randomTileY + 1, randomTileX].GetComponent<Cell>().thisCellType = machineCellType;
            //world.CellMap[randomTileY + 1, randomTileX + 1].GetComponent<Cell>().thisCellType = machineCellType;
            world.CellMap[randomTileY, randomTileX].GetComponent <Cell>().OverworldLocationX = randomTileX;
            world.CellMap[randomTileY, randomTileX].GetComponent <Cell>().OverworldLocationY = randomTileY;
            validMachineTiles.RemoveAt(randomInd);
            Debug.Log("New machine generated! " + System.DateTime.Now);
            return(1);
        }
示例#10
0
        //.....Cell Generation Functions.....//

        void GenerateTown(Overworld world)
        {
            int townStartY = world.CellMap.GetLength(0) - 2;
            int townStartX = (world.CellMap.GetLength(1) / 2) - 1;

            world.CellMap[townStartY, townStartX] = Instantiate(GetCellPrefabByName("Town"), CellCoordToScene(townStartX, townStartY), Quaternion.identity, world.transform).GetComponent <Cell>();
            world.CellMap[townStartY, townStartX].gameObject.SetActive(false);
            world.CellMap[townStartY, townStartX].OverworldLocationX = townStartX;
            world.CellMap[townStartY, townStartX].OverworldLocationY = townStartY;
            world.CellMap[townStartY, townStartX + 1] = Instantiate(GetCellPrefabByName("Placeholder"), CellCoordToScene(townStartX + 1, townStartY), Quaternion.identity, world.transform).GetComponent <Cell>();
            world.CellMap[townStartY, townStartX + 1].OverworldLocationX = townStartX + 1;
            world.CellMap[townStartY, townStartX + 1].OverworldLocationY = townStartY;
            world.CellMap[townStartY + 1, townStartX] = Instantiate(GetCellPrefabByName("Placeholder"), CellCoordToScene(townStartX, townStartY + 1), Quaternion.identity, world.transform).GetComponent <Cell>();
            world.CellMap[townStartY + 1, townStartX].OverworldLocationX = townStartX;
            world.CellMap[townStartY + 1, townStartX].OverworldLocationY = townStartY + 1;
            world.CellMap[townStartY + 1, townStartX + 1] = Instantiate(GetCellPrefabByName("Placeholder"), CellCoordToScene(townStartX + 1, townStartY + 1), Quaternion.identity, world.transform).GetComponent <Cell>();
            world.CellMap[townStartY + 1, townStartX + 1].OverworldLocationX = townStartX + 1;
            world.CellMap[townStartY + 1, townStartX + 1].OverworldLocationY = townStartY + 1;
            world.CellMap[townStartY, townStartX + 1].thisCellType           = CellType.Forest;
            world.CellMap[townStartY + 1, townStartX].thisCellType           = CellType.Forest;
            world.CellMap[townStartY + 1, townStartX + 1].thisCellType       = CellType.Forest;
        }
示例#11
0
        void PlaceShrines(Overworld world)
        {
            int numShrines = (world.CellMap.GetLength(0) * world.CellMap.GetLength(1)) / 32;

            //if (numShrines <= 2)
            for (int s = 0; s < numShrines; s++)
            {
                world.CellMap[s, s] = Instantiate(GetCellPrefabByName("Shrine"), transform).GetComponent <Cell>();
                world.CellMap[s, s].GetComponent <Cell>().thisCellType = CellType.Forest;

                /*
                 * switch (s)
                 * {
                 *  case 0:
                 *          world.CellMap[3, 1] = Instantiate(GetCellPrefabByName("Shrine"), transform);
                 *          world.CellMap[3, 1].GetComponent<Cell>().thisCellType = CellType.Forest;
                 *          break;
                 *  case 1:
                 *          world.CellMap[3, 6] = Instantiate(GetCellPrefabByName("Shrine"), transform);
                 *          world.CellMap[3, 6].GetComponent<Cell>().thisCellType = CellType.Forest;
                 *          break;
                 * }*/
            }
        }