using GiraffeRoller.scenes;
using GiraffeRoller.scenes.Levels;
using GiraffeRoller.Utility;
using Otter;

namespace GiraffeRoller.entities
{
    class Player : Entity
    {
        #region Private Variables
        private Spritemap<string> _spriteMap;
        private BasicMovement movement = new BasicMovement(400, 400, 400);//init all the things.
        private BasicMovement chargedMovement = new BasicMovement(400, 400, 100);//init all the things.
        private float _forcedChargedSpeed = 15f;
        private Axis _axis = new Axis();
        private float xoffset = 10;
        private bool IsL;
        private bool IsR;
        private bool IsU;
        private bool IsD;
        private bool _hMove = true;
        private bool _vMove = true;
        private bool isInLevelOne;
        private bool isInBase;
        private int chargedSpeedMax = 50;
        private int chargedSpeedMin = 9;
        private int _checkSpeed = 0;

        #endregion
        public static int IsJoystickAxisActive = 0;//use a Joystick axis instead of keys
        public static bool RefreshAxisButtons = false;
        public static bool Charging = false;

        public Player(float x, float y)
        {
            X = x; Y = y;
            SetHitbox(50, 50, (int)Global.Type.PLAYER);
            Collider.X = 25;//was 15
            Collider.Y = 25;//was 8 was 25            
            #region SetCustomInputs
            movement.Axis = _axis;
            string tempUp = Global.PlayerSession.Data.GetString("P1Up");
            string tempRight = Global.PlayerSession.Data.GetString("P1Right");
            string tempDown = Global.PlayerSession.Data.GetString("P1Down");
            string tempLeft = Global.PlayerSession.Data.GetString("P1Left");
            if (tempRight.Contains("Joy"))
                movement.Axis = _axis.AddButton(Controllers.Controllers.TranslateInputKeysForInts(tempRight), Direction.Right, int.Parse(Global.PlayerSession.Data.GetString("P1JoystickNumber")));
            else if (tempRight.Contains("Key"))
                movement.Axis = _axis.AddKey((Key)Controllers.Controllers.TranslateInputKeysForInts(tempRight), Direction.Right);
            else if (tempRight.Contains("Mouse"))
                movement.Axis = _axis.AddMouseButton((MouseButton)Controllers.Controllers.TranslateInputKeysForInts(tempRight), Direction.Right);
            if (tempLeft.Contains("Joy"))
                movement.Axis = _axis.AddButton(Controllers.Controllers.TranslateInputKeysForInts(tempLeft), Direction.Left, int.Parse(Global.PlayerSession.Data.GetString("P1JoystickNumber")));
            else if (tempLeft.Contains("Key"))
                movement.Axis = _axis.AddKey((Key)Controllers.Controllers.TranslateInputKeysForInts(tempLeft), Direction.Left);
            else if (tempLeft.Contains("Mouse"))
                movement.Axis = _axis.AddMouseButton((MouseButton)Controllers.Controllers.TranslateInputKeysForInts(tempLeft), Direction.Left);
            if (tempDown.Contains("Joy"))
                movement.Axis = _axis.AddButton(Controllers.Controllers.TranslateInputKeysForInts(tempDown), Direction.Down, int.Parse(Global.PlayerSession.Data.GetString("P1JoystickNumber")));
            else if (tempDown.Contains("Key"))
                movement.Axis = _axis.AddKey((Key)Controllers.Controllers.TranslateInputKeysForInts(tempDown), Direction.Down);
            else if (tempDown.Contains("Mouse"))
                movement.Axis = _axis.AddMouseButton((MouseButton)Controllers.Controllers.TranslateInputKeysForInts(tempDown), Direction.Down);
            if (tempUp.Contains("Joy"))
                movement.Axis = _axis.AddButton(Controllers.Controllers.TranslateInputKeysForInts(tempUp), Direction.Up, int.Parse(Global.PlayerSession.Data.GetString("P1JoystickNumber")));
            else if (tempUp.Contains("Key"))
                movement.Axis = _axis.AddKey((Key)Controllers.Controllers.TranslateInputKeysForInts(tempUp), Direction.Up);
            else if (tempUp.Contains("Mouse"))
                movement.Axis = _axis.AddMouseButton((MouseButton)Controllers.Controllers.TranslateInputKeysForInts(tempUp), Direction.Up);
            #endregion
            movement.SpeedScale = 100;//was 100
            movement.AddCollision((int)Global.Type.SOLID);//walls
            movement.Collider = Collider;
            //create basic bubble movement settings
            chargedMovement.SpeedScale = 100;//was 100
            chargedMovement.AddCollision((int)Global.Type.SOLID);//walls
            Axis chargedAxis = Axis.CreateArrowKeys();
            chargedMovement.Axis = chargedAxis;
            chargedMovement.Axis.AddKeys(Key.P, Key.O, Key.I, Key.U);//you could use this to add your own keys for moving the character! :-)
            chargedMovement.Collider = Collider;
            chargedMovement.Axis.Locked = true;
            AddComponents(_axis, movement, chargedMovement);
            Layer = 1;

            _spriteMap = new Spritemap<string>(Assets.PLAYER, 100, 100);
            AddNewSprites();
            if (Global.StuckInLoop)
                _spriteMap.Play("rollRight");
            else
                _spriteMap.Play("walkRight");
            Graphic = _spriteMap;
        }

