Пример #1
0
        /// <summary>
        /// Constructor for <see cref="World"/> object
        /// </summary>
        /// <param name="seed">The seed of this <see cref="World"/></param>
        public World(int?seed = null)
        {
            // Setting up singleton
            Instance = this;

            // Setting up quadtree and search range
            worldBoundsRect = new Rectangle(0, 0, Tile.SPACING * Chunk.SIZE * CHUNK_COUNT, Tile.SPACING * Chunk.SIZE * CHUNK_COUNT);
            collisionTree   = new CollisionTree(worldBoundsRect);

            // Creating terrtain generator and generating terrain
            terrainGenerator = new TerrainGenerator(seed);
            AdjustLoadedChunks(new Vector2Int(0, 0));
            cachedBuildings.Add(new Dungeon(new Vector2Int(0, 0)));
        }
Пример #2
0
        /// <summary>
        /// Subprogram to setup this <see cref="CollisionTree"/>'s subtrees
        /// </summary>
        private void BuildSubtrees()
        {
            // Various rectangle/related variables
            int x          = Range.X;
            int y          = Range.Y;
            int halfWidth  = Range.Width / 2;
            int halfHeight = Range.Height / 2;

            // Setting up subtrees
            subtrees[0] = new CollisionTree(new Rectangle(x + halfWidth, y, halfWidth, halfHeight));
            subtrees[1] = new CollisionTree(new Rectangle(x, y, halfWidth, halfHeight));
            subtrees[2] = new CollisionTree(new Rectangle(x, y + halfHeight, halfWidth, halfHeight));
            subtrees[3] = new CollisionTree(new Rectangle(x + halfWidth, y + halfHeight, halfWidth, halfHeight));
        }
Пример #3
0
        /// <summary>
        /// Constructor
        /// </summary>
        public DungeonGenerator()
        {
            rng           = new Random();
            rooms         = new List <Rectangle>();
            collisionTree = new CollisionTree(new Rectangle(0, 0, MAX_WIDTH, MAX_HEIGHT));
            region        = new int[MAX_WIDTH, MAX_HEIGHT];
            currentRegion = -1;

            for (int i = 0; i < MAX_WIDTH; i++)
            {
                for (int j = 0; j < MAX_HEIGHT; j++)
                {
                    region[i, j] = -1;
                }
            }
        }