Example #1
0
        public void UpdateChunkGeneration()
        {
            Chunk prevChunk = Chunks[0];

            foreach (Chunk chunk in Chunks)
            {
                if (!chunk.Generated)
                {
                    chunk.Generate(MapReader.ReadImage(GetNewMapName()), Game1.TILE_SIZE);
                }
                if (!chunk.Stitched)
                {
                    Chunk.StitchChunks(prevChunk, chunk);
                }
                prevChunk = chunk;
            }

            if (Chunks.Count > 0)
            {
                if (Chunks[Chunks.Count - 1].EndTile.Rect.X < Camera.Rect.Right)
                {
                    //End tile of last chunk is on screen, generate new chunk
                    GenerateNewChunk(Chunks[Chunks.Count - 1].EndTile.Rect, GetNewMapName());
                }

                if (Chunks[0].EndTile.Rect.X <= Camera.Rect.Left - Chunks[0].EndTile.Rect.Width)
                {
                    //last tile of first chunk is off screen, destroy that chunk (i.e. remove it from the list).
                    Chunks.RemoveAt(0);
                }
            }
        }
Example #2
0
        //Starter generation
        public Chunk(string path, Rectangle origin)
        {
            stitched = true;
            atlas    = MapReader.ReadImage(path);

            this.origin = origin;
            Generate(atlas, Game1.TILE_SIZE);
        }