/// <summary>
        /// Loads graphics content for this screen. The background texture is quite
        /// big, so we use our own local ContentManager to load it. This allows us
        /// to unload before going from the menus into the game itself, wheras if we
        /// used the shared ContentManager provided by the Game class, the content
        /// would remain loaded forever.
        /// </summary>
        public override void LoadContent(ContentManager _content)
        {
            //world = LevelDataManager.nextworld;
            //if (world < 1 || world > 6) world = 1;
            parallaxEngine = new ParallaxManager();
            Camera.ResetZoom();
            //if (content == null)
            //    content = new ContentManager(ScreenManager.Game.Services, "Content");

            //the Level data manager instances its own content manager
            LevelDataManager.Initialize(ScreenManager.Game, parallaxEngine, world, level);
            LevelDataManager.UItextures.TryGetValue("Pixel", out pixel);

            Camera.CameraPositionLimits = Camera.WorldRectangle;
            Camera.LookAt(new Vector2 (0, Camera.WorldRectangle.Bottom));

            foreach (Layer layer in parallaxEngine.worldLayers)
            {
                layer.IsRepreating = true;
                layer.IsRepreatingSeamless = true;
                layer.IsAwake = true;
                layer.LayerVelocity = 0f;
                layer.IsLayerMotion = false;
                layer.LayerVDirection = new Vector2(-1,0);

            }

            decoManager = new DecoManager(parallaxEngine, false);
            for (int i = 0; i < parallaxEngine.worldLayers.Count; i++)
            {
                for (int j = 0; j < parallaxEngine.worldLayers[i].layerSprites.Count; j++)
                {
                    if (parallaxEngine.worldLayers[i].layerSprites[j].SpriteType == Sprite.Type.Deco)
                    {
                        decoManager.InitializeDeco(parallaxEngine.worldLayers[i].layerSprites[j]);
                    }
                }
            }
        }
        public static void Initialize(Game game, ParallaxManager _parallaxEngine, int _world, int _level)
        {
            rand = new Random();
            parallaxEngine = _parallaxEngine;

            if (tempContent == null)
            {
                tempContent = new ContentManager(game.Services, "Content");
            }

            if (levelContent == null)
            {
                levelContent = new ContentManager(game.Services, "Content");
                levelTextures = new List<TextureData>();
            }

            if (effectsContent == null)
            {
                effectsContent = new ContentManager(game.Services, "Content");
                effectTextures = new List<TextureData>();
                //load effects
                LoadTextures("Content\\Textures\\Effects\\EffectTextures.pck");
            }

            //reinitialize UI content if it is empty somehow
            if (UIcontent == null) SplashPreInitialize(game);

            if (world != _world)
            {
                UnloadLevelData();
                worldChanged = true; //flag for the load world function
            }
            else worldChanged = false;

            if (level != _level)
            {
                levelChanged = true; //flag for the soundManager music function
            }
            else levelChanged = false;

            world = _world;
            level = _level;

            LoadMap("Content\\Levels\\" + world + "_" + level + ".lvl");
        }
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent(ContentManager _content)
        {
            base.LoadContent(_content);

            Camera.Score = 0;
            Camera.ScoreCombo = 1;

            //setup physics world
            ConvertUnits.SetDisplayUnitToSimUnitRatio((float)physicsScale);

            spriteBatch = ScreenManager.SpriteBatch;
            pp = ScreenManager.GraphicsDevice.PresentationParameters; //aa
            renderTarget = new RenderTarget2D(ScreenManager.GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, false, pp.BackBufferFormat, pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.DiscardContents); //aa
            renderTarget2 = new RenderTarget2D(ScreenManager.GraphicsDevice, pp.BackBufferWidth/2, pp.BackBufferHeight/2, false, pp.BackBufferFormat, pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.DiscardContents); //aa

            parallaxEngine = new ParallaxManager();
            contactListener = new ContactListener(physicsWorld);
            contactSolver = new ContactSolver(physicsWorld, contactListener);
            contactListener.PowerUpActivated += new ContactListener.EffectEventHandler(contactListener_PowerUpActivated);

            //gameplay instances a new content manager for UI
            if (content == null)
                content = new ContentManager(ScreenManager.Game.Services, "Content");

            //level data manager instances its own content managers for level textures and effects
            LevelDataManager.Initialize(ScreenManager.Game, parallaxEngine, world, level);
            SoundManager.InitializeSoundEvents(contactListener);
            SoundManager.LoadMusic(LevelDataManager.levelContent, world);

            //xboxButtonFont = content.Load <SpriteFont>("GameUI\\xboxControllerSpriteFont");
            menuBackground = content.Load<Texture2D>("GameUI\\MenuBack");
            menuCorner = content.Load<Texture2D>("GameUI\\MenuCorner");
            menuTopSide = content.Load<Texture2D>("GameUI\\MenuSide");
            pellet = content.Load<Texture2D>("GameUI\\pellet");
            powerFrame = content.Load<Texture2D>("GameUI\\PowerFrame");
            powerBar = content.Load<Texture2D>("GameUI\\PowerBar");
            powerMarkerTarget = content.Load<Texture2D>("GameUI\\Power01");
            fruitBar = content.Load<Texture2D>("GameUI\\FruitBar");
            shotWindow = content.Load<Texture2D>("GameUI\\ShotWindow");
            smLock = content.Load<Texture2D>("GameUI\\Small_Lock");
            LevelDataManager.UItextures.TryGetValue("MedalBronze", out medalBronze);
            LevelDataManager.UItextures.TryGetValue("MedalSilver", out medalSilver);
            LevelDataManager.UItextures.TryGetValue("MedalGold", out medalGold);
            LevelDataManager.UItextures.TryGetValue("NoMedal", out noMedal);
            LevelDataManager.UItextures.TryGetValue("Cursor", out cursor);
            LevelDataManager.UItextures.TryGetValue("Pixel", out pixel);
            LevelDataManager.UItextures.TryGetValue("AppleJack", out appleJack);
            cursorOrigin = new Vector2(cursor.Width / 2, cursor.Height / 2);

            star = new Sprite(51, 0, Vector2.Zero, false);
            star.TintColor = new Color (0,0,0,0);
            star.Location = new Vector2(shotWindowLocation.X + (shotWindow.Width * 0.5f) - (star.SpriteRectWidth * 0.5f),
                                         shotWindowLocation.Y + (shotWindow.Height * 0.5f) - (star.SpriteRectHeight * 0.5f));

            terrainManager = new TerrainManager(physicsWorld);
            blockManager = new BlockManager(physicsWorld, contactListener);
            enemyManager = new EnemyManager(physicsWorld, contactListener);
            shotManager = new ShotManager(physicsWorld, contactListener);
            hazardManager = new HazardManager(physicsWorld, contactListener);
            explosiveManager = new ExplosiveManager(physicsWorld, contactListener);
            introManager = new IntroManager(ScreenManager.buxtonFont,ScreenManager.smallFont, world,level);

            #region  ACTIVE BARREL
            for (int i = 0; i < parallaxEngine.worldLayers.Count; i++)
            {
                for (int j = 0; j < parallaxEngine.worldLayers[i].SpriteCount; j++)
                {

                    if (parallaxEngine.worldLayers[i].layerSprites[j].SpriteType == Sprite.Type.PowerUp)
                    {
                        //find the barrel with variable set to -1
                        if (parallaxEngine.worldLayers[i].layerSprites[j].HitPoints == -1 )
                        {
                            shotManager.ShotStartBarrel = parallaxEngine.worldLayers[i].layerSprites[j];
                            shotManager.ActivePowerUpBarrel = shotManager.ShotStartBarrel;
                            interactLayer = i;
                        }

                    }
                }
            }
            #endregion

            //different objects are updated through their manager classes therefore the play area layer is set to not awake so that update is skipped for the layer
            for ( int i = 0 ; i < parallaxEngine.worldLayers.Count; i++)
            {
                parallaxEngine.worldLayers[i].IsAwake = false;
            }

            //create physical bodies for all objects, for parallax 1.o layers
            for (int j = 0; j < parallaxEngine.worldLayers.Count; j++)
            {
                if (parallaxEngine.worldLayers[j].LayerParallax == Vector2.One)
                {
                    for (int i = 0; i < parallaxEngine.worldLayers[j].SpriteCount; i++)
                    {
                        CreateBody(physicsWorld, parallaxEngine.worldLayers[j].layerSprites[i]);
                    }
                }
            }

            //UI setup
            levelName = "WORLD " + LevelDataManager.world.ToString() + "-" + LevelDataManager.level.ToString() + "  :  " + LevelDataManager.levelData[LevelDataManager.world, LevelDataManager.level].name;
            levelNameSize = ScreenManager.font.MeasureString(levelName);

            //create debug view
            oDebugView = new DebugViewXNA(physicsWorld)
            {
                DefaultShapeColor = Color.Magenta,
                SleepingShapeColor = Color.Pink,
                StaticShapeColor = Color.Yellow,
            };
            this.oDebugView.LoadContent(ScreenManager.GraphicsDevice, content, ScreenManager.smallFont);
            this.oDebugView.AppendFlags(DebugViewFlags.Shape);
            this.oDebugView.AppendFlags(DebugViewFlags.PolygonPoints);
            this.oDebugView.AppendFlags(DebugViewFlags.CenterOfMass);

            powerTargetLocation = new Vector2(powerBarLocation.X - 24, powerBarLocation.Y - 36);
            powerSlope = (GameSettings.MaxFiringPower - GameSettings.MinFiringPower) / 0.8f;
            powerMod = GameSettings.MaxFiringPower - powerSlope;

            PlayArea.AddSpriteToLayer(shotManager.shot);
            firingPower = (GameSettings.MaxFiringPower + GameSettings.MinFiringPower) * 0.5f;
            firingDirection = new Vector2(1, -1);
            firingAngle = 45f;
            firingForce = firingDirection * firingPower;
            firingLocation = shotManager.ActivePowerUpBarrel.SpriteCenterInWorld;
            shotLocation = shotManager.shot.SpriteCenterInWorld;

            shotManager.shot.spriteBody = BodyFactory.CreateCircle(physicsWorld, ConvertUnits.ToSimUnits(32f), 1f, shotManager.ShotStartBarrel.spriteBody.Position, shotManager.shot);
            shotManager.shot.spriteBody.Enabled = false;
            shotManager.shot.spriteBody.BodyType = BodyType.Dynamic;

            #region INITIALIZE DECO SPRITES TO MANAGER
            decoManager = new DecoManager(parallaxEngine, true);
            for (int i = 0; i < parallaxEngine.worldLayers.Count; i++)
            {
                for (int j = 0; j < parallaxEngine.worldLayers[i].SpriteCount; j++)
                {

                    if (parallaxEngine.worldLayers[i].layerSprites[j].SpriteType == Sprite.Type.Deco)
                    {
                        decoManager.InitializeDeco(parallaxEngine.worldLayers[i].layerSprites[j]);
                    }
                    if (parallaxEngine.worldLayers[i].layerSprites[j].SpriteType == Sprite.Type.Boss)
                    {
                        enemyManager.bossLayer = parallaxEngine.worldLayers[i];
                    }
                    if (parallaxEngine.worldLayers[i].layerSprites[j].TextureID == 3) //cage
                    {
                        enemyManager.cageLayer = parallaxEngine.worldLayers[i];
                    }
                }
            }
            #endregion

            effectManager = new EffectManager(physicsWorld, contactListener, decoManager.Tint);

            #region SETUP 5-15 boss level
            if (world == 5 && level == 15)
            {
                LevelDataManager.levelData[world, level].safety = true;
            }
            #endregion

            #region SETUP APPLEJACK LEVELS
            if (world == 6 && level == 3)
            {
                appleJackPos = new Vector2(2914, 1344);
                isAppleJack = true;
            }
            if (world == 6 && level == 5)
            {
                appleJackPos = new Vector2(2880, 1344);
                isAppleJack = true;
            }
            if (world == 6 && level == 7)
            {
                appleJackPos = new Vector2(3512, 1344);
                isAppleJack = true;
            }
            #endregion

            //set starting level state
            if (introManager.IntroFinished())
            {
                Camera.ScrollTo(firingLocation, 0);
                Camera.IsScrolling = true;
                if (!LevelDataManager.levelData[world, level].safety)
                {
                    shotManager.shot.spriteBody.Enabled = true;
                    shotManager.shot.spriteBody.IsSensor = true;
                    levelState = LevelState.Aim;
                }
                else levelState = LevelState.Countdown;
            }
            else levelState = LevelState.Intro;

            if (GameSettings.isBoss) Camera.ZoomTo(0.6f);

            #region APPLY CHEATS
            if (GameSettings.CheatTNTBarrel) shotManager.ShotStartBarrel.TextureIndex = 4;
            if (GameSettings.CheatFireBarrel) shotManager.ShotStartBarrel.TextureIndex = 1;
            if (GameSettings.CheatLightningBarrel) shotManager.ShotStartBarrel.TextureIndex = 3;
            if (GameSettings.CheatGrowthBarrel) shotManager.ShotStartBarrel.TextureIndex = 7;
            if (GameSettings.CheatCannonBarrel) shotManager.ShotStartBarrel.TextureIndex = 8;
            if (GameSettings.CheatSawBarrel) shotManager.ShotStartBarrel.TextureIndex = 9;

            #endregion

            // once the load has finished, we use ResetElapsedTime to tell the game's
            // timing mechanism that we have just finished a very long frame, and that
            // it should not try to catch up.

            ScreenManager.Game.ResetElapsedTime();
        }
        //public Game1(IntPtr drawSurface, IntPtr drawSurface2, System.Windows.Forms.Form parentForm, System.Windows.Forms.PictureBox pictureBox )
        public Game1(IntPtr drawSurface, System.Windows.Forms.Form parentForm, System.Windows.Forms.PictureBox pictureBox )
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            #region Winforms setup
            this.drawSurface = drawSurface;
            //this.drawSurface2 = drawSurface2;
            this.parentForm = parentForm;
            this.pictureBox = pictureBox;

            graphics.PreparingDeviceSettings += new EventHandler<PreparingDeviceSettingsEventArgs>(graphics_PreparingDeviceSettings);

            Mouse.WindowHandle = drawSurface;

            vscroll = (System.Windows.Forms.VScrollBar)parentForm.Controls["vScrollBar1"];
            hscroll = (System.Windows.Forms.HScrollBar)parentForm.Controls["hScrollBar1"];

            gameForm = System.Windows.Forms.Control.FromHandle(this.Window.Handle);
            gameForm.VisibleChanged += new EventHandler(gameForm_VisibleChanged);
            gameForm.SizeChanged += new EventHandler(pictureBox_SizeChanged);
            #endregion

            parallaxEngine = new ParallaxManager(this);
        }
        public void LoadMap(string _loadFilePath)
        {
            //reset parallax game engine
            parallaxEngine = new ParallaxManager(this);
            Camera.Move(new Vector2(-Camera.Position.X, -Camera.Position.Y + worldHeight - Camera.ViewportHeight - Camera.Position.Y));  //set camera to bottom left
            LevelDataManager.Unload();
            spriteFont = Content.Load<SpriteFont>(@"Fonts\Moire");
            worldGridTexture = Content.Load<Texture2D>(@"defaultTextures\grid");
            boxOutlineTexture = Content.Load<Texture2D>(@"defaultTextures\outline");
            boxHighlightTexture = Content.Load<Texture2D>(@"defaultTextures\highlight");

            LoadWorld(_loadFilePath);
            LoadTextures(Content.RootDirectory + texturePack);

            FileStream fs = new FileStream(_loadFilePath, FileMode.Open);
            StreamReader read = new StreamReader(fs);
            string data = read.ReadLine();
            do
            {
                switch (data)
                {
                    case "<LAYER>":
                        LoadLayerData(read);
                        break;
                    case "<SPRITE>":
                        LoadSpriteData(read);
                        break;
                    default:
                        break;
                }

                data = read.ReadLine();
            } while (data != "<ENDFILE>");

            read.Close();
            fs.Close();

            //reset variables
            editingLayer = parallaxEngine.worldLayers.Count-1;
            placementSprite = new Sprite(0, 0, Vector2.Zero);
            isPlacementBlocked = false;
            placementBlockingSprites = new List<Sprite>();
            isMouseOverPlacedSprite = false;
            isExistingSpriteSelected = false;
            selectedSpriteIndex = 0;
            tempselectedSpriteIndex = 0;

            return;
        }
        public DecoManager(ParallaxManager _parallaxManager, bool _isSound)
        {
            IsSound = _isSound;

            DecoSprites = new List<Sprite>();
            StarSprites = new List<Sprite>();
            CloudSprites = new List<Sprite>();
            WeatherSprites = new List<Sprite>();
            parallaxEngine = _parallaxManager;
            SoundManager.ClearSounds();

            int decoworld = LevelDataManager.world;

            if (decoworld == 6) //bonus world
            {
                switch (LevelDataManager.level)
                {
                    case 1:
                    case 2:
                    case 4:
                        {
                            decoworld = 1; //play grass
                            break;
                        }
                    case 5:
                    case 13:
                        {
                            decoworld = 2; //forest
                            break;
                        }
                    case 6:
                    case 7:
                    case 8:
                        {
                            decoworld = 3; //desert
                            break;
                        }
                    case 3:
                    case 14:
                        {
                            decoworld = 4; //snow
                            break;
                        }
                    case 9:
                    case 10:
                    case 11:
                    case 12:
                    case 15:
                        {
                            decoworld = 5; //factory
                            break;
                        }
                    default:
                        break;
                }
            }

            if (decoworld != 5)
            {
                #region ROLL RANDOM TIME DAY, SUNSET, NIGHT
                int timeRoll = LevelDataManager.rand.Next(1, 11);
                if (timeRoll < 5) //day 40%
                {
                    for (int i = 0; i < parallaxEngine.worldLayers[0].layerSprites.Count; i++)
                    {
                        parallaxEngine.worldLayers[0].layerSprites[i].TextureID = 34;
                    }
                    IsSunset = false;
                    IsNight = false;
                }
                if (timeRoll == 5 || timeRoll == 6) //sunset 20%
                {
                    for (int i = 0; i < parallaxEngine.worldLayers[0].layerSprites.Count; i++)
                    {
                        parallaxEngine.worldLayers[0].layerSprites[i].TextureID = 35;
                    }
                    IsSunset = true;
                    IsNight = false;
                }
                if (timeRoll > 6) //night 40%
                {
                    for (int i = 0; i < parallaxEngine.worldLayers[0].layerSprites.Count; i++)
                    {
                        parallaxEngine.worldLayers[0].layerSprites[i].TextureID = 36;
                    }
                    IsNight = true;
                    IsSunset = false;
                    if (IsSound) SoundManager.Play(SoundManager.Sound.EffectCricketsLoop, true, false);
                }
                #endregion
            }

            if (LevelDataManager.world == 5 && LevelDataManager.level == 5)
            {
                for (int i = 0; i < parallaxEngine.worldLayers[0].layerSprites.Count; i++)
                {
                    parallaxEngine.worldLayers[0].layerSprites[i].TextureID = 36;
                }
                IsNight = true;
            }

            #region REMOVE PLACED MOON OR ADD MOON
            if (!IsNight && parallaxEngine.worldLayers[1].layerSprites[0].TextureID == 33) parallaxEngine.worldLayers.RemoveAt(1);
            if (IsNight && parallaxEngine.worldLayers[1].layerSprites[0].TextureID != 33)
            {
                int maxMoonHeight = (int)Math.Sqrt(Camera.ViewportHeight) * 70;
                Layer moonLayer = new Layer("moon", Vector2.Zero, false, true, false, 0f, Vector2.Zero, false, 0f, Vector2.Zero);
                Vector2 moonLocation = new Vector2( LevelDataManager.rand.Next(-400,Camera.ViewportWidth+150), (float)Math.Pow((float)LevelDataManager.rand.Next(0, maxMoonHeight) / 100f, (2.0)));
                Sprite moon = new Sprite(33, 0, moonLocation, false);
                moonLayer.AddSpriteToLayer(moon);
                parallaxEngine.worldLayers.Insert(1, moonLayer);
            }
            #endregion

            #region CREATE STARS
            if (IsNight)
            {
                starPerCycle = numberOfStars / 10;
                int maxStarHeight = (int)Math.Sqrt(Camera.ViewportHeight) * 70;
                Layer starLayer = new Layer("stars", Vector2.Zero, false, true, false, 0f, Vector2.Zero, false, 0f, Vector2.Zero);
                for (int i = 0; i < numberOfStars; i++)
                {
                    int starID = 21 + LevelDataManager.rand.Next(0, 2);
                    Vector2 starLocation = new Vector2(LevelDataManager.rand.Next(0, Camera.ViewportWidth), (float)Math.Pow((float)LevelDataManager.rand.Next(0, maxStarHeight) / 100f, (2.0)));
                    Sprite star = new Sprite(starID, 0, starLocation, true);
                    star.IsAwake = false;
                    star.Scale = (float)LevelDataManager.rand.Next(50, 101) / 100f;
                    star.TotalRotation = MathHelper.ToRadians(LevelDataManager.rand.Next(0, 361));
                    star.TintColor *= (float)LevelDataManager.rand.Next(0, 101) / 100f;
                    StarSprites.Add(star);
                    starLayer.AddSpriteToLayer(star);
                }
                parallaxEngine.worldLayers.Insert(1, starLayer);
            }

            #endregion

            if (parallaxEngine.worldLayers[0].layerSprites[0].TextureID == 36 || parallaxEngine.worldLayers[0].layerSprites[0].TextureID == 35 || parallaxEngine.worldLayers[0].layerSprites[0].TextureID == 34)
            {
                #region CREATE CLOUD LAYER
                cloudsPerCycle = numberOfClouds / 10;
                int maxCloudHeight = 400;
                Layer cloudLayer = new Layer("clouds", Vector2.Zero, false, true, false, 0f, Vector2.Zero, false, 0f, Vector2.Zero);
                for (int i = 0; i < numberOfClouds; i++)
                {
                    Vector2 cloudLocation = new Vector2(LevelDataManager.rand.Next(-200, Camera.ViewportWidth + 200), LevelDataManager.rand.Next(-100, maxCloudHeight));
                    Sprite cloud = new Sprite(23, LevelDataManager.rand.Next(0, 3), cloudLocation, true);
                    cloud.IsAwake = false;
                    if (IsSunset) cloud.TextureIndex += 3;
                    if (IsNight) cloud.TextureIndex += 6;
                    cloud.Scale = (float)LevelDataManager.rand.Next(100, 401) / 100f;
                    if (LevelDataManager.rand.Next(0, 2) == 0) cloud.IsFlippedHorizontally = true;
                    if (IsSunset) cloud.TintColor = duskTint;
                    if (IsNight) cloud.TintColor = nightTint;
                    cloud.TintColor *= (float)LevelDataManager.rand.Next(0, 51) / 100f;
                    cloud.Velocity = LevelDataManager.rand.Next(20, 60);
                    if (LevelDataManager.rand.Next(0, 2) == 0) cloud.Velocity *= -1;
                    CloudSprites.Add(cloud);
                    cloudLayer.AddSpriteToLayer(cloud);
                }
                if (IsNight) parallaxEngine.worldLayers.Insert(3, cloudLayer);
                if (IsSunset) parallaxEngine.worldLayers.Insert(1, cloudLayer);
                if (!IsSunset && !IsNight) parallaxEngine.worldLayers.Insert(1, cloudLayer);
                #endregion
            }

            #region CREATE WEATHER
            if (decoworld == 0) weather = Weather.Pollen;
            if (decoworld == 1) weather = Weather.Pollen;
            if (decoworld == 2) weather = Weather.Leaf;
            if (numberOfClouds > 70 && LevelDataManager.rand.Next(0, 2) == 0) weather = Weather.Rain; //50% chance of rain if cloud cover in top 20% (10% chance total)
            if (decoworld == 4) weather = Weather.Snow;
            if (decoworld == 3) weather = Weather.None;
            if (decoworld == 5) weather = Weather.None;

            int partID = 0;
            int tiles = 1;
            weatherLayer = new Layer("weather",weatherParallax,false,true,false,0f,Vector2.Zero,false,0f,Vector2.Zero);
            if (weather == Weather.Rain)
            {
                partID = 26;
                numberOfWeatherParticles = Math.Max(0, numberOfClouds - 60) * LevelDataManager.rand.Next(6,13);
                if (IsSound) SoundManager.Play(SoundManager.Sound.EffectRainLoop, true, false);
            }
            if (weather == Weather.Snow)
            {
                numberOfWeatherParticles = Math.Max(0, numberOfClouds - 30) * LevelDataManager.rand.Next(2,5);
                partID = 27;
                tiles = 5;
            }
            if (weather == Weather.Pollen)
            {
                numberOfWeatherParticles = LevelDataManager.rand.Next(10, 21);
                partID = 25;
                tiles = 3;
            }
            if (weather == Weather.Leaf)
            {
                numberOfWeatherParticles = LevelDataManager.rand.Next(8, 16);
                partID = 24;
                tiles = 9;
            }
            //weatherPartPerCycle = numberOfWeatherParticles / 10;
            weatherPartPerCycle = numberOfWeatherParticles;
            for (int i = 0; i < numberOfWeatherParticles; i++)
            {
                Vector2 weatherParticleLocation = Camera.ScreenToWorld(new Vector2(LevelDataManager.rand.Next(0, Camera.Viewport.Width),
                                                              LevelDataManager.rand.Next(0, Camera.Viewport.Height)),weatherLayer.LayerParallax);
                Sprite weatherP = new Sprite(partID, LevelDataManager.rand.Next(0, tiles), Vector2.Zero, true);
                weatherP.IsAwake = false;
                if (weather == Weather.Rain) NewRain(weatherP, weatherParticleLocation);
                if (weather == Weather.Snow) NewSnow(weatherP,weatherParticleLocation);
                if (weather == Weather.Pollen) NewPollen(weatherP,weatherParticleLocation);
                if (weather == Weather.Leaf) NewLeaf(weatherP,weatherParticleLocation);
                WeatherSprites.Add(weatherP);
                weatherLayer.AddSpriteToLayer(weatherP);
            }

            #endregion

            #region TINT
            for (int i = 0; i < parallaxEngine.worldLayers.Count; i++)
            {
                for (int j = 0; j < parallaxEngine.worldLayers[i].SpriteCount; j++)
                {
                    if (parallaxEngine.worldLayers[i].layerSprites[j].TextureID < 20 ||
                        (parallaxEngine.worldLayers[i].layerSprites[j].IsEffect && parallaxEngine.worldLayers[i].layerSprites[j].TextureID >= 24))
                    {
                        TintSprite(parallaxEngine.worldLayers[i].layerSprites[j]);
                    }

                    //tint for rain
                    if (weather == Weather.Rain)
                    {
                        if (parallaxEngine.worldLayers[i].layerSprites[j].TextureID < 20 || parallaxEngine.worldLayers[i].layerSprites[j].SpriteType == Sprite.Type.Deco ||
                            parallaxEngine.worldLayers[i].layerSprites[j].TextureID == 34 || parallaxEngine.worldLayers[i].layerSprites[j].TextureID == 35 || parallaxEngine.worldLayers[i].layerSprites[j].TextureID == 36 ||
                            parallaxEngine.worldLayers[i].layerSprites[j].IsEffect)
                        {
                            parallaxEngine.worldLayers[i].layerSprites[j].TintColor = Color.Lerp(parallaxEngine.worldLayers[i].layerSprites[j].TintColor, Color.Gray,0.5f);
                        }
                        Tint = Color.Lerp(Tint, Color.Gray, 0.5f);
                    }
                }
            }
            #endregion
        }