public override void Initialize(Simulation simulation) { base.Initialize(simulation); simulationConfiguration = SimulationConfiguration.LoadConfigOrDefault(); tileMap = TileMap.DeserializeFromFile("tilemap.dat", this); if (tileMap == null) { tileMap = new TileMap(100, 100, 100.0f); tileMap.Initialize(this); ValueNoise2D vn = new ValueNoise2D(tileMap.Width, tileMap.Height); vn.startFrequencyX = 10; vn.startFrequencyY = 10; vn.calculate(); float[,] heightMap = vn.getHeightMap(); for (int x = 0; x < tileMap.Width; x++) { for (int y = 0; y < tileMap.Height; y++) { tileMap.SetTileType(x, y, heightMap[x, y] > 0.5 ? TileType.Land : TileType.Water); } } tileMap.SerializeToFile("tilemap.dat"); } creatureManager.Initialize(this); creatureManager.Deserialize("creatures.dat"); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); WhiteCircleTexture = Content.Load <Texture2D>("Map/WhiteCircle512"); RenderHelper.Ini(WhiteTexture, WhiteCircleTexture); tileMap = TileMap.DeserializeFromFile("tilemap.dat", this); if (tileMap == null) { tileMap = new TileMap(100, 100, 100.0f); tileMap.Initialize(this); ValueNoise2D vn = new ValueNoise2D(tileMap.Width, tileMap.Height); vn.startFrequencyX = 10; vn.startFrequencyY = 10; vn.calculate(); float[,] heightMap = vn.getHeightMap(); for (int x = 0; x < tileMap.Width; x++) { for (int y = 0; y < tileMap.Height; y++) { tileMap.SetTileType(x, y, heightMap[x, y] > 0.5 ? TileType.Land : TileType.Water); } } tileMap.SerializeToFile("tilemap.dat"); } creatureManager.Initialize(this); creatureManager.Deserialize("creatures.dat"); modules.Add(tileMap); modules.Add(creatureManager); Creature.Initialize(); // TODO: use this.Content to load your game content here }