Exemple #1
0
 public TerrainGenerator(PerlinNoise perlinNoise, PerlinNoise biomePerlinNoise, ColourGenerator colourGen, BiomeHelper biomeHelper)
 {
     this.perlinNoise      = perlinNoise;
     this.biomePerlinNoise = biomePerlinNoise;
     this.colourGen        = colourGen;
     this.biomeHelper      = biomeHelper;
 }
Exemple #2
0
        public UtopiaProcessor(WorldParameters worldParameters, EntityFactory entityFactory, LandscapeBufferManager landscapeEntityManager)
        {
            _worldParameters        = worldParameters;
            _entityFactory          = entityFactory;
            _config                 = (UtopiaWorldConfiguration)worldParameters.Configuration;
            _biomeHelper            = new BiomeHelper(_config);
            _worldGeneratedHeight   = _config.ProcessorParam.WorldGeneratedHeight;
            _landscapeBufferManager = landscapeEntityManager;
            LandscapeEntities       = new LandscapeEntities(_landscapeBufferManager, _worldParameters);
            _spawnControler         = new UtopiaEntitySpawningControler(_config);

            landscapeEntityManager.Processor = this;
        }
Exemple #3
0
    // Generate "random" Biomes for the alphamap, based on Perlin noise
    private void generateBiomes()
    {
        // Create the layers with the right texture for each biome
        Dictionary <Biome, Texture2D> layers = GetLayers();

        LayersHelper layersHelper = new LayersHelper(GameSettings.terrainAlphamapRes, layers);

        terrainData.terrainLayers = layersHelper.GetTerrainLayers();

        // Gnenerate an terrainData.heigthMap using Perlin Noise

        generateHeightsMap();

        // Map the terrain to layers according to biomes (based on altitude, temperature & humidity)
        BiomeHelper  biomes = new BiomeHelper(this);
        TerrainTiles tiles  = new TerrainTiles(biomes);

        Biome biome;
        int   hmx, hmz;
        float height;
        float jitter = 1f / GameSettings.terrainAlphamapRes;

        float[,] flatHeight = new float[1, 1];
        flatHeight[0, 0]    = 0.5f;
        for (int z = 0; z < GameSettings.terrainAlphamapRes; z++)
        {
            for (int x = 0; x < GameSettings.terrainAlphamapRes; x++)
            {
                hmx    = (int)(x * GameSettings.factor_h2a);
                hmz    = (int)(z * GameSettings.factor_h2a);
                height = terrainData.GetHeight(hmx, hmz) / GameSettings.terrainMaxAltitude;

                var pos = new Vector2Int(x, z);
                biome = biomes.GetBiomeAt(pos, height);

                layersHelper.SetAt(x, z, biome);

                if (height < flatHeight[0, 0])
                {
                    height = flatHeight[0, 0];
                    // Flaten the low lands, to get to ~50% of flat areas (easier to build on)
                    terrainData.SetHeights(hmx, hmz, flatHeight);
                }

                // Create a tile (at alphamap location) with items on it according to it's biome
                tiles.AddTile(pos, height, biome);
            }
        }
        terrainData.SetAlphamaps(0, 0, layersHelper.GetAlphaMaps());
    }
Exemple #4
0
            public void returnsTrueIfHasOneNullSurrounding(int x, int y, int z, int ox, int oy, int oz)
            {
                Board board = new Board();

                board.setTile(new HexagonalCoordinate(x, y, z), Tile.CLAY);
                foreach (var neighbor in new HexagonalCoordinate(x, y, z).getNeighbors())
                {
                    if (Board.isOnBoard(neighbor))
                    {
                        board.setTile(neighbor, Tile.WOOD);
                    }
                }
                board.setTile(new HexagonalCoordinate(ox, oy, oz), null);
                Assert.True(BiomeHelper.evaluateCoordinate(board, new HexagonalCoordinate(x, y, z)));
            }
Exemple #5
0
    public Color[] GenerateColours(float[,] heightMap, float[,] biomeMap, BiomeHelper biomeHelper, int size)
    {
        this.biomeHelper = biomeHelper;

        Color[] colourMap = new Color[Mathf.RoundToInt(5.8806f * (size * size))];
        for (int y = 0; y < size; y++)
        {
            for (int x = 0; x < size; x++)
            {
                colourMap[y * size + x] = BlendColours(GetNeighbourColours(x, y, heightMap, biomeMap));
            }
        }

        return(colourMap);
    }
Exemple #6
0
    public static MeshData GenerateTerrainMesh(Terrain terrain, BiomeHelper biomeHelper, float heightMultiplier, AnimationCurve meshHeightCurve, int levelOfDetail)
    {
        AnimationCurve heightCurve = new AnimationCurve(meshHeightCurve.keys);
        int            size        = terrain.heightMap.GetLength(0);
        float          topLeftX    = (size - 1) / -2f;
        float          topLeftZ    = (size - 1) / 2f;

        int meshSimplificationIncrement = levelOfDetail == 0 ? 1 : levelOfDetail * 2;
        int verticesPerLine             = (size - 1) / meshSimplificationIncrement + 1;

        MeshData meshData    = new MeshData(verticesPerLine);
        int      vertexIndex = 0;

        for (int y = 0; y < size; y += meshSimplificationIncrement)
        {
            for (int x = 0; x < size; x += meshSimplificationIncrement)
            {
                Biome biome = biomeHelper.GetBiome(terrain.biomeMap[x, y]);
                meshData.vertices[vertexIndex] = new Vector3(topLeftX + x, heightCurve.Evaluate(terrain.heightMap[x, y]) * heightMultiplier * (biome != null ? biome.heightMultiplier : 1), topLeftZ - y);
                meshData.uvs[vertexIndex]      = new Vector2(x / (float)size, y / (float)size);

                if (x < size - 1 && y < size - 1)
                {
                    meshData.AddTriangle(vertexIndex, vertexIndex + verticesPerLine + 1, vertexIndex + verticesPerLine);
                    meshData.AddTriangle(vertexIndex + verticesPerLine + 1, vertexIndex, vertexIndex + 1);
                }

                vertexIndex++;
            }
        }

        meshData.SetColours(terrain.colourMap);
        meshData.ApplyFlatShading();

        return(meshData);
    }
Exemple #7
0
        public static void DrawMenu(GameTime gameTime)
        {
            //float uiScaleWanted = Main._uiScaleWanted;
            //Main.UIScale = 1f;
            //Main._uiScaleWanted = uiScaleWanted;

            //if (!(bool)IsEngineLoaded.GetValue(null))
            //{
            //	  IsEngineLoaded.SetValue(null, true);
            //	  EventHelper.InvokeEvent(Main.instance, nameof(Main.OnEngineLoad));
            //}

            GamepadMainMenuHandler.Update();
            GamepadMainMenuHandler.MenuItemPositions.Clear();

            //int num = Main.menuMode;

            //if (MenuState <= MenuMode.PlayerSelection && Main.slimeRain)
            if (Main.slimeRain)
            {
                Main.StopSlimeRain();
            }

            Main.render = false;

            Star.UpdateStars();
            Cloud.UpdateClouds();
            BiomeHelper.ResetTiles();

            Main.drawingPlayerChat = false;             //i wonder what would happen if this was set to true

            for (int i = 0; i < Main.numChatLines; i++)
            {
                Main.chatLine[i] = new ChatLine();
            }

            FPSCounterSystem.DrawFPS();

            Main.screenLastPosition = Main.screenPosition;
            Main.screenPosition.Y   = (float)(Main.worldSurface * 16.0 - Main.screenHeight);

            if (Main.grabSky)
            {
                Main.screenPosition.X += (Main.mouseX - Main.screenWidth / 2) * 0.02f;
            }
            else
            {
                Main.screenPosition.X += 2f;
            }

            Main.background = 0;

            /* skiped logo ahh
             * byte b = (byte)((255 + Main.tileColor.R * 2) / 3);
             * Microsoft.Xna.Framework.Color color = new Microsoft.Xna.Framework.Color(b, b, b, 255);
             *
             * Microsoft.Xna.Framework.Color color2 = new Microsoft.Xna.Framework.Color((byte)(color.R * (Main.LogoA / 255f)), (byte)(color.G * (Main.LogoA / 255f)), (byte)(color.B * (Main.LogoA / 255f)), (byte)(color.A * (Main.LogoA / 255f)));
             * Microsoft.Xna.Framework.Color color3 = new Microsoft.Xna.Framework.Color((byte)(color.R * (Main.LogoB / 255f)), (byte)(color.G * (Main.LogoB / 255f)), (byte)(color.B * (Main.LogoB / 255f)), (byte)(color.A * (Main.LogoB / 255f)));
             * if (Main.dayTime)
             * {
             *      Main.LogoA += 2;
             *      if (Main.LogoA > 255)
             *      {
             *              Main.LogoA = 255;
             *      }
             *      Main.LogoB--;
             *      if (Main.LogoB < 0)
             *      {
             *              Main.LogoB = 0;
             *      }
             * }
             * else
             * {
             *      Main.LogoB += 2;
             *      if (Main.LogoB > 255)
             *      {
             *              Main.LogoB = 255;
             *      }
             *      Main.LogoA--;
             *      if (Main.LogoA < 0)
             *      {
             *              Main.LogoA = 0;
             *              Main.LogoT = true;
             *      }
             * }*/
        }
Exemple #8
0
 public TerrainTiles(BiomeHelper biomes)
 {
     this.biomes = biomes;
 }
Exemple #9
0
 public FlatTerrainGenerator(PerlinNoise perlinNoise, PerlinNoise biomePerlinNoise, ColourGenerator colourGen, BiomeHelper biomeHelper)
     : base(perlinNoise, biomePerlinNoise, colourGen, biomeHelper)
 {
 }