public void Init(int X, int Y)
        {
            ChunkX = X;
            ChunkY = Y;

            var MapData = Noise2d.GenerateNoiseMap(ChunkX * ChunkManager.Instance.ChunkWidth, ChunkY * ChunkManager.Instance.ChunkHeight,
                                                   ChunkManager.Instance.ChunkWidth, ChunkManager.Instance.ChunkHeight, 8, 256);
            var BaseTileData       = new int[ChunkManager.Instance.ChunkWidth, ChunkManager.Instance.ChunkHeight];
            var DecorationTileData = new int[ChunkManager.Instance.ChunkWidth, ChunkManager.Instance.ChunkHeight];

            ChunkTileData = new TileData[ChunkManager.Instance.ChunkWidth, ChunkManager.Instance.ChunkHeight];

            for (var i = 0; i < ChunkManager.Instance.ChunkWidth; i++)
            {
                for (var j = 0; j < ChunkManager.Instance.ChunkHeight; j++)
                {
                    BaseTileData[i, j]
                        = TerrainGen.TileForHeight((ChunkX * ChunkManager.Instance.ChunkWidth) + i, (ChunkY * ChunkManager.Instance.ChunkHeight) + j,
                                                   MapData[i, j]);


                    DecorationTileData[i, j] = -1;

                    //527
                    var tree = TerrainGen.WantTree(
                        (ChunkX * ChunkManager.Instance.ChunkWidth) + i, (ChunkY * ChunkManager.Instance.ChunkHeight) + j, MapData[i, j]);


                    TileData tData = new TileData();
                    tData.ChunkTileOffsetX = i;
                    tData.ChunkTileOffsetY = j;
                    tData.TileBaseType     = BaseTileData[i, j];
                    tData.TileDetailType   = DecorationTileData[i, j];
                    tData.TileX            = (ChunkX * ChunkManager.Instance.ChunkWidth) + i;
                    tData.TileY            = (ChunkY * ChunkManager.Instance.ChunkHeight) + j;
                    tData.TileEntity       = new Entity();

                    if (tree)
                    {
                        tData.TileEntity.addComponent <TIleCollider>();

                        tData.TileEntity.addComponent(new ResourceTile("wood", 527, tData));
                    }

                    tData.UpdateWalkableState();
                    ChunkTileData[i, j] = tData;
                }
            }
        }
예제 #2
0
        public void ConstructTileMap()
        {
            var noiseMap = Noise2d.GenerateNoiseMap(13, 13, 2);
            var walker   = 0;

            var sqr3 = Mathf.Sqrt(3);

            foreach (var t in _holder.TileMap)
            {
                var c   = t.Coord;
                var pos = new Vector3(sqr3 * c.Q + sqr3 * c.R / 2, 0, 1.5f * c.R) -
                          new Vector3(_holder.TileMap.Radius * 1.5f * sqr3, 0, _holder.TileMap.Radius * 1.5f);
                var tile = Instantiate(hexTilePrefab, transform);
                tile.Init(t, OnClickTile);
                var a = noiseMap[walker / 13, walker % 13];
                tile.GetComponent <SpriteRenderer>().color = new Color(a, a, a);
                tile.transform.localPosition = pos;
                walker++;
            }
        }
예제 #3
0
        public Hills(int seed, int width, int height, float frequency, float amplitude) : base(seed, width, height)
        {
            Noise2d noise = new Noise2d(seed);

            noiseMap = noise.GenerateNoiseMap(width, height, frequency, amplitude);
        }
예제 #4
0
        public FogOfWar(int seed, int width, int height, GraphicsDeviceManager graphics)
        {
            Noise = new Noise2d(seed);

            Width  = width;
            Height = height;

            Vertecies = new VertexPositionColor[width * height * 6];
            var NoiseMap = Noise.GenerateNoiseMap(width, height, 100f, 1f);

            int    i      = 0;
            Random random = new Random(123);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    float value1 = NoiseMap[y * width + x];
                    float value2 = NoiseMap[Math.Min(y * width + x + 1, width * height - 1)];
                    float value3 = NoiseMap[Math.Min((y + 1) * width + x, width * height - 1)];
                    float value4 = NoiseMap[Math.Min((y + 1) * width + x + 1, width * height - 1)];

                    int al1 = 255; //random.NextDouble() > 0.2 ? 0 : 255;
                    int al2 = 255; //random.NextDouble() > 0.2 ? 0 : 255;


                    Color color1 = Color.FromNonPremultiplied(40, 40, (int)(value1 * 255), al1);
                    Color color2 = Color.FromNonPremultiplied(40, 40, (int)(value2 * 255), al1);
                    Color color3 = Color.FromNonPremultiplied(40, 40, (int)(value3 * 255), al1);
                    Color color4 = Color.FromNonPremultiplied(40, 40, (int)(value4 * 255), al1);

                    Color color1x = Color.FromNonPremultiplied(40, 40, (int)(value1 * 255), al2);
                    Color color2x = Color.FromNonPremultiplied(40, 40, (int)(value2 * 255), al2);
                    Color color3x = Color.FromNonPremultiplied(40, 40, (int)(value3 * 255), al2);
                    Color color4x = Color.FromNonPremultiplied(40, 40, (int)(value4 * 255), al2);

                    int cx = x * TILE_WIDTH;
                    int cy = y * TILE_DEPTH;

                    int   nx    = cx + TILE_WIDTH;
                    int   ny    = cy + TILE_DEPTH;
                    Color color = Color.Blue;//value > 10 ? value > 20 ? Color.SandyBrown: Color.Green : Color.Blue;

                    int a = 10;
                    Vertecies[i]     = new VertexPositionColor(new Vector3(cx, cy, value1 * a), color1);
                    Vertecies[i + 1] = new VertexPositionColor(new Vector3(cx, ny, value3 * a), color3);
                    Vertecies[i + 2] = new VertexPositionColor(new Vector3(nx, cy, value2 * a), color2);

                    Vertecies[i + 3] = new VertexPositionColor(Vertecies[i + 1].Position, color3x);
                    Vertecies[i + 4] = new VertexPositionColor(new Vector3(nx, ny, value4 * a), color4x);
                    Vertecies[i + 5] = new VertexPositionColor(Vertecies[i + 2].Position, color2x);

                    i += 6;
                }
            }

            //using (var reader = new BinaryReader(File.Open("Content/Shaders/FogOfWar.xnb", FileMode.Open)))
            //{
            //    effect = new Effect(graphics.GraphicsDevice, reader.ReadBytes((int)reader.BaseStream.Length));
            //}

            //effect = new BasicEffect(graphics.GraphicsDevice);
        }