public World(string worldName) { this.worldName = worldName; // convert world name to seed value var md5Hasher = MD5.Create(); var hashed = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(worldName)); var seed = BitConverter.ToInt32(hashed, 0); Noise2.SetSeed(seed, .006f); }
/// <summary> /// Reads in chunk file from text file or if file dosnt exists creates a new chunk /// creates the main background layer this layer must be created before others as it determains were things will spawn and be placed /// </summary> /// <returns></returns> private void CreateChunk() { Game.debugConsole.WriteLine("Adding new Chunk (" + chunkRootPosX + "," + chunkRootPosY + ")"); float sand = .1f; float water = 0f; float grass = 2; //it shouldnt EVER return more then 1, but it does.. //float factor =.006f; int cX = 0; int cY = 0; for (int Y = World.chunkHeight * chunkRootPosY; Y < (World.chunkHeight * chunkRootPosY) + World.chunkHeight; Y++) { for (int X = World.chunkWidth * chunkRootPosX; X < ((World.chunkWidth * chunkRootPosX) + World.chunkWidth); X++) { float noise = Noise2.GetWorldNoise(X, Y, 100); //create the cell if (noise <= water)//Water Cell { cells[cX, cY] = new Cell(Cell.CellType.Water, new Vector2(X, Y)); } else if (noise <= sand)//Sand Cell { cells[cX, cY] = new Cell(Cell.CellType.Sand, new Vector2(X, Y)); } else if (noise <= grass)//Grass cell { cells[cX, cY] = new Cell(Cell.CellType.Grass, new Vector2(X, Y)); } ++cX; } cX = 0; ++cY; } }