Advertisement
Guest User

Chunk

a guest
Mar 5th, 2012
738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. using Cerios.Miner.Blocks;
  7. using Cerios.Miner.Worlds.Generation;
  8. using Cerios.Miner.Worlds.Location;
  9.  
  10. namespace Cerios.Miner.Worlds
  11. {
  12.     public class Chunk
  13.     {
  14.         /// <summary>
  15.         /// The chunk side in world cordinates
  16.         /// </summary>
  17.         public const int ChunkSize = 16;
  18.  
  19.         /// <summary>
  20.         /// Gets or sets the blocks in the Chunk
  21.         /// </summary>
  22.         public Block[] Blocks
  23.         {
  24.             get;
  25.             set;
  26.         }
  27.  
  28.         /// <summary>
  29.         /// Gets or sets the location of the chunk
  30.         /// </summary>
  31.         public ChunkLocation Location
  32.         {
  33.             get;
  34.             set;
  35.         }
  36.  
  37.         /// <summary>
  38.         /// The constructor
  39.         /// </summary>
  40.         /// <param name="location">The location of the chunk</param>
  41.         public Chunk(ChunkLocation location)
  42.         {
  43.             Location = location;
  44.             Blocks = new Block[ChunkSize * ChunkSize];
  45.         }
  46.  
  47.         /// <summary>
  48.         /// Generate the chunk
  49.         /// </summary>
  50.         /// <param name="generator">The generator to use</param>
  51.         public void Generate(Generator generator)
  52.         {
  53.             for (int x = 0; x < ChunkSize; x++)
  54.                 for (int y = 0; y < ChunkSize; y++)
  55.                 {
  56.                     BlockChunkLocation blockChunkLocation = new BlockChunkLocation(x, y, Location);
  57.                     WorldLocation blockLocation = blockChunkLocation.GetWorldLocation();
  58.                     Blocks[x * ChunkSize + y] = generator.GetMaterialAtPosition(blockLocation.X, blockLocation.Y);
  59.                     Blocks[x * ChunkSize + y].Position = blockChunkLocation;
  60.                 }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement