private void CreateBackground(Background layers, int layerCount)
        {
            Sprite stars = new Sprite(Content.Load <Texture2D>("Images/nebula1"));

            stars.Color = Color.White * 0.2f;
            stars.Scale = 3.0f;
            layers.AddLayer(stars, new Vector2(0.02f, 0.02f));

            List <Texture2D> nebulas = new List <Texture2D>();

            nebulas.Add(Content.Load <Texture2D>("Images/nebula1"));
            nebulas.Add(Content.Load <Texture2D>("Images/nebula2"));

            Random    r        = new Random();
            float     parallax = 1.0f;
            Rectangle areaSize = CurrentLevel.Bounds;

            for (int i = 0; i < layerCount; i++)
            {
                int           spritesPerLayer = 5 + r.Next(100);
                List <Sprite> sprites         = new List <Sprite>();
                for (int j = 0; j < spritesPerLayer; j++)
                {
                    int    si  = r.Next(100) % nebulas.Count;
                    Sprite neb = new Sprite(nebulas[si]);
                    neb.Position = Interpolations.GetRandomRectanglePoint(areaSize, r);
                    neb.Scale    = (float)(r.NextDouble() * 2f) + 0.1f;
                    neb.Rotation = (float)r.NextDouble() * MathHelper.PiOver2;
                    sprites.Add(neb);
                }
                layers.AddLayer(sprites, new Vector2(parallax, parallax));
                parallax += (0.9f / layerCount);
            }
        }
        private Background CreateBackground(int layerCount)
        {
            Background background = new Background(camera);

            Sprite stars = new Sprite(StateManager.Content.Load <Texture2D>("Images/nebula1"));

            stars.Color = Color.White * 0.2f;
            stars.Scale = 3.0f;
            background.AddLayer(stars, new Vector2(0.02f, 0.02f));

            List <Texture2D> nebulas = new List <Texture2D>();

            nebulas.Add(StateManager.Content.Load <Texture2D>("Images/nebula1"));
            nebulas.Add(StateManager.Content.Load <Texture2D>("Images/nebula2"));

            Random r = new Random();

            for (int i = 0; i < layerCount; i++)
            {
                int    si  = r.Next(100) % nebulas.Count;
                Sprite neb = new Sprite(nebulas[si]);
                neb.Position = Interpolations.GetRandomRectanglePoint(idleStateArea, r);
                neb.Scale    = (float)r.NextDouble() + 0.1f;
                neb.Rotation = (float)r.NextDouble() * MathHelper.PiOver2;
                float r2 = (float)r.NextDouble() * neb.Scale;
                background.AddLayer(neb, new Vector2(r2, r2));
            }

            return(background);
        }
        public void InitializeLevel(Rectangle bounds)
        {
            CurrentLevel  = new Level(bounds);
            shipTexture   = Content.Load <Texture2D>("Images/ship2");
            bulletTexture = Content.Load <Texture2D>("Images/bullet1");

            SetupParticleSystem();

            Layers = new Background(PlayCamera);
            CreateBackground(Layers, 5);

            // Setup player
            EntityLayer = Layers.AddLayer(new Vector2(1.0f, 1.0f));
            CurrentLevel.EntityLayer = EntityLayer;
            AddPlanets(EntityLayer);

            CurrentLevel.SetPlayer(CreatePlayer(shipTexture), EntityLayer);
            soundHit = Content.Load <SoundEffect>("Samples/shot");

            ResetGame();
            EntityLayer.AddParticleEffect(shipEffect);
            EntityLayer.AddParticleEffect(shipEffect2);
        }