        public override void UpdateFirst()//this is so that when the player moves the camera, the UI will update after it moves. (but the player will still appear below the elements. (it's an update thing)
        {
            base.UpdateFirst();
            #region Camera follows player
            if (X > Scene.HalfWidth - xoffset && X < Global.MW - Scene.HalfWidth - xoffset)//this is now universal. haha!
                Scene.CameraX = X - Scene.HalfWidth + xoffset;//this does follow the player!
            else if (X <= Scene.HalfWidth - xoffset)
                Scene.CameraX = 0;
            else if (X >= Global.MW - (Scene.HalfWidth * 2))
                Scene.CameraX = Global.MW - (Scene.HalfWidth * 2);
            if (Y > Scene.HalfHeight && Y < Global.MH - Scene.HalfHeight)
                Scene.CameraY = Y - Scene.HalfHeight;//this does follow the player!
            else if (Y <= Scene.HalfHeight)
                Scene.CameraY = 0;
            else if (Y >= Global.MH - Scene.HalfHeight * 2)
                Scene.CameraY = Global.MH - Scene.HalfHeight * 2;
            #endregion
        }

        public override void Update()
        {
            base.Update();
            //testing
            var cn = Global.PlayerSession.Controller;
            Global.PlayerX = X;
            Global.PlayerY = Y;
            Global.PlayerCurrentAnim = _spriteMap.CurrentAnim;
            #region Testing (r)
            if (cn.Button("P1Testing").Pressed)// this is for testing atm.
            {
                //Global.StuckInLoop = false;
                //System.Console.WriteLine("MouseX: {0} MouseY: {1}", Scene.MouseX, Scene.MouseY);
                //Scene.Add(new TestPowerShot(Scene.MouseX + 30, Scene.MouseY));
            }
            #endregion
            #region Testing (q)
            if (cn.Button("P1Testing2").Down)// this is for testing atm.
            {
                //Global.StuckInLoop = true;
            }
            #endregion
            //Console.WriteLine("mopvalue: {0}", Global.UsingMop);
            //System.Console.WriteLine("currentAnimValue: {0}", _spriteMap.CurrentAnim);
            if (!Global.StuckInLoop)
            {
                movement.SpeedScale = 150;
            }
            if (Global.StuckInLoop && cn.Button("P1Fire").Pressed)//charge
            {
                if (!Charging)
                {
                    movement.Speed.X = 0;
                    movement.Speed.Y = 0;
                    movement.Freeze = true;
                    chargedMovement.SpeedScale = chargedSpeedMax;
                    chargedMovement.Freeze = false;
                    chargedMovement.Speed.X = 0;
                    chargedMovement.Speed.Y = 0;
                    Charging = true;
                    SoundManager.PlayRequestedSound("_charge", 4f);
                }
                else
                    StopChargingMovement();
            }
            else if (Global.StuckInLoop && cn.Button("P1Fire").Down && Charging)
            {
                if (chargedMovement.SpeedScale >= chargedSpeedMin)
                {
                    chargedMovement.SpeedScale--;
                    _checkSpeed = chargedMovement.SpeedScale;
                }
                //System.Console.WriteLine("checkSPeed: {0} {1} {2}", _checkSpeed, _spriteMap.CurrentAnim, X);
                #region charge your animations!
                if (_checkSpeed >= 49 && IsR)
                    ChangeAnimTo("chargeR1");
                else if (_checkSpeed >= 40 && _checkSpeed < 49 && IsR)
                    ChangeAnimTo("chargeR2");
                else if (_checkSpeed >= 30 && _checkSpeed < 40 && IsR)
                    ChangeAnimTo("chargeR3");
                else if (_checkSpeed >= 20 && _checkSpeed < 30 && IsR)
                    ChangeAnimTo("chargeR4");
                else if (_checkSpeed >= 10 && _checkSpeed < 20 && IsR)
                    ChangeAnimTo("chargeR5");
                else if (_checkSpeed < 10 && IsR)
                    ChangeAnimTo("chargeR6");
                if (_checkSpeed >= 49 && IsL)
                    ChangeAnimTo("chargeL1");
                else if (_checkSpeed >= 40 && _checkSpeed < 49 && IsL)
                    ChangeAnimTo("chargeL2");
                else if (_checkSpeed >= 30 && _checkSpeed < 40 && IsL)
                    ChangeAnimTo("chargeL3");
                else if (_checkSpeed >= 20 && _checkSpeed < 30 && IsL)
                    ChangeAnimTo("chargeL4");
                else if (_checkSpeed >= 10 && _checkSpeed < 20 && IsL)
                    ChangeAnimTo("chargeL5");
                else if (_checkSpeed < 10 && IsL)
                    ChangeAnimTo("chargeL6");
                if (_checkSpeed >= 49 && IsU)
                    ChangeAnimTo("chargeU1");
                else if (_checkSpeed >= 40 && _checkSpeed < 49 && IsU)
                    ChangeAnimTo("chargeU2");
                else if (_checkSpeed >= 30 && _checkSpeed < 40 && IsU)
                    ChangeAnimTo("chargeU3");
                else if (_checkSpeed >= 20 && _checkSpeed < 30 && IsU)
                    ChangeAnimTo("chargeU4");
                else if (_checkSpeed >= 10 && _checkSpeed < 20 && IsU)
                    ChangeAnimTo("chargeU5");
                else if (_checkSpeed < 10 && IsU)
                    ChangeAnimTo("chargeU6");
                if (_checkSpeed >= 49 && IsD)
                    ChangeAnimTo("chargeD1");
                else if (_checkSpeed >= 40 && _checkSpeed < 49 && IsD)
                    ChangeAnimTo("chargeD2");
                else if (_checkSpeed >= 30 && _checkSpeed < 40 && IsD)
                    ChangeAnimTo("chargeD3");
                else if (_checkSpeed >= 20 && _checkSpeed < 30 && IsD)
                    ChangeAnimTo("chargeD4");
                else if (_checkSpeed >= 10 && _checkSpeed < 20 && IsD)
                    ChangeAnimTo("chargeD5");
                else if (_checkSpeed < 10 && IsD)
                    ChangeAnimTo("chargeD6");
                #endregion
            }
            else if (Global.StuckInLoop && cn.Button("P1Fire").Released && Charging)
            {
                if (IsL || IsR)
                    ChangeAnimTo("chargeHorizontal");
                else if (IsU || IsD)
                    ChangeAnimTo("chargeVertical");
                if (IsL)
                    chargedMovement.Axis.ForceState(-_forcedChargedSpeed, 0);
                else if (IsR)
                    chargedMovement.Axis.ForceState(_forcedChargedSpeed, 0);
                else if (IsU)
                    chargedMovement.Axis.ForceState(0, -_forcedChargedSpeed);
                else if (IsD)
                    chargedMovement.Axis.ForceState(0, _forcedChargedSpeed);
                IsL = false; IsR = false; IsU = false; IsD = false;
                SoundManager.PlayRequestedSound("_releaseCharge");
            }
            else if (Global.StuckInLoop)
                PressKeysForAnimation(cn, "rollLeft", "rollRight", "rollUp", "rollDown", true);
            else
                PressKeysForAnimation(cn, "walkLeft", "walkRight", "walkUp", "walkDown");

            #region Hmovement or Vmovement
            if (cn.Button("P1Left").Down)//LEFT
                _hMove = true;
            else if (cn.Button("P1Right").Down)//RIGHT
                _hMove = true;
            else
                _hMove = false;
            if (cn.Button("P1Up").Down)//UP
                _vMove = true;
            else if (cn.Button("P1Down").Down)//DOWN
                _vMove = true;
            else
                _vMove = false;
            #endregion
            StopWalkingAnimations();

            //Console.WriteLine("speedX: {0}", (int)Math.Abs(movement.SumSpeedX));
            #region HandlingMapEdges
            //right and left will probably never happen. It's only up and down.
            var offset = 24;
            if (X < -offset)
            {
                if (Global.StuckInLoop)
                {
                    var scenes = Global.GAME.Scenes;//get all scenes             
                    foreach (var s in scenes)//find the scene that is active
                    {//run checks on that one scene(none of the others)
                        if (s == Global.GAME.GetScene<LevelOne>())
                        {
                            isInLevelOne = true;
                        }
                        if (s == Global.GAME.GetScene<Base>())
                        {
                            isInBase = true;
                        }
                        if (isInBase)
                        {
                            //Global.GAME.RemoveScene();
                            //Global.GAME.AddScene(new LevelOne(Global.MW - 10, Y));// Add next level here or, where you want to go
                            X = Global.MW - 9;
                        }
                        if (isInLevelOne)
                        {
                            X = Global.MW - 9;
                        }
                    }
                }
                else
                    X = Global.MW - 9;
            }
            else if (X > Global.MW - 9)
            {
                if (Global.StuckInLoop)
                {
                    var scenes = Global.GAME.Scenes;//get all scenes             
                    foreach (var s in scenes)//find the scene that is active
                    {//run checks on that one scene(none of the others)
                        if (s == Global.GAME.GetScene<LevelOne>())
                        {
                            isInLevelOne = true;
                        }
                        if (s == Global.GAME.GetScene<Base>())
                        {
                            isInBase = true;
                        }
                        if (isInLevelOne)
                        {
                            Global.GAME.RemoveScene();
                            Global.GAME.AddScene(new Base(9, Y));// Add next level here or, where you want to go
                        }
                        if (isInBase)
                        {
                            X = -offset;
                        }
                    }
                }
                else
                    X = -offset;
            }
            if (Y < -offset)
                Y = Global.MH - 9;
            else if (Y > Global.MH - 9)
            {
                Y = -offset;
            }
            #endregion
            #region Timers
            #endregion
            #region refresh axis buttons check
            if (Global.IsPlayerOneAxisReset)
            {
                Global.IsPlayerOneAxisReset = false;

                string tempUp = Global.PlayerSession.Data.GetString("P1Up");
                string tempRight = Global.PlayerSession.Data.GetString("P1Right");
                string tempDown = Global.PlayerSession.Data.GetString("P1Down");
                string tempLeft = Global.PlayerSession.Data.GetString("P1Left");

                RemoveComponent(_axis);
                _axis = new Axis();
                movement.Axis = _axis;

                if (tempRight.Contains("Joy"))
                    movement.Axis = _axis.AddButton(Controllers.Controllers.TranslateInputKeysForInts(tempRight), Direction.Right, int.Parse(Global.PlayerSession.Data.GetString("P1JoystickNumber")));
                else if (tempRight.Contains("Key"))
                    movement.Axis = _axis.AddKey((Key)Controllers.Controllers.TranslateInputKeysForInts(tempRight), Direction.Right);
                else if (tempRight.Contains("Mouse"))
                    movement.Axis = _axis.AddMouseButton((MouseButton)Controllers.Controllers.TranslateInputKeysForInts(tempRight), Direction.Right);
                if (tempLeft.Contains("Joy"))
                    movement.Axis = _axis.AddButton(Controllers.Controllers.TranslateInputKeysForInts(tempLeft), Direction.Left, int.Parse(Global.PlayerSession.Data.GetString("P1JoystickNumber")));
                else if (tempLeft.Contains("Key"))
                    movement.Axis = _axis.AddKey((Key)Controllers.Controllers.TranslateInputKeysForInts(tempLeft), Direction.Left);
                else if (tempLeft.Contains("Mouse"))
                    movement.Axis = _axis.AddMouseButton((MouseButton)Controllers.Controllers.TranslateInputKeysForInts(tempLeft), Direction.Left);
                if (tempDown.Contains("Joy"))
                    movement.Axis = _axis.AddButton(Controllers.Controllers.TranslateInputKeysForInts(tempDown), Direction.Down, int.Parse(Global.PlayerSession.Data.GetString("P1JoystickNumber")));
                else if (tempDown.Contains("Key"))
                    movement.Axis = _axis.AddKey((Key)Controllers.Controllers.TranslateInputKeysForInts(tempDown), Direction.Down);
                else if (tempDown.Contains("Mouse"))
                    movement.Axis = _axis.AddMouseButton((MouseButton)Controllers.Controllers.TranslateInputKeysForInts(tempDown), Direction.Down);
                if (tempUp.Contains("Joy"))
                    movement.Axis = _axis.AddButton(Controllers.Controllers.TranslateInputKeysForInts(tempUp), Direction.Up, int.Parse(Global.PlayerSession.Data.GetString("P1JoystickNumber")));
                else if (tempUp.Contains("Key"))
                    movement.Axis = _axis.AddKey((Key)Controllers.Controllers.TranslateInputKeysForInts(tempUp), Direction.Up);
                else if (tempUp.Contains("Mouse"))
                    movement.Axis = _axis.AddMouseButton((MouseButton)Controllers.Controllers.TranslateInputKeysForInts(tempUp), Direction.Up);
                AddComponent(_axis);
            }
            #endregion
            //Console.WriteLine("currentAnim: {0}", _spriteMap.CurrentAnim);
            #region collisions
            var anything = Collider.Collide(X, Y, (int)Global.Type.BOSS);
            if (anything != null)
            {
                Global.StuckInLoop = true;
                ChangeAnimTo("rollLeft");
                //BOss s = (Boss)anything.Entity;
                //s.CollidedWithPlayer = true;
                //SoundManager.PlayRequestedSound(RandomPickupSound());
                //Global.Score++;
                //Global.PlayerHealth++;
                //Global.SwirlingObjects++;
            }
            #endregion
            if (Global.StopPlayerCharge)
            {
                Global.StopPlayerCharge = false;
                StopChargingMovement();
            }
            //System.Console.WriteLine("PlayerHealth {0}", Global.PlayerHealth);
            if (Global.PlayerHealth <= 0)
            {
                Global.GAME.RemoveScene();
                Global.GAME.AddScene(new LoseScreen());// Add next level here or, where you want to go
            }
        }//end of update

