using Otter;
using Puppyups.objects;
using Puppyups.Utilities;
using System;
using System.Collections;

namespace Puppyups.entities
{
    class Player2 : Entity
    {
        private Spritemap<string> _spriteMap;
        private bool _hMove = true;
        private bool _vMove = true;
        public static bool canPlayerCollide = true;
        public static bool isSpritemapChanged = true;
        private BasicMovement movement = new BasicMovement(400, 400, 400);//was 400,400,400
        private const float player2aiSpeedMax = 2f;//testing, update this as needed
        private float player2aiSpeed = player2aiSpeedMax;//testing, update this as needed
        private bool one = true;

        //ai follow me code
        private bool isSeekingTarget = true;
        private float closestDistanceItem = 3650f;
        private Entity closestItem;
        private double angleInRadians = 1;//this is about 57 degrees. ;-)
        private bool isHittingTarget = false;
        private const int ScanTimerMax = 10;//50 is fine for slower speeds
        private int scanAgain = ScanTimerMax;
        private int hitTimerMax = Rand.Int(100, 150);
        private int hitTimer;
        private bool IsL;
        private bool IsR;
        private bool IsU;
        private bool IsD;
        private bool _isShooting;
        private float _X;
        private float _Y;
        private float _grappleDragSpeed = 9f;
        private Vector2 velocity;

        public static bool OneTimeGrappleAngle = true;
        public static bool Pulled;

