Implementation of the Perlin simplex noise, an improved Perlin noise algorithm. Based loosely on SimplexNoise1234 by Stefan Gustavson http://staffwww.itn.liu.se/~stegu/aqsis/aqsis-newnoise/
 private static float GetStaticRandom(int x, int y)
 {
     return(PerlinSimplexNoise.noise((float)x * NoiseScale.x, (float)y * NoiseScale.y));
 }
Esempio n. 2
0
	///////////////////////////////////////////////////////////////////////////
	// Functions:

	public CGalaxy()
	{
		sGalaxy = this;

		// Instantiate galaxy noises.
		for (uint ui = 0; ui < (uint)ENoiseLayer.MAX; ++ui)
			mNoises[ui] = new PerlinSimplexNoise();
	}
Esempio n. 3
0
        private void render()
        {
            {
                var color1 = new Vector3(0.8f, 0.8f, 0.8f);
                var color2 = new Vector3(0.7f, 0.7f, 0.7f);


                var screenAABB = Camera.mainCamera.worldBounds;
                var wx0        = Math.Floor(screenAABB.X0 / tileSize);
                var wx1        = Math.Ceiling(screenAABB.X1 / tileSize);
                var wy0        = Math.Floor(screenAABB.Y0 / tileSize);
                var wy1        = Math.Ceiling(screenAABB.Y1 / tileSize);

                var minX = (int)Math.Max(0, wx0);
                var maxX = (int)Math.Min(_width.Number, wx1);
                var minY = (int)Math.Max(0, wy0);
                var maxY = (int)Math.Min(_height.Number, wy1);

                for (var y = minY; y < maxY; y++)
                {
                    for (var x = minX; x < maxX; x++)
                    {
                        var p = new Vector2(x * tileSize, y * tileSize);

                        //var c = color1.Lerp(color2, z / 10f);
                        //if (shadowmap[x, y])
                        //    c *= 0.9f;
                        var texture = _open;
                        var color   = Color.Black;
                        switch (tiles[x, y].tileType)
                        {
                        case MapTileType.Blocked:
                            texture = _blocked;
                            break;

                        case MapTileType.Room:
                            texture = _room;
                            color   = new Color(color1.Lerp(color2, (1 + PerlinSimplexNoise.noise(x * 0.5f, y * 0.5f)) / 2));
                            break;

                        case MapTileType.Wall:
                            texture = _wall;
                            color   = new Color(0.2f, 0.2f, 0.2f);
                            break;
                        }

                        Root.instance.graphics.Draw(0, texture, AxisAlignedBox.FromRect(p, tileSize, tileSize), color, 0);

                        //if (z == heights[x, y] - 1)
                        //{
                        //    if (((x + 1 < size && heights[x + 1, y] > heights[x, y])))
                        //        Root.instance.graphics.Draw(0, _shadow_hort, _material, AxisAlignedBox.FromRect(p, tileSize, tileSize), Color.White, z + 0.1f);
                        //    if (((y - 1 >= 0 && heights[x, y - 1] > heights[x, y])))
                        //        Root.instance.graphics.Draw(0, _shadow_vert, _material, AxisAlignedBox.FromRect(p, tileSize, tileSize), Color.White, z + 0.1f);

                        //    if (((x - 1 >= 0 && heights[x - 1, y] > heights[x, y])))
                        //        Root.instance.graphics.Draw(0, _shadow_hort, _material, AxisAlignedBox.FromRect(p, tileSize, tileSize), Color.White, SpriteEffects.FlipHorizontally, z + 0.1f);
                        //    if (((y + 1 < size && heights[x, y + 1] > heights[x, y])))
                        //        Root.instance.graphics.Draw(0, _shadow_vert, _material, AxisAlignedBox.FromRect(p, tileSize, tileSize), Color.White, SpriteEffects.FlipVertically, z + 0.1f);
                        //}

                        //if ((x - 1 < 0 || heights[x - 1, y] < heights[x, y]) && z == heights[x, y] - 1)
                        //{
                        //    Root.instance.graphics.DrawLine(0, null, null, new Vector2(x * tileSize, y * tileSize - z * tileHeight), new Vector2(x * tileSize, (y + 1) * tileSize - z * tileHeight), Color.Black, z + 0.1f);
                        //}
                        //if ((x + 1 >= size || heights[x + 1, y] < heights[x, y]) && z == heights[x, y] - 1)
                        //{
                        //    Root.instance.graphics.DrawLine(0, null, null, new Vector2((x + 1) * tileSize, y * tileSize - z * tileHeight), new Vector2((x + 1) * tileSize, (y + 1) * tileSize - z * tileHeight), Color.Black, z + 0.1f);
                        //}
                        //if ((y - 1 < 0 || heights[x, y - 1] < heights[x, y]) && z == heights[x, y] - 1)
                        //{
                        //    Root.instance.graphics.DrawLine(0, null, null, new Vector2(x * tileSize, y * tileSize - z * tileHeight), new Vector2((x + 1) * tileSize, y * tileSize - z * tileHeight), Color.Black, z + 0.1f);
                        //}
                        //if ((y + 1 >= size || heights[x, y + 1] < heights[x, y]) && z == heights[x, y] - 1)
                        //{
                        //    Root.instance.graphics.DrawLine(0, null, null, new Vector2(x * tileSize, (y + 1) * tileSize - z * tileHeight), new Vector2((x + 1) * tileSize, (y + 1) * tileSize - z * tileHeight), Color.Black, z + 0.1f);
                        //}
                        //if ((x - 1 < 0 || heights[x - 1, y] < z + 1) && (y + 1 >= size || heights[x, y + 1] < z + 1))
                        //    Root.instance.graphics.DrawLine(0, null, null, new Vector2(x * tileSize, (y + 1) * tileSize - z * tileHeight), new Vector2(x * tileSize, (y + 1) * tileSize - z * tileHeight + tileHeight), Color.Black, z + 0.1f);
                        //if ((x + 1 >= size || heights[x + 1, y] < z + 1) && (y + 1 >= size || heights[x, y + 1] < z + 1))
                        //    Root.instance.graphics.DrawLine(0, null, null, new Vector2((x + 1) * tileSize, (y + 1) * tileSize - z * tileHeight), new Vector2((x + 1) * tileSize, (y + 1) * tileSize - z * tileHeight + tileHeight), Color.Black, z + 0.1f);
                    }
                }

                //Root.instance.graphics.DrawRect(1, null, null, AxisAlignedBox.FromDimensions(Vector2.One * 250, Vector2.One * 25), Color.Pink);
            }
            //{
            //    var go = Root.instance.RootObject.find("player");
            //    var physics = go.getScript<Physics>();

            //    var screenAABB = physics.shape;
            //    var wx0 = Math.Floor(screenAABB.X0 / tileSize);
            //    var wx1 = Math.Ceiling(screenAABB.X1 / tileSize);
            //    var wy0 = Math.Floor(screenAABB.Y0 / tileSize);
            //    var wy1 = Math.Ceiling(screenAABB.Y1 / tileSize);

            //    var minX = (int)Math.Max(0, wx0);
            //    var maxX = (int)Math.Min(_width.Number, wx1);
            //    var minY = (int)Math.Max(0, wy0);
            //    var maxY = (int)Math.Min(_height.Number, wy1 );

            //    var hs = tileSize * Game.WORLD_SCALE * Vector2.One;
            //    var aabb = AxisAlignedBox.FromRect(Vector2.Zero, hs);
            //    var mtv = MinimumTranslationVector.Zero;
            //    for (var y = minY; y < maxY; y++)
            //    {
            //        for (var x = minX; x < maxX; x++)
            //        {
            //            if (tiles[x, y].tileType != MapTileType.Room)
            //            {
            //                aabb.Center = new Vector2(x, y) * tileSize * Game.WORLD_SCALE + hs / 2;

            //                Root.instance.graphics.DrawRect(1, null, null, aabb, Color.Green);
            //            }
            //        }
            //    }

            //}
        }