        public void StopChargingMovement()
        {
            movement.Speed.X = 0;
            movement.Speed.Y = 0;
            movement.Freeze = false;
            chargedMovement.SpeedScale = chargedSpeedMax;
            chargedMovement.Freeze = true;
            chargedMovement.Speed.X = 0;
            chargedMovement.Speed.Y = 0;
            chargedMovement.Axis.Reset();
            Charging = false;
            SoundManager.PlayRequestedSound(RandomBrake(), .7f);
        }

        public void PressKeysForAnimation(Controller cn, string l, string r, string u, string d, bool isStuck = false)
        {
            #region pressed Keys for animation
            if (cn.Button("P1Left").Pressed)//LEFT
            {
                if (Global.StuckInLoop)
                    SoundManager.PlayRequestedSound(RandomRoll(), .3f);//testing this, concerned about frequency and volume
                Shared.ChangeAnimTo(l, _spriteMap);
                if (isStuck)
                    _spriteMap.FlippedX = true;
                else
                    _spriteMap.FlippedX = false;
                IsL = true; IsR = false; IsU = false; IsD = false;
            }
            else if (cn.Button("P1Right").Pressed)//RIGHT
            {
                if (Global.StuckInLoop)
                    SoundManager.PlayRequestedSound(RandomRoll(), .3f);//testing this, concerned about frequency and volume
                Shared.ChangeAnimTo(r, _spriteMap);
                if (isStuck)
                    _spriteMap.FlippedX = false;
                else
                    _spriteMap.FlippedX = true;
                IsL = false; IsR = true; IsU = false; IsD = false;
            }
            else if (cn.Button("P1Up").Pressed)//UP
            {
                if (Global.StuckInLoop)
                    SoundManager.PlayRequestedSound(RandomRoll(), .3f);//testing this, concerned about frequency and volume
                Shared.ChangeAnimTo(u, _spriteMap);
                _spriteMap.FlippedX = true;
                IsL = false; IsR = false; IsU = true; IsD = false;
            }
            else if (cn.Button("P1Down").Pressed)//DOWN
            {
                if (Global.StuckInLoop)
                    SoundManager.PlayRequestedSound(RandomRoll(), .3f);//testing this, concerned about frequency and volume
                Shared.ChangeAnimTo(d, _spriteMap);
                if (isStuck)
                    _spriteMap.FlippedX = true;
                else
                    _spriteMap.FlippedX = false;
                IsL = false; IsR = false; IsU = false; IsD = true;
            }

            #endregion
            #region released keys for animation
            if (cn.Button("P1Left").Released)//if i release left, updownright
            {
                if (cn.Button("P1Up").Down)//and i'm holding up
                {
                    Shared.ChangeAnimTo(u, _spriteMap);
                    _spriteMap.FlippedX = true;
                }
                else if (cn.Button("P1Down").Down)//and i'm holding down
                {
                    Shared.ChangeAnimTo(d, _spriteMap);
                    if (isStuck)
                        _spriteMap.FlippedX = true;
                    else
                        _spriteMap.FlippedX = false;
                }
                else if (cn.Button("P1Right").Down)//and i'm holding right
                {
                    Shared.ChangeAnimTo(r, _spriteMap);
                    if (isStuck)
                        _spriteMap.FlippedX = false;
                    else
                        _spriteMap.FlippedX = true;
                }
            }
            else if (cn.Button("P1Right").Released)//if i release right, updownleft
            {
                if (cn.Button("P1Up").Down)//and i'm holding up
                {
                    Shared.ChangeAnimTo(u, _spriteMap);
                    _spriteMap.FlippedX = true;
                }
                else if (cn.Button("P1Down").Down)//and i'm holding down
                {
                    Shared.ChangeAnimTo(d, _spriteMap);
                    if (isStuck)
                        _spriteMap.FlippedX = true;
                    else
                        _spriteMap.FlippedX = false;
                }
                else if (cn.Button("P1Left").Down)//and i'm holding left
                {
                    Shared.ChangeAnimTo(l, _spriteMap);
                    if (isStuck)
                        _spriteMap.FlippedX = true;
                    else
                        _spriteMap.FlippedX = false;
                }
            }
            else if (cn.Button("P1Up").Released)//if i release up, rightleftdown
            {
                if (cn.Button("P1Right").Down)//and i'm holding right
                {
                    Shared.ChangeAnimTo(r, _spriteMap);
                    if (isStuck)
                        _spriteMap.FlippedX = false;
                    else
                        _spriteMap.FlippedX = true;
                }
                else if (cn.Button("P1Left").Down)//and i'm holding left
                {
                    Shared.ChangeAnimTo(l, _spriteMap);
                    if (isStuck)
                        _spriteMap.FlippedX = true;
                    else
                        _spriteMap.FlippedX = false;
                }
                else if (cn.Button("P1Down").Down)//and i'm holding down
                {
                    Shared.ChangeAnimTo(d, _spriteMap);
                    if (isStuck)
                        _spriteMap.FlippedX = true;
                    else
                        _spriteMap.FlippedX = false;
                }
            }
            else if (cn.Button("P1Down").Released)//if i release down, rightleftup
            {
                if (cn.Button("P1Right").Down)//and i'm holding right
                {
                    Shared.ChangeAnimTo(r, _spriteMap);
                    if (isStuck)
                        _spriteMap.FlippedX = false;
                    else
                        _spriteMap.FlippedX = true;
                }
                else if (cn.Button("P1Left").Down)//and i'm holding left
                {
                    Shared.ChangeAnimTo(l, _spriteMap);
                    if (isStuck)
                        _spriteMap.FlippedX = true;
                    else
                        _spriteMap.FlippedX = false;
                }
                else if (cn.Button("P1Up").Down)//and i'm holding up
                {
                    Shared.ChangeAnimTo(u, _spriteMap);
                    _spriteMap.FlippedX = true;
                }
            }
            #endregion
        }

        public void StopWalkingAnimations()
        {
            if (!_hMove && !_vMove)
            {
                switch (_spriteMap.CurrentAnim)
                {
                    case ("walkLeft"):
                        _spriteMap.Play("standLeft");
                        _spriteMap.FlippedX = false;
                        break;
                    case ("walkRight"):
                        _spriteMap.Play("standRight");
                        _spriteMap.FlippedX = true;
                        break;
                    case ("walkUp"):
                        _spriteMap.Play("standUp");
                        _spriteMap.FlippedX = true;
                        break;
                    case ("walkDown"):
                        _spriteMap.Play("standDown");
                        _spriteMap.FlippedX = false;
                        break;
                    case ("rollLeft"):
                        _spriteMap.Play("standRollLeft");
                        _spriteMap.FlippedX = false;
                        break;
                    case ("rollRight"):
                        _spriteMap.Play("standRollRight");
                        _spriteMap.FlippedX = false;
                        break;
                    case ("rollUp"):
                        _spriteMap.Play("standRollUp");
                        _spriteMap.FlippedX = true;
                        break;
                    case ("rollDown"):
                        _spriteMap.Play("standRollDown");
                        _spriteMap.FlippedX = true;
                        break;
                    default:
                        break;
                }
            }
        }

        public void ChangeAnimTo(string desiredAnimation)
        {
            if (_spriteMap.CurrentAnim != desiredAnimation)
                _spriteMap.Play(desiredAnimation);
        }
        #region AddSprites
        public void AddNewSprites()
        {
            var hMs = 7f;//horizontal animation speed
            var unstuck = 3f;//horizontal animation speed
            _spriteMap.Add("standLeft", new int[] { 0 }, new float[] { unstuck, unstuck });
            _spriteMap.Add("walkLeft", new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, new float[] { unstuck, unstuck });
            _spriteMap.Add("standRight", new int[] { 0 }, new float[] { unstuck, unstuck });
            _spriteMap.Add("walkRight", new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, new float[] { unstuck, unstuck });
            _spriteMap.Add("standUp", new int[] { 0 }, new float[] { unstuck, unstuck });
            _spriteMap.Add("walkUp", new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, new float[] { unstuck, unstuck });
            _spriteMap.Add("standDown", new int[] { 0 }, new float[] { unstuck, unstuck });
            _spriteMap.Add("walkDown", new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, new float[] { unstuck, unstuck });
            _spriteMap.Add("standRollRight", new int[] { 14 }, new float[] { 1, 1 });
            _spriteMap.Add("rollRight", new int[] { 12, 13, 14, 15 }, new float[] { hMs, hMs });
            _spriteMap.Add("standRollLeft", new int[] { 16 }, new float[] { hMs, hMs });
            _spriteMap.Add("rollLeft", new int[] { 16, 17, 18, 19 }, new float[] { hMs, hMs });
            _spriteMap.Add("standRollDown", new int[] { 20 }, new float[] { hMs, hMs });
            _spriteMap.Add("rollDown", new int[] { 20, 21, 22, 23 }, new float[] { hMs, hMs });
            _spriteMap.Add("standRollUp", new int[] { 24 }, new float[] { hMs, hMs });
            _spriteMap.Add("rollUp", new int[] { 24, 25, 26, 27 }, new float[] { hMs, hMs });
            _spriteMap.Add("chargeHorizontal", new int[] { 28, 29, 28, 30 }, new float[] { 2, 2 });
            _spriteMap.Add("chargeVertical", new int[] { 31, 32, 31, 33 }, new float[] { 2, 2 });
            _spriteMap.Add("deathRight", new int[] { 10, 11, 12, 13, 10, 11, 12, 13, 25, 26 }, new float[] { 10f, 10f });
            _spriteMap.Add("deathLeft", new int[] { 21, 22, 23, 24, 21, 22, 23, 24, 25, 26 }, new float[] { 10f, 10f });
            _spriteMap.Add("break", new int[] { 21, 22, 23, 24, 21, 22, 23, 24, 25, 26 }, new float[] { 10f, 10f });
            #region Charge Animations
            //charged animation sequence
            _spriteMap.Add("chargeR1", new int[] { 12, 13, 14, 15 }, new float[] { 6, 6 });
            _spriteMap.Add("chargeR2", new int[] { 12, 13, 14, 15 }, new float[] { 5, 5 });
            _spriteMap.Add("chargeR3", new int[] { 12, 13, 14, 15 }, new float[] { 4, 4 });
            _spriteMap.Add("chargeR4", new int[] { 12, 13, 14, 15 }, new float[] { 3, 3 });
            _spriteMap.Add("chargeR5", new int[] { 12, 13, 14, 15 }, new float[] { 2, 2 });
            _spriteMap.Add("chargeR6", new int[] { 12, 13, 14, 15 }, new float[] { 1, 1 });
            _spriteMap.Add("chargeL1", new int[] { 16, 17, 18, 19 }, new float[] { 6, 6 });
            _spriteMap.Add("chargeL2", new int[] { 16, 17, 18, 19 }, new float[] { 5, 5 });
            _spriteMap.Add("chargeL3", new int[] { 16, 17, 18, 19 }, new float[] { 4, 4 });
            _spriteMap.Add("chargeL4", new int[] { 16, 17, 18, 19 }, new float[] { 3, 3 });
            _spriteMap.Add("chargeL5", new int[] { 16, 17, 18, 19 }, new float[] { 2, 2 });
            _spriteMap.Add("chargeL6", new int[] { 16, 17, 18, 19 }, new float[] { 1, 1 });
            _spriteMap.Add("chargeD1", new int[] { 20, 21, 22, 23 }, new float[] { 6, 6 });
            _spriteMap.Add("chargeD2", new int[] { 20, 21, 22, 23 }, new float[] { 5, 5 });
            _spriteMap.Add("chargeD3", new int[] { 20, 21, 22, 23 }, new float[] { 4, 4 });
            _spriteMap.Add("chargeD4", new int[] { 20, 21, 22, 23 }, new float[] { 3, 3 });
            _spriteMap.Add("chargeD5", new int[] { 20, 21, 22, 23 }, new float[] { 2, 2 });
            _spriteMap.Add("chargeD6", new int[] { 20, 21, 22, 23 }, new float[] { 1, 1 });
            _spriteMap.Add("chargeU1", new int[] { 24, 25, 26, 27 }, new float[] { 6, 6 });
            _spriteMap.Add("chargeU2", new int[] { 24, 25, 26, 27 }, new float[] { 5, 5 });
            _spriteMap.Add("chargeU3", new int[] { 24, 25, 26, 27 }, new float[] { 4, 4 });
            _spriteMap.Add("chargeU4", new int[] { 24, 25, 26, 27 }, new float[] { 3, 3 });
            _spriteMap.Add("chargeU5", new int[] { 24, 25, 26, 27 }, new float[] { 2, 2 });
            _spriteMap.Add("chargeU6", new int[] { 24, 25, 26, 27 }, new float[] { 1, 1 });
            #endregion
        }
        #endregion

        private string RandomBrake()
        {
            switch (Rand.Int(1, 4))//one more than the last case number (so counting the default would be an additional one)
            {
                case 1:
                    return "_brake";
                case 2:
                    return "_brake2";
                case 3:
                    return "_brake3";
                default:
                    return "_brake4";
            }
        }

        private string RandomRoll()
        {
            switch (Rand.Int(1, 4))//one more than the last case number (so counting the default would be an additional one)
            {
                case 1:
                    return "_roll";
                case 2:
                    return "_roll2";
                case 3:
                    return "_roll3";
                default:
                    return "_roll4";
            }
        }

        public override void Render()//mainly for testing colliders :D
        {
            base.Render();
            //Collider.Render();
            //chargingCollider.Render(Color.Blue);
        }

        public void Destroy()
        {
            RemoveSelf();
        }
    }
}
