Пример #1
0
        // Fill out a TileDungeon using RawDungeon data
        public void ParseDungeonData(RawDungeonData rawDungeon)
        {
            m_Tiles = MakeEmptyTileMap(rawDungeon);

            // Tiles for Rooms
            for (int i = 0; i < rawDungeon.Rooms.Length; i++)        //itterate clusters
            {
                for (int j = 0; j < rawDungeon.Rooms[i].Length; j++) //itterate rooms
                {
                    for (int y = (int)rawDungeon.Rooms[i][j].min.y; y < rawDungeon.Rooms[i][j].max.y; y++)
                    {
                        for (int x = (int)rawDungeon.Rooms[i][j].min.x; x < rawDungeon.Rooms[i][j].max.x; x++)
                        {
                            // The tiles on the edge or a room are walls
                            if (x == rawDungeon.Rooms[i][j].xMin ||
                                y == rawDungeon.Rooms[i][j].yMin ||
                                x == rawDungeon.Rooms[i][j].xMax - 1 ||
                                y == rawDungeon.Rooms[i][j].yMax - 1)
                            {
                                //tiles[x, y] = EDungeonTile.Wall;
                            }
                            else
                            {
                                m_Tiles[x, y] = EDungeonTile.Floor;
                            }
                        }
                    }
                    JoinPoints(rawDungeon.Rooms[i][j].center, rawDungeon.Path[i]);
                }
                if (i < rawDungeon.Rooms.Length - 1)
                {
                    JoinPoints(rawDungeon.Path[i + 1], rawDungeon.Path[i]);
                }
            }

            m_Tiles[(int)rawDungeon.GetExitPosition().x, (int)rawDungeon.GetExitPosition().y] = EDungeonTile.DownStairs;

#if Debug
            // Tiles for paths
            for (int i = 0; i < rawDungeon.Rooms.Length; i++)
            {
                var   cluster    = rawDungeon.Rooms[i];
                Color debugColor = Color.HSVToRGB((float)i / rawDungeon.Rooms.Length, 1, 1);
                for (int j = 1; j < cluster.Length; j++)
                {
                    Debug.DrawLine(cluster[j - 1].center + rawDungeon.GetWorldOffset(),
                                   cluster[j].center + rawDungeon.GetWorldOffset(),
                                   debugColor, 100);
                }

                if (i < rawDungeon.Rooms.Length - 1)
                {
                    Debug.DrawLine(rawDungeon.Path[i] + rawDungeon.GetWorldOffset(),
                                   rawDungeon.Path[i + 1] + rawDungeon.GetWorldOffset(),
                                   Color.white, 100);
                }
            }
#endif
        }
Пример #2
0
        private EDungeonTile[,] MakeEmptyTileMap(RawDungeonData dungeon)
        {
            EDungeonTile[,] tiles = new EDungeonTile[dungeon.Width, dungeon.Height];
            for (int y = 0; y < dungeon.Height; y++)
            {
                for (int x = 0; x < dungeon.Width; x++)
                {
                    tiles[x, y] = EDungeonTile.Wall;
                }
            }

            return(tiles);
        }