        public Player2(float x, float y)
        {
            X = x; Y = y;
            SetHitbox(9, 20, (int)Global.Type.PLAYER2);
            Collider.X = 0;
            Collider.Y = -16;
            Axis axis = Axis.CreateArrowKeys();
            movement.Axis = axis;
            movement.Collider = Collider;
            movement.AddCollision((int)Global.Type.SOLID);//walls
            AddComponents(axis, movement);
            LoadCorrectSpritemap();
            _spriteMap.CenterOrigin();
            movement.Speed = Global.Player2Speed;
        }
        public override void Update()
        {
            base.Update();
            if (isSpritemapChanged)
                LoadCorrectSpritemap();
            Global.Player2X = X;
            Global.Player2Y = Y;
            var cn = Global.Player2Session.Controller;

            if (!Global.IsTwoPlayerActive)
            {//follow the player around. for the AI she needs to actually walk to your destination. (where you were. Then stand there till you move)
                //so that when you move she moves in random stints to give you a slower animation cycle. :D she'll teleport to you on map changes.

                if (_spriteMap.CurrentAnim == "death") //if you are dying, do it. don't do anything else!
                {
                    if (_spriteMap.CurrentFrameIndex == 11)//whatever frame death is.
                    {
                        //do death here. yay!
                    }
                }
                else
                {
                    if (isSeekingTarget)
                    {
                        ScanAllTargets();
                    }
                    else if (!AmCloseEnoughToAnythingToShootIt())//travel to target
                    {
                        player2aiSpeed = player2aiSpeedMax;
                        X -= player2aiSpeed * (float)Math.Cos(angleInRadians);
                        Y -= player2aiSpeed * (float)Math.Sin(angleInRadians);
                        if (X >= Global.PlayerX)
                        {
                            ChangeAnimTo("walkLeft");
                            _spriteMap.FlippedX = true;
                        }
                        else
                        {
                            ChangeAnimTo("walkRight");
                            _spriteMap.FlippedX = false;
                        }
                        one = true;
                    }
                    else if (isHittingTarget)
                    {
                        if (one || hitTimer <= 0)
                        {
                            hitTimer = hitTimerMax;
                            one = false;
                            //Scene.Add(new Bullet(X, Y, closestItem));
                            
                        }
                        if (Global.IsPlayer2GunCollected)
                        {
                            ChangeAnimTo("shootRight");
                            _spriteMap.FlippedX = false;
                        }
                        else
                        {
                            if (X >= Global.PlayerX)
                            {
                                ChangeAnimTo("standRight");
                                _spriteMap.FlippedX = false;
                            }
                            else
                            {
                                ChangeAnimTo("standLeft");
                                _spriteMap.FlippedY = false;
                            }
                            hitTimer--;
                        }

                    }
                    if (scanAgain <= 0)
                    {
                        isSeekingTarget = true;
                        closestItem = null;
                        closestDistanceItem = 1670;
                        scanAgain = ScanTimerMax;
                    }
                    if (scanAgain > 0)
                        scanAgain--;
                }
            }
            else if (Pulled)
            {
                movement.Freeze = false;
                movement.SpeedScale = 25;
                if (OneTimeGrappleAngle)
                {
                    OneTimeGrappleAngle = false;
                    GetRealDirection((int)Global.Grapple2X, (int)Global.Grapple2Y, (int)X, (int)Y);//this sets the angle in radians.
                }
                GetVelocity(angleInRadians);
                movement.Axis.ForceState(velocity);

                var gr = Collider.Collide(X, Y, Global.Type.GRAPPLE2);
                if (gr != null)
                {
                    Grapple2 gpl2 = (Grapple2)gr.Entity;
                    gpl2.Destroy();
                    Pulled = false;
                    _isShooting = false;
                    Player2Aimer.IsActive = false;
                    movement.Axis.ReleaseState();
                }
                if (cn.Button("NumZero").Pressed)//use this to cancel the pull.
                {
                    var grapples = GetEntities<Grapple2>();
                    foreach (var item in grapples)//kill all grapples.
                    {
                        item.Destroy();
                    }
                    Pulled = false;
                    _isShooting = false;
                    Player2Aimer.IsActive = false;
                    movement.Axis.ReleaseState();

                }
            }
            else if (cn.Button("NumZero").Pressed && Player2Aimer.IsActive)//use this to cancel the pull.
            {
                var grapples = GetEntities<Grapple2>();
                foreach (var item in grapples)//kill all grapples.
                {
                    item.Destroy();
                }
                Pulled = false;
                _isShooting = false;
                Player2Aimer.IsActive = false;
                movement.Axis.ReleaseState();
            }
            else
            {
                movement.SpeedScale = 100;//two player is active
                PressKeysForAnimation(cn, "walkLeft", "walkRight", "walkUp", "walkDown");

                #region Hmovement or Vmovement
                if (cn.Button("Left").Down)//LEFT
                    _hMove = true;
                else if (cn.Button("Right").Down)//RIGHT
                    _hMove = true;
                else
                    _hMove = false;
                if (cn.Button("Up").Down)//UP
                    _vMove = true;
                else if (cn.Button("Down").Down)//DOWN
                    _vMove = true;
                else
                    _vMove = false;
                #endregion

                StopWalkingAnimations();
                //collisions:
                var labgun2 = Collider.Collide(X, Y, (int)Global.Type.LABGUN2);
                if (labgun2 != null)
                {
                    Global.GAME.Coroutine.Start(GotGun());
                    LabGun2 l = (LabGun2)labgun2.Entity;
                    Global.IsPlayer2GunCollected = true;
                    l.Destroy();
                }
            }
            #region collisions

            #endregion
            if (Global.Player2Health <= 0)
            {//turn into a ghost and follow the player around... till the player can bring you back...
                //SoundManager.PlayRequestedSound("_girlDeath");
                //load the level
                //Global.GAME.RemoveScene();
                //Global.GAME.AddScene(new LoseScreen());
                //RemoveSelf();
            }
        }//end update
        public static IEnumerator GotGun()
        {
            SoundManager.PlayRequestedSound("_aaaa2");
            yield return Coroutine.Instance.WaitForFrames(170);
            SoundManager.PlayRequestedSound("_girlohok");
        }
        private void ScanAllTargets()
        {
            var anyPlayer = GetEntities<Player>();
            foreach (var item in anyPlayer)
            {
                var dist = Util.Distance(this, item);
                if (dist <= closestDistanceItem)
                {
                    closestDistanceItem = dist;
                    closestItem = item;
                }
            }
            if (closestItem != null)
            {
                isSeekingTarget = false;
                GetDirection();
            }
        }

