コード例 #1
0
ファイル: Chunk.cs プロジェクト: DuckKnightDuel/Adam
        /// <summary>
        /// Calculates the tile indexes that need to be loaded when this chunk is active.
        /// </summary>
        /// <param name="chunks"></param>
        /// <param name="maxChunksX"></param>
        /// 
        public void StoreIndexesOfSurroundingChunks(Chunk[] chunks, int maxChunksX)
        {
            // Put the surrounding chunks in a list.
            List<Chunk> surroundingChunks = new List<Chunk>();
            int startingChunk = Index - maxChunksX - 4;
            int selectionSize = 8;

            for (int h = 0; h < selectionSize; h++)
            {
                for (int w = 0; w < selectionSize; w++)
                {
                    int current = startingChunk + (h * maxChunksX + w);
                    if (current >= 0 && current < chunks.Length)
                        surroundingChunks.Add(chunks[current]);
                }
            }

            // Make one array containing all indexes of surrounding chunks.
            int chunkCapacity = Chunk.DefaultSize * Chunk.DefaultSize;
            List<int> indexesSurroundingChunk = new List<int>();
            foreach (Chunk c in surroundingChunks)
            {
                int[] chunkIndexes = c.GetTileIndexes();
                foreach (int i in chunkIndexes)
                {
                    indexesSurroundingChunk.Add(i);
                }
            }
            _indexesAround = indexesSurroundingChunk.ToArray();
        }
コード例 #2
0
ファイル: ChunkManager.cs プロジェクト: DuckKnightDuel/Adam
        public void ConvertToChunks(int worldWidth, int worldHeight)
        {
            // Validate data.
            if (worldWidth % Chunk.DefaultSize != 0 || worldHeight % Chunk.DefaultSize != 0)
            {
                throw new ArgumentException("This level file version is no longer supported. It has dimensions that cannot be divided into chunks.");
            }

            this._worldHeight = worldHeight;
            this._worldWidth = worldWidth;

            // Calculates the amount of chunks that need to be created.
            _maxChunksX = worldWidth / Chunk.DefaultSize;
            _maxChunksY = worldHeight / Chunk.DefaultSize;

            _chunks = new Chunk[_maxChunksX * _maxChunksY];

            for (int i = 0; i < _chunks.Length; i++)
            {
                _chunks[i] = new Chunk(i);
            }

            SplitTiles();
        }
コード例 #3
0
ファイル: ChunkManager.cs プロジェクト: DuckKnightDuel/Adam
        /// <summary>
        /// Gathers all the indexes of the visible chunks around the camera.
        /// </summary>
        /// <returns>Visible indexes of tiles in chunks.</returns>
        public int[] GetVisibleIndexes()
        {
            Camera camera = GameWorld.Instance.Camera;
            if (camera == null)
                return new int[0];

            _activeChunk = GetChunk((int)camera.InvertedCoords.X, (int)camera.InvertedCoords.Y);
            // Chunk activeChunk = GetChunk(128 * Main.Tilesize, 128 * Main.Tilesize);
            return _activeChunk.GetSurroundIndexes();
        }