public void GenerateTerrain(int x, int y, SurfaceGenerator surfaceGenerator) { for (int i = 0; i < Props.chunkSize; i++) { for (int j = 0; j < Props.chunkSize; j++) { int nx = i + x; int ny = j + y; SetTile(i, j, surfaceGenerator.GetTile(nx, ny)); } } }
public void CreateMapGenMenu(string tag) { GeneratorEntityAffinity treeCollection = new GeneratorEntityAffinity(new string[] { "Pine Tree 1" }, new float[] { 0.5f }, new float[] { 0.5f }, new float[] { 0.5f }, new float[] { 0.7f }, new float[] { 0.7f }, new float[] { 0.7f }); GeneratorEntityAffinity resourceCollection = new GeneratorEntityAffinity(new string[] { "Iron", "Copper", "Coal" }, new float[] { 0.0f, 0.0f, 0.3f }, new float[] { 0.0f, 0.2f, 0.5f }, new float[] { 0.2f, 0.4f, 0.0f }, new float[] { 0.2f, 0.2f, 0.2f }, new float[] { 0.2f, 0.2f, 0.2f }, new float[] { 0.2f, 0.2f, 0.2f }); resourceCollection.SetDensity("", 32); treeCollection.SetDensity("", 96); List <GeneratorEntityAffinity> list = new List <GeneratorEntityAffinity>(); list.Add(treeCollection); list.Add(resourceCollection); surfaceGenerator = new SurfaceGenerator(tileCollection, entityCollection, list); menuFactory.CreateMapGenMenu(surfaceGenerator); }
public SurfaceContainer(TileCollection tileCollection, SurfaceGenerator surfaceGenerator) { this.worldSize = surfaceGenerator.surfaceSize / Props.chunkSize; tileBox = new BoundingBox(-16, -16, 16, 16); this.tileCollection = tileCollection; chunks = new Chunk[worldSize * worldSize]; this.surfaceGenerator = surfaceGenerator; activeChunks = new List <Chunk>(); spawnPoint = new Vector2(worldSize * Props.chunkSize * Props.tileSize / 2, worldSize * Props.chunkSize * Props.tileSize / 2); this.timeOfMidday = surfaceGenerator.lengthOfDay; this.lengthOfNight = surfaceGenerator.lengthOfNight; this.levelOfDarkness = surfaceGenerator.levelOfDarkness; timeOfDay = 0; queuedCollisionEntities = new Dictionary <int[], List <Entity> >(); }
public void GenerateEntities(int x, int y, SurfaceGenerator surfaceGenerator, SurfaceContainer surface) { surfaceGenerator.GenerateEntities(x, y, surface); }
public void CreateMapGenMenu(SurfaceGenerator surfaceGenerator) { //Declaring elements Font mapGenFont = fontContainer.GetFont("SairaRegular"); MenuPanel worldMenu = new MenuPanel(new Vector2i(0, 0), new Vector2i(600, 500), new FloatRect(0, 0, 96, 96), 4, null, new Color(255, 255, 255, 224)); //Noise dropdowns string[] noiseNames = Enum.GetNames(typeof(FastNoise.NoiseType)); int[] noiseValues = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; MenuListBox moistureNoiseType = new MenuListBox(new Vector2i(150, 25), noiseNames, noiseValues, surfaceGenerator.SetNoiseType, mapGenFont, 24, 24, 0); moistureNoiseType.tag = "moisture"; MenuText moistureNoiseText = new MenuText(new Vector2i(150, 25), mapGenFont, "Moisture Noise:", 24, 24); moistureNoiseText.SetTextPosition("right", "center"); MenuListBox elevationNoiseType = new MenuListBox(new Vector2i(150, 25), noiseNames, noiseValues, surfaceGenerator.SetNoiseType, mapGenFont, 24, 24, 0); elevationNoiseType.tag = "elevation"; MenuText elevationNoiseText = new MenuText(new Vector2i(150, 25), mapGenFont, "Elevation Noise:", 24, 24); elevationNoiseText.SetTextPosition("right", "center"); MenuListBox temperatureNoiseType = new MenuListBox(new Vector2i(150, 25), noiseNames, noiseValues, surfaceGenerator.SetNoiseType, mapGenFont, 24, 24, 0); MenuText temperatureNoiseText = new MenuText(new Vector2i(150, 25), mapGenFont, "Temperature Noise:", 24, 24); temperatureNoiseText.SetTextPosition("right", "center"); temperatureNoiseType.tag = "temperature"; //Surface size field MenuText surfaceSizeFieldTitle = new MenuText(new Vector2i(100, 25), mapGenFont, "Map size:", 24, 24); MenuField surfaceSizeField = new MenuField(new Vector2i(150, 25), mapGenFont, surfaceGenerator.ParseString); surfaceSizeField.tag = "surfacesize"; surfaceSizeField.AttachComponent(surfaceSizeFieldTitle); surfaceSizeFieldTitle.SetTextPosition("right", "center"); surfaceSizeFieldTitle.SetPivots("left", "center", "outside", 0); surfaceSizeFieldTitle.SetInitialPosition(surfaceSizeField); //Seed field MenuText seedFieldTitle = new MenuText(new Vector2i(100, 25), mapGenFont, "Map Seed:", 24, 24); MenuField seedField = new MenuField(new Vector2i(150, 25), mapGenFont, surfaceGenerator.ParseString); seedField.tag = "seed"; seedField.AttachComponent(seedFieldTitle); seedFieldTitle.SetTextPosition("right", "center"); seedFieldTitle.SetPivots("left", "center", "outside", 0); seedFieldTitle.SetInitialPosition(seedField); //Start game button MenuButton startGame = new MenuButton(new Vector2i(100, 40), program.SwitchGameState); MenuText startGameText = new MenuText(new Vector2i(100, 40), mapGenFont, "Start Game", 24, 24); startGame.AttachComponent(startGameText); startGameText.SetTextPosition("center", "center"); startGameText.SetPivots("center", "center", "inside", 0); startGame.tag = "inGame"; //Slider MenuSlider elevationFactor = new MenuSlider(5, surfaceGenerator.SetNoiseFactor, 0.5f, 1.5f, 1.0f); elevationFactor.tag = "elevation"; MenuText elevationSliderText = new MenuText(new Vector2i(150, 25), mapGenFont, "Elevation Factor", 24, 24); MenuSlider moistureFactor = new MenuSlider(5, surfaceGenerator.SetNoiseFactor, 0.5f, 1.5f, 1.0f); moistureFactor.tag = "moisture"; MenuText moistureSliderText = new MenuText(new Vector2i(150, 25), mapGenFont, "Moisture Factor", 24, 24); MenuSlider temperatureFactor = new MenuSlider(5, surfaceGenerator.SetNoiseFactor, 0.5f, 1.5f, 1.0f); MenuText temperatureSliderText = new MenuText(new Vector2i(150, 25), mapGenFont, "Temperature Factor", 24, 24); temperatureFactor.tag = "temperature"; //Attaching Elements worldMenu.AttachComponent(startGame); worldMenu.AttachComponent(seedField); worldMenu.AttachComponent(surfaceSizeField); worldMenu.AttachComponent(temperatureNoiseType); worldMenu.AttachComponent(elevationNoiseType); worldMenu.AttachComponent(moistureNoiseType); worldMenu.AttachComponent(moistureNoiseText); worldMenu.AttachComponent(temperatureNoiseText); worldMenu.AttachComponent(elevationNoiseText); worldMenu.AttachComponent(elevationFactor); worldMenu.AttachComponent(moistureFactor); worldMenu.AttachComponent(temperatureFactor); worldMenu.AttachComponent(elevationSliderText); worldMenu.AttachComponent(moistureSliderText); worldMenu.AttachComponent(temperatureSliderText); //Positioning elements seedField.SetRelativePosition(new Vector2i(100, 25)); surfaceSizeField.SetPivots("bottom", "center", "outside", 25); surfaceSizeField.SetInitialPosition(seedField); startGame.SetPivots("bottom", "right", "inside", 25); startGame.SetInitialPosition(); worldMenu.SetInitialPosition(camera.GetGUIView()); elevationFactor.SetInitialPosition(camera.GetGUIView()); moistureFactor.SetPivots("bottom", "center", "outside", 25); moistureFactor.SetInitialPosition(elevationFactor); temperatureFactor.SetPivots("bottom", "center", "outside", 25); temperatureFactor.SetInitialPosition(moistureFactor); moistureNoiseType.SetPivots("top", "right", "inside", 25); moistureNoiseType.SetInitialPosition(camera.GetGUIView()); elevationNoiseType.SetPivots("bottom", "center", "outside", 25); elevationNoiseType.SetInitialPosition(moistureNoiseType); temperatureNoiseType.SetPivots("bottom", "center", "outside", 25); temperatureNoiseType.SetInitialPosition(elevationNoiseType); moistureNoiseText.SetRelativePosition(moistureNoiseType.position - new Vector2i(230, 0)); elevationNoiseText.SetRelativePosition(elevationNoiseType.position - new Vector2i(230, 0)); temperatureNoiseText.SetRelativePosition(temperatureNoiseType.position - new Vector2i(230, 0)); moistureSliderText.SetRelativePosition(moistureFactor.position - new Vector2i(150, 0)); elevationSliderText.SetRelativePosition(elevationFactor.position - new Vector2i(150, 0)); temperatureSliderText.SetRelativePosition(temperatureFactor.position - new Vector2i(150, 0)); //Finalize into menu container menuContainer.AttachMenu(worldMenu); }