        public void GetDirection()
        {
            var vector1 = new Point((int)closestItem.X, (int)closestItem.Y);
            var vector2 = new Point((int)X, (int)Y);
            angleInRadians = Math.Atan2(vector2.Y - vector1.Y, vector2.X - vector1.X);
            var angleInFrisbees = MathHelper.ToDegrees((float)angleInRadians);
            if (angleInFrisbees < 0)
            {
                angleInFrisbees += 360;
                angleInRadians = MathHelper.ToRadians(angleInFrisbees);
            }
        }

        public void GetRealDirection(int destX, int destY, int sourceX, int sourceY)
        {
            var vector1 = new Point(sourceX, sourceY);
            var vector2 = new Point(destX, destY);
            angleInRadians = Math.Atan2(vector2.Y - vector1.Y, vector2.X - vector1.X);
            var angleInFrisbees = MathHelper.ToDegrees((float)angleInRadians);
            if (angleInFrisbees < 0)
            {
                angleInFrisbees += 360;
                angleInRadians = MathHelper.ToRadians(angleInFrisbees);
            }
        }

        private void GetVelocity(double originalAngle)//these speeds are not variable enough. :/
        {
            var angle = (int)MathHelper.ToDegrees((float)originalAngle);
            //Console.WriteLine("angle: {0}", angle);
            _X = _grappleDragSpeed * (float)Math.Cos(originalAngle);
            _Y = _grappleDragSpeed * (float)Math.Sin(originalAngle);
            velocity = new Vector2(_X, _Y);
        }

        public double GetAngle(float angle)
        {
            return MathHelper.ToRadians(angle);
        }

        public bool AmICollidingWithMyEnemies()
        {
            var dog = Collider.Collide(X, Y, (int)Global.Type.DOG);
            if (dog != null)
                return true;
            else
                return false;
        }

        public bool AmICollidingWithWalls(float s)
        {
            var wallu = Collider.Collide(X, Y - s, (int)Global.Type.SOLID);
            var walld = Collider.Collide(X, Y + s, (int)Global.Type.SOLID);
            var walll = Collider.Collide(X - s, Y, (int)Global.Type.SOLID);
            var wallr = Collider.Collide(X + s, Y, (int)Global.Type.SOLID);
            if (wallu != null || wallr != null || walld != null || walll != null)
                return true;
            else
                return false;
        }

        public bool AmCloseEnoughToAnythingToShootIt()
        {
            //get the distance to closest item. if close shoot at it!
            var dist = Util.Distance(this, closestItem);
            if (dist <= 20)//hmm
            {
                isHittingTarget = true;
                return true;
            }
            else
            {
                isHittingTarget = false;
                return false;
            }
        }

        public void ChangeAnimTo(string desiredAnimation)
        {
            if (_spriteMap.CurrentAnim != desiredAnimation)
                _spriteMap.Play(desiredAnimation);
        }

        public void StopWalkingAnimations()
        {
            if (!_hMove && !_vMove)
            {
                switch (_spriteMap.CurrentAnim)
                {
                    case ("walkLeft"):
                        _spriteMap.Play("standLeft");
                        break;
                    case ("walkRight"):
                        _spriteMap.Play("standRight");
                        break;
                    case ("walkUp"):
                        _spriteMap.Play("standUp");
                        break;
                    case ("walkDown"):
                        _spriteMap.Play("standDown");
                        break;
                    case ("walkShootLeft"):
                        _spriteMap.Play("shootLeft");
                        break;
                    case ("walkShootRight"):
                        _spriteMap.Play("shootRight");
                        break;
                    case ("walkShootUp"):
                        _spriteMap.Play("shootUp");
                        break;
                    case ("walkShootDown"):
                        _spriteMap.Play("shootDown");
                        break;
                    default:
                        break;
                }
            }
        }

