using Otter;
using PpbbffttMiningHa.ui;

namespace PpbbffttMiningHa
{
    class Shared
    {//all public because i'm reseting them when the level starts. Private vars didn't reset on their own. Not sure how to do that on shared class.
        public static void LevelUpdate(Scene scene)
        {
            //Global.cam.FollowPlayer(Global.MW, Global.MH, Global.PlayerX, Global.PlayerY, Global.PlayerSpeed);
            #region Win Conditions
            //add win conditions here if you want the same win condition on every level... lol
            #endregion
            if (Global.IsScreenShake)
                ShakeScreen(scene);
        }//end of shared level update

        public static void DisplayText(float x, float y, string text, Color color, Scene scene)
        {
            var a = 0;
            for (var b = 0; b < text.Length; b++)
            {
                scene.Add(new Numbers(x + a, y, text[b].ToString(), color));
                a += 8;
            }
        }

        public static void ChangeAnimTo(string desiredAnimation, Spritemap<string> _spriteMap)
        {
            if (_spriteMap.CurrentAnim != desiredAnimation)
                _spriteMap.Play(desiredAnimation);
        }

        public static void ShakeScreen(Scene scene)
        {
            var tempCamX = scene.CameraX;
            var tempCamY = scene.CameraY;
            if (Global.CameraTimer > 0 && Global.Done < 4)
            {
                if (Global.Drection == 1)
                {
                    scene.CameraX += Rand.Int(0, 5);
                    scene.CameraY += Rand.Int(0, 5);
                }
                if (Global.Drection == 2)
                {
                    scene.CameraX -= Rand.Int(0, 5);
                    scene.CameraY += Rand.Int(0, 5);
                }
                if (Global.Drection == 3)
                {
                    scene.CameraX += Rand.Int(0, 5);
                    scene.CameraY -= Rand.Int(0, 5);
                }
                if (Global.Drection == 4)
                {
                    scene.CameraX -= Rand.Int(0, 5);
                    scene.CameraY -= Rand.Int(0, 5);
                }
                Global.CameraTimer--;
            }
            if (Global.CameraTimer <= 0 && Global.Done < 4)
            {
                Global.Drection = Rand.Int(1, 5);
                Global.CameraTimer = 3;
                scene.CameraX = tempCamX;
                scene.CameraY = tempCamY;
                Global.Done++;
            }
            if (Global.Done >= 4)
            {
                scene.CameraX = tempCamX;//set back to origin
                scene.CameraY = tempCamY;//set back to origin
                Global.Done = 0;//reset it for future use
                Global.CameraTimer = 3;//set for future use
                Global.IsScreenShake = false;//shut this thing off till active again
            }
        }
    }
}

