/// <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]);
                    }
                }
            }
        }
        /// <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();
        }