        public void LoadCorrectSpritemap()
        {
            isSpritemapChanged = false;
            if (_spriteMap != null)
                _spriteMap.Clear();
            //if no other spritemaps are needed, this will work fine.
            _spriteMap = null;
            _spriteMap = new Spritemap<string>(Assets.PLAYER2, 50, 50);
            AddNewSprites();
            _spriteMap.Update();
            _spriteMap.CenterOrigin();
            _spriteMap.Play("standDown");
            Graphic = _spriteMap;
        }

        #region AddSprites
        public void AddNewSprites()
        {
            var hMs = 6f;//horizontal animation speed
            var vMs = 6f;//vertical animation speed
            _spriteMap.Add("standRight", new int[] { 0 }, new float[] { hMs, hMs });
            _spriteMap.Add("standLeft", new int[] { 0 }, new float[] { hMs, hMs });
            _spriteMap.Add("standUp", new int[] { 0 }, new float[] { hMs, hMs });
            _spriteMap.Add("standDown", new int[] { 0 }, new float[] { hMs, hMs });
            _spriteMap.Add("walkRight", new int[] { 1, 2, 3, 4 }, new float[] { hMs, hMs });
            _spriteMap.Add("walkLeft", new int[] { 1, 2, 3, 4 }, new float[] { hMs, hMs });
            _spriteMap.Add("walkUp", new int[] { 1, 2, 3, 4 }, new float[] { vMs, vMs });
            _spriteMap.Add("walkDown", new int[] { 1, 2, 3, 4 }, new float[] { vMs, vMs });
            _spriteMap.Add("shootRight", new int[] { 5 }, new float[] { hMs, hMs });
            _spriteMap.Add("shootLeft", new int[] { 5 }, new float[] { hMs, hMs });
            _spriteMap.Add("shootUp", new int[] { 7 }, new float[] { hMs, hMs });
            _spriteMap.Add("shootDown", new int[] { 9 }, new float[] { hMs, hMs });
            _spriteMap.Add("walkShootRight", new int[] { 5, 6 }, new float[] { hMs, hMs });
            _spriteMap.Add("walkShootLeft", new int[] { 5, 6 }, new float[] { hMs, hMs });
            _spriteMap.Add("walkShootUp", new int[] { 7, 8 }, new float[] { hMs, hMs });
            _spriteMap.Add("walkShootDown", new int[] { 9, 10 }, new float[] { hMs, hMs });

            _spriteMap.Add("death", new int[] { 1, 5, 1, 7, 2, 0, 3, 5, 1, 6, 7 }, new float[] { 16, 16 });
        }
        /*public void AddPlayerWagonSprites()
        {
            var hMs = 1f;//horizontal animation speed
            var vMs = 1f;//vertical animation speed
            _spriteMap.Add("standRight", new int[] { 1 }, new float[] { hMs, hMs });
            _spriteMap.Add("standLeft", new int[] { 0 }, new float[] { hMs, hMs });
            _spriteMap.Add("standUp", new int[] { 0 }, new float[] { hMs, hMs });
            _spriteMap.Add("standDown", new int[] { 1 }, new float[] { hMs, hMs });
            _spriteMap.Add("walkRight", new int[] { 12, 11, 10, 19, 18, 17, 16, 15 }, new float[] { hMs, hMs });
            _spriteMap.Add("walkLeft", new int[] { 2, 3, 4, 5, 6, 7, 8, 9 }, new float[] { hMs, hMs });
            _spriteMap.Add("walkUp", new int[] { 2, 3, 4, 5, 6, 7, 8, 9 }, new float[] { vMs, vMs });
            _spriteMap.Add("walkDown", new int[] { 12, 11, 10, 19, 18, 17, 16, 15 }, new float[] { vMs, vMs });
            _spriteMap.Add("defendRight", new int[] { 14 }, new float[] { vMs, vMs });
            _spriteMap.Add("defendLeft", new int[] { 13 }, new float[] { vMs, vMs });

            _spriteMap.Add("pickup", new int[] { 16, 16, 16 }, new float[] { vMs, vMs });
            _spriteMap.Add("dropoff", new int[] { 16, 16, 16 }, new float[] { vMs, vMs });
            _spriteMap.Add("hit", new int[] { 1, 2, 6, 5 }, new float[] { vMs, vMs });
        }*/
        #endregion

        public void PressKeysForAnimation(Controller cn, string l, string r, string u, string d)
        {
            if (_isShooting)
                movement.Freeze = true;
            else
                movement.Freeze = false;
            #region pressed Keys for animation
            if (cn.Button("Left").Pressed && Global.IsPlayer2GunCollected)//LEFT with gun
            {
                if (movement.Freeze)
                    Shared.ChangeAnimTo("shootLeft", _spriteMap);
                else
                    Shared.ChangeAnimTo("walkShootLeft", _spriteMap);
                _spriteMap.FlippedX = true;
                IsL = true; IsR = false; IsU = false; IsD = false;
            }
            else if (cn.Button("Right").Pressed && Global.IsPlayer2GunCollected)//RIGHT with gun
            {
                if (movement.Freeze)
                    Shared.ChangeAnimTo("shootRight", _spriteMap);
                else
                    Shared.ChangeAnimTo("walkShootRight", _spriteMap);
                _spriteMap.FlippedX = false;
                IsL = false; IsR = true; IsU = false; IsD = false;
            }
            else if (cn.Button("Up").Pressed && Global.IsPlayer2GunCollected)//UP with gun
            {
                if (movement.Freeze)
                    Shared.ChangeAnimTo("shootUp", _spriteMap);
                else
                    Shared.ChangeAnimTo("walkShootUp", _spriteMap);
                _spriteMap.FlippedX = false;
                IsL = false; IsR = false; IsU = true; IsD = false;
            }
            else if (cn.Button("Down").Pressed && Global.IsPlayer2GunCollected)//DOWN with gun
            {
                if (movement.Freeze)
                    Shared.ChangeAnimTo("shootDown", _spriteMap);
                else
                    Shared.ChangeAnimTo("walkShootDown", _spriteMap);
                _spriteMap.FlippedX = false;
                IsL = false; IsR = false; IsU = false; IsD = true;
            }
            else if (cn.Button("Left").Pressed)//LEFT
            {
                Shared.ChangeAnimTo(l, _spriteMap);
                _spriteMap.FlippedX = true;
                IsL = true; IsR = false; IsU = false; IsD = false;
            }
            else if (cn.Button("Right").Pressed)//RIGHT
            {
                Shared.ChangeAnimTo(r, _spriteMap);
                _spriteMap.FlippedX = false;
                IsL = false; IsR = true; IsU = false; IsD = false;
            }
            else if (cn.Button("Up").Pressed)//UP
            {
                Shared.ChangeAnimTo(u, _spriteMap);
                _spriteMap.FlippedX = true;
                IsL = false; IsR = false; IsU = true; IsD = false;
            }
            else if (cn.Button("Down").Pressed)//DOWN
            {
                Shared.ChangeAnimTo(d, _spriteMap);
                _spriteMap.FlippedX = false;
                IsL = false; IsR = false; IsU = false; IsD = true;
            }

            #endregion
            #region released keys for animation
            if (cn.Button("Left").Released && Global.IsPlayer2GunCollected)//if i release left, updownright
            {
                if (cn.Button("Up").Down)//and i'm holding up
                {
                    if (movement.Freeze)
                        Shared.ChangeAnimTo("shootUp", _spriteMap);
                    else
                        Shared.ChangeAnimTo("walkShootUp", _spriteMap);
                    _spriteMap.FlippedX = false;
                }
                else if (cn.Button("Down").Down)//and i'm holding down
                {
                    if (movement.Freeze)
                        Shared.ChangeAnimTo("shootDown", _spriteMap);
                    else
                        Shared.ChangeAnimTo("walkShootDown", _spriteMap);
                    _spriteMap.FlippedX = false;
                }
                else if (cn.Button("Right").Down)//and i'm holding right
                {
                    if (movement.Freeze)
                        Shared.ChangeAnimTo("shootRight", _spriteMap);
                    else
                        Shared.ChangeAnimTo("walkShootRight", _spriteMap);
                    _spriteMap.FlippedX = false;
                }
            }
            else if (cn.Button("Right").Released && Global.IsPlayer2GunCollected)//if i release right, updownleft
            {
                if (cn.Button("Up").Down)//and i'm holding up
                {
                    if (movement.Freeze)
                        Shared.ChangeAnimTo("shootUp", _spriteMap);
                    else
                        Shared.ChangeAnimTo("walkShootUp", _spriteMap);
                    _spriteMap.FlippedX = false;
                }
                else if (cn.Button("Down").Down)//and i'm holding down
                {
                    if (movement.Freeze)
                        Shared.ChangeAnimTo("shootDown", _spriteMap);
                    else
                        Shared.ChangeAnimTo("walkShootDown", _spriteMap);
                    _spriteMap.FlippedX = false;
                }
                else if (cn.Button("Left").Down)//and i'm holding left
                {
                    if (movement.Freeze)
                        Shared.ChangeAnimTo("shootLeft", _spriteMap);
                    else
                        Shared.ChangeAnimTo("walkShootLeft", _spriteMap);
                    _spriteMap.FlippedX = true;
                }
            }
            else if (cn.Button("Up").Released && Global.IsPlayer2GunCollected)//if i release up, rightleftdown
            {
                if (cn.Button("Right").Down)//and i'm holding right
                {
                    if (movement.Freeze)
                        Shared.ChangeAnimTo("shootRight", _spriteMap);
                    else
                        Shared.ChangeAnimTo("walkShootRight", _spriteMap);
                    _spriteMap.FlippedX = false;
                }
                else if (cn.Button("Left").Down)//and i'm holding left
                {
                    if (movement.Freeze)
                        Shared.ChangeAnimTo("shootLeft", _spriteMap);
                    else
                        Shared.ChangeAnimTo("walkShootLeft", _spriteMap);
                    _spriteMap.FlippedX = true;
                }
                else if (cn.Button("Down").Down)//and i'm holding down
                {
                    if (movement.Freeze)
                        Shared.ChangeAnimTo("shootDown", _spriteMap);
                    else
                        Shared.ChangeAnimTo("walkShootDown", _spriteMap);
                    _spriteMap.FlippedX = false;
                }
            }
            else if (cn.Button("Down").Released && Global.IsPlayer2GunCollected)//if i release down, rightleftup
            {
                if (cn.Button("Right").Down)//and i'm holding right
                {
                    if (movement.Freeze)
                        Shared.ChangeAnimTo("shootRight", _spriteMap);
                    else
                        Shared.ChangeAnimTo("walkShootRight", _spriteMap);
                    _spriteMap.FlippedX = false;
                }
                else if (cn.Button("Left").Down)//and i'm holding left
                {
                    if (movement.Freeze)
                        Shared.ChangeAnimTo("shootLeft", _spriteMap);
                    else
                        Shared.ChangeAnimTo("walkShootLeft", _spriteMap);
                    _spriteMap.FlippedX = true;
                }
                else if (cn.Button("Up").Down)//and i'm holding up
                {
                    if (movement.Freeze)
                        Shared.ChangeAnimTo("shootUp", _spriteMap);
                    else
                        Shared.ChangeAnimTo("walkShootUp", _spriteMap);
                    _spriteMap.FlippedX = false;
                }
            }
            else if (cn.Button("Left").Released)//if i release left, updownright
            {
                if (cn.Button("Up").Down)//and i'm holding up
                {
                    Shared.ChangeAnimTo(u, _spriteMap);
                    _spriteMap.FlippedX = true;
                }
                else if (cn.Button("Down").Down)//and i'm holding down
                {
                    Shared.ChangeAnimTo(d, _spriteMap);
                    _spriteMap.FlippedX = false;
                }
                else if (cn.Button("Right").Down)//and i'm holding right
                {
                    Shared.ChangeAnimTo(r, _spriteMap);
                    _spriteMap.FlippedX = false;
                }
            }
            else if (cn.Button("Right").Released)//if i release right, updownleft
            {
                if (cn.Button("Up").Down)//and i'm holding up
                {
                    Shared.ChangeAnimTo(u, _spriteMap);
                    _spriteMap.FlippedX = true;
                }
                else if (cn.Button("Down").Down)//and i'm holding down
                {
                    Shared.ChangeAnimTo(d, _spriteMap);
                    _spriteMap.FlippedX = false;
                }
                else if (cn.Button("Left").Down)//and i'm holding left
                {
                    Shared.ChangeAnimTo(l, _spriteMap);
                    _spriteMap.FlippedX = true;
                }
            }
            else if (cn.Button("Up").Released)//if i release up, rightleftdown
            {
                if (cn.Button("Right").Down)//and i'm holding right
                {
                    Shared.ChangeAnimTo(r, _spriteMap);
                    _spriteMap.FlippedX = false;
                }
                else if (cn.Button("Left").Down)//and i'm holding left
                {
                    Shared.ChangeAnimTo(l, _spriteMap);
                    _spriteMap.FlippedX = true;
                }
                else if (cn.Button("Down").Down)//and i'm holding down
                {
                    Shared.ChangeAnimTo(d, _spriteMap);
                    _spriteMap.FlippedX = false;
                }
            }
            else if (cn.Button("Down").Released)//if i release down, rightleftup
            {
                if (cn.Button("Right").Down)//and i'm holding right
                {
                    Shared.ChangeAnimTo(r, _spriteMap);
                    _spriteMap.FlippedX = false;
                }
                else if (cn.Button("Left").Down)//and i'm holding left
                {
                    Shared.ChangeAnimTo(l, _spriteMap);
                    _spriteMap.FlippedX = true;
                }
                else if (cn.Button("Up").Down)//and i'm holding up
                {
                    Shared.ChangeAnimTo(u, _spriteMap);
                    _spriteMap.FlippedX = true;
                }
            }
            #endregion
            if (Global.IsPlayer2GunCollected)
            {
                if (IsL && cn.Button("NumZero").Pressed && !Player2Aimer.IsActive)//LEFT
                {
                    //Scene.Add(new Grapple(X, Y, "Left", this));
                    Scene.Add(new Player2Aimer("left"));
                    _isShooting = true;
                }
                if (IsR && cn.Button("NumZero").Pressed && !Player2Aimer.IsActive)//RIGHT
                {
                    Scene.Add(new Player2Aimer("right"));
                    //Scene.Add(new Grapple(X, Y, "Right", this));
                    _isShooting = true;
                }
                if (IsU && cn.Button("NumZero").Pressed && !Player2Aimer.IsActive)//UP
                {
                    Scene.Add(new Player2Aimer("up"));
                    //Scene.Add(new Grapple(X, Y, "Up", this));
                    _isShooting = true;
                }
                if (IsD && cn.Button("NumZero").Pressed && !Player2Aimer.IsActive)//DOWN
                {
                    Scene.Add(new Player2Aimer("down"));
                    //Scene.Add(new Grapple(X, Y, "Down", this));
                    _isShooting = true;
                }
            }
        }

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

        public void Destroy()
        {
            RemoveSelf();
        }

    }
}
