using Otter;
using PpbbffttMiningHa.entities;
using PpbbffttMiningHa.entities.MapEntities;
using PpbbffttMiningHa.ui;
using PpbbffttMiningHa.Utility;

namespace PpbbffttMiningHa.scenes.Levels
{
    class LevelTwo : Scene
    {
        public const int _width = Global.MW;
        public const int _height = Global.MH;
        private bool _addGlobalUI = true;
        private bool one;
        private bool _addScoreMissing;

        public LevelTwo()
        {
            Add(new BackDrop2(0, 0));
            SoundManager.PlayRequestedSound("_waterDrain");
            Global.WriteWord(160, 340, "Something's still not quite right...", Color.FromBytes(70, 35, 0, 255), 1, -10, this, 300, 14);
            for (var x = -64; x < Global.MW + 64; x += 32)
            {
                for (var y = 300; y < 2000; y += 32)
                {

                    if (y > 1900)
                        Add(new BottomRock(x, y));
                    else if (y > 1800 && y <= 1900)
                    {
                        Add(new DeadDirt(x, y));
                        if (!one)
                        {
                            one = true;
                            Add(new PrairieDog(x, y + 20));
                            Add(new Door(x + 600, y + 50));
                        }
                    }
                    else if (y % 10 == 0)
                    {
                        var randomTilePlacement = Rand.Int(1, 6);
                        if (randomTilePlacement == 1)
                            Add(new BottomRock(x, y));
                        else
                            Add(new Dirt(x, y));
                    }
                    else
                        Add(new Dirt(x, y));
                }
            }
            Global.cam = new Camera(100, 2);
            #region Add Players and UI
            Global.player = new Player(16, 200);//was 200
            Add(Global.player);
            Add(new Score(16, 10));
            Add(new GemsInHand(400, 10));
            Add(new PlayerHealthDisplay(240, 10));
            Add(new Boss2Health(540, 460));
            #endregion
            /*if (Global.music == null)
                Global.music = new Music(Assets.MUSIC_STAGE_THEME);
            if (!Global.music.IsPlaying)
            {
                Global.music.Play();
                Global.music.Volume = .3f;
                Global.music.Loop = true;
            }*/
            Add(Global.cam);
            //for (var i = 0; i < 3; i++)
            //{
            //    Add(new Robot(Rand.Int(16, Global.MW - 16), Rand.Int(16, Global.MH - 32)));
            //}

            //always add this guy so we can pause the game:
            Add(new PausePerson());
        }

        public override void Begin()
        {
            base.Begin();
            Global.cam.AdjustToPlayer(Global.MW, Global.MH, Global.PlayerX, Global.PlayerY);
        }
        public override void Update()
        {
            base.Update();
            if (!IsGroupPaused(0))
            {
                if (_addGlobalUI)
                {
                    _addGlobalUI = false;
                    //Global.AddAllLevelUI(Global.GAME.Scene);//so i don't have to add the same ui every level if all levels have it.
                }
                Shared.LevelUpdate(Global.GAME.Scene);
                //all other unique level updates go here:
                /*if (Global.PlayerSession.Controller.Button("P1Start").Pressed)
                {
                    Global.GAME.RemoveScene();
                    Global.GAME.AddScene(new LoseScreen());// Add next level here or, where you want to go
                }*/
            }
            if (!_addScoreMissing)
            {
                _addScoreMissing = true;
                Global.WriteWord(450 - 1, 10 - 1, "Gems:", Color.FromBytes(3, 153, 209, 255), 1f, -101, this, 0, 10);//regular text  
                Global.WriteWord(450, 10, "Gems:", Color.FromBytes(0, 0, 0, 255), 1f, -100, this, 0, 10);//shadow (layers sort this)
                Global.WriteWord(20 - 1, 10 - 1, "Score:", Color.FromBytes(228, 255, 43, 255), 1f, -101, this, 0, 10);//regular text  
                Global.WriteWord(20, 10, "Score:", Color.FromBytes(0, 0, 0, 255), 1f, -100, this, 0, 10);//shadow (layers sort this)
                Global.WriteWord(230 - 1, 10 - 1, "Health:", Color.FromBytes(255, 0, 0, 255), 1f, -101, this, 0, 10);//regular text  
                Global.WriteWord(230, 10, "Health:", Color.FromBytes(0, 0, 0, 255), 1f, -100, this, 0, 10);//shadow (layers sort this)
                                                                                                           //boss health
                Global.WriteWord(530 - 1, 460 - 1, "BossHealth:", Color.FromBytes(37, 119, 28, 255), 1f, -101, this, 0, 10);//regular text  
                Global.WriteWord(530, 460, "BossHealth:", Color.FromBytes(0, 0, 0, 255), 1f, -100, this, 0, 10);//shadow (layers sort this)
                                                                                                                //first event:
                Global.WriteWordUI(20 - 1, 460 - 1, "Dig!", Color.FromBytes(0, 64, 255, 255), 1f, -101, this, 0, 10);//regular text  
                Global.WriteWordUI(20, 460, "Dig!", Color.FromBytes(0, 0, 0, 255), 1f, -100, this, 0, 10);//shadow (layers sort this)

            }
        }//end of UPDATE

        public override void Render()
        {
            base.Render();
            //grid.Render();
        }
    }
}

