Esempio n. 1
0
        static void Main(string[] args)
        {
            //var dsConfig = new DiamondSquareConfig(12, 0.67f);
            var pnConfig1  = new NoiseConfig(2000, 0.7);
            var generator1 = new Noise(pnConfig1);
            var h1         = generator1.GenerateAsync();

            var pnConfig2  = new NoiseConfig(2000, 0.25);
            var generator2 = new Noise(pnConfig2);
            var h2         = generator2.GenerateAsync();

            var hlayer1     = new HeightmapLayer(h1.Result);
            var hlayer2     = new HeightmapLayer(h2.Result);
            var hlayerCells = HeightmapLayer.Overlay(hlayer1, hlayer2, new OverlayFloatSum());
            var hlayer      = new HeightmapLayer(
                HeightmapLayer.NormalizeHeights(
                    new HeightmapLayer(hlayerCells)));

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            var m = new Map();

            m.AddLayer <HeightmapLayer, float>(hlayer);
            var waterLine  = WaterLayer.GetWaterlineFromPercentage(hlayer, 0.35f);
            var waterLayer = new WaterLayer(hlayer, waterLine);

            m.AddLayer <WaterLayer, bool>(waterLayer);

            CreateImage(pnConfig1, hlayer, waterLayer);

            stopWatch.Stop();
            Debug.WriteLine(stopWatch.Elapsed);
        }
Esempio n. 2
0
        private static void CreateImage(NoiseConfig config, HeightmapLayer layer, WaterLayer waterLayer)
        {
            var bmp       = new Bitmap(config.Size, config.Size);
            var maxDepth  = waterLayer.Waterline - layer.MinHeight;
            var maxHeight = layer.MaxHeight - waterLayer.Waterline;

            for (var x = 0; x < config.Size; x++)
            {
                for (var y = 0; y < config.Size; y++)
                {
                    if (waterLayer.GetCell(x, y))
                    {
                        var depth = waterLayer.Waterline - layer.GetCell(x, y);
                        var g     = 255 - (byte)(255 * (depth / maxDepth));
                        var b     = 255 - (byte)(100 * (depth / maxDepth));
                        bmp.SetPixel(x, y, Color.FromArgb(0, g, b));
                    }
                    else
                    {
                        var height = layer.GetCell(x, y) - waterLayer.Waterline;
                        var b      = (byte)(50 * height / maxHeight);
                        var r      = (byte)(255 * height / maxHeight);
                        var g      = 175 - (byte)(50 * height / maxHeight);
                        bmp.SetPixel(x, y, Color.FromArgb(r, g, b));
                    }
                }
            }

            var codec    = GetEncoder(ImageFormat.Jpeg);
            var filename = "test.jpg";

            bmp.Save(filename, codec, GetEncoderParameters());
        }
Esempio n. 3
0
        public void ResetGame()
        {
            gameProgress = 0;
            elapsedTimeSinceLastPowerUp = 0.0f;
            cloudOffsets = Vector2.Zero;

            Components.Clear();

            world = new World(new Vector2(0, 25));

            staticWorldGround = BodyFactory.CreateRectangle(world, worldWidthInBlocks, 1, 1.0f, new Vector2(worldWidthInBlocks / 2.0f, 0.5f));
            staticWorldL = BodyFactory.CreateRectangle(world, 4, worldHeightInBlocks, 1.0f, new Vector2(2.0f, -worldHeightInBlocks / 2.0f));
            staticWorldR = BodyFactory.CreateRectangle(world, 1, worldHeightInBlocks, 1.0f, new Vector2(worldWidthInBlocks, -worldHeightInBlocks / 2.0f));
            staticWorldGround.BodyType = BodyType.Static;
            staticWorldL.BodyType = BodyType.Static;
            staticWorldR.BodyType = BodyType.Static;
            staticWorldGround.Friction = 100.0f;
            staticWorldL.Friction = 100.0f;
            staticWorldR.Friction = 100.0f;
            staticWorldGround.CollisionCategories = COLLISION_GROUP_STATIC_OBJECTS;
            staticWorldL.CollisionCategories = COLLISION_GROUP_LEVEL_SEPARATOR;
            staticWorldR.CollisionCategories = COLLISION_GROUP_LEVEL_SEPARATOR;

            tetris = new TetrisPlayer(this, world);
            Components.Add(tetris);

            Components.Add(platform = new PlatformPlayer(this, world));

            // Create other level components
            WaterLayer = new WaterLayer(this);
            SavePlatform = new SavePlatform(this);
            Components.Add(SavePlatform);
            Components.Add(WaterLayer);

            waveLayer = new WaveLayer(this);
            Components.Add(waveLayer);

            titleScreenLayer = new TitleScreenLayer(this);
            gameOverLayer = new GameOverLayer(this);

            tetrisViewport = new GameViewport(this, gameBlockSizeTetris);
            tetrisViewport.resize(1280, 720);
            tetris.viewportToSpawnIn = tetrisViewport;

            Components.Add(tetrisViewport);

            // Add GUI components
            StatusLayer = new GameStatusLayer(this);
            Components.Add(StatusLayer);

            MusicManager.StopMusic();
        }