public Enemy(Texture2D[] td, Player ta, Vector2 position, Dictionary<PlayerIndex, Player> players)
 {
     this.players = players;
     texture = td;
     target = ta;
     boundingBox = new Rectangle((int)position.X, (int)position.Y, 30, 30);
 }
        public TargetBullet(Player t, Texture2D tex, Direction dir, Vector2 position)
        {
            target = t;
            texture = tex;
            direction = dir;
            boundingBox = new Rectangle((int)position.X, (int)position.Y, tex.Width*2, tex.Height*2);

            if (t.index == PlayerIndex.One)
                color = Color.Green;
            if (t.index == PlayerIndex.Two)
                color = Color.Red;
            if (t.index == PlayerIndex.Three)
                color = Color.Yellow;
            if (t.index == PlayerIndex.Four)
                color = Color.Blue;
        }
        public Player(PlayerIndex i, ContentManager Content, BulletManager bm, Dictionary<PlayerIndex, Player> p, Vector2 position)
        {
            index = i;
            string ps = "";
            if (index == PlayerIndex.One)
            {
                ps = "Player1";
            }
            if (index == PlayerIndex.Two)
            {
                ps = "Player2";
            }
            if (index == PlayerIndex.Three)
            {
                ps = "Player3";
            }
            if (index == PlayerIndex.Four)
            {
                ps = "Player4";
            }
            texture = new Dictionary<Direction, Texture2D>();
            texture.Add(Direction.North, Content.Load<Texture2D>(ps + "/North"));
            texture.Add(Direction.South, Content.Load<Texture2D>(ps + "/South"));
            texture.Add(Direction.East, Content.Load<Texture2D>(ps + "/East"));
            texture.Add(Direction.West, Content.Load<Texture2D>(ps + "/West"));

            target = this;

            players = p;

            bulletManager = bm;

            if (index == PlayerIndex.One)
                color = Color.Green;
            if (index == PlayerIndex.Two)
                color = Color.Red;
            if (index == PlayerIndex.Three)
                color = Color.Yellow;
            if (index == PlayerIndex.Four)
                color = Color.Blue;
            boundingBox = new Rectangle(50, 50, 20,30);
        }
 public void shootTarget(Player target, Direction direction, Vector2 position)
 {
     targetBullets.Add(new TargetBullet(target, texture, direction, position));
 }
        public void update(WallManager wm)
        {
            if (this.health <= 0)
            {
                if (item != null)
                {
                    item.boundingBox.X = this.boundingBox.X;
                    item.boundingBox.Y = this.boundingBox.Y;
                    item.pickedUp = false;
                }
                players.Remove(this.index);
            }

            if (boundingBox.X < 100 && item != null)
                Game1.state = GameState.Win;

            #region movement
            float x = GamePad.GetState(index).ThumbSticks.Left.X;
            float y = GamePad.GetState(index).ThumbSticks.Left.Y;
            int curSpeed = speed;
            if (x == 0 && y == 0)
                curSpeed = 0;
            double angle = Math.Atan2(y,x);
            boundingBox.Y -= (int)(curSpeed * Math.Sin(angle));
            foreach (Wall current in wm.walls)
            {
                if (boundingBox.Intersects(current.boundingBox))
                {
                    if (y > 0)
                        boundingBox.Y = current.boundingBox.Y + current.boundingBox.Height + 1;
                    else
                        boundingBox.Y = current.boundingBox.Y - boundingBox.Height - 1;
                }
            }
            boundingBox.X += (int)(Math.Cos(angle) * curSpeed);
            foreach (Wall current in wm.walls)
            {
                if (boundingBox.Intersects(current.boundingBox))
                {
                    if (x < 0)
                        boundingBox.X = current.boundingBox.X + current.boundingBox.Width + 1;
                    else
                        boundingBox.X = current.boundingBox.X - boundingBox.Width - 1;
                }
            }
            foreach (CameralWall current in wm.camWalls)
            {
                if (boundingBox.Intersects(current.boundingBox))
                {
                    if (x < 0)
                        boundingBox.X = current.boundingBox.X + current.boundingBox.Width + 1;
                    else
                        boundingBox.X = current.boundingBox.X - boundingBox.Width - 1;
                }
            }
            #endregion
            #region Attacks
            float lookX = GamePad.GetState(index).ThumbSticks.Right.X;
            float lookY = GamePad.GetState(index).ThumbSticks.Right.Y;
            if (Math.Abs(lookX) > Math.Abs(lookY))
            {
                if (lookX > 0)
                    this.state = Direction.East;
                if (lookX < 0)
                    this.state = Direction.West;
            }
            else
            {
                if (lookY > 0)
                    this.state = Direction.North;
                if (lookY < 0)
                    this.state = Direction.South;
            }
            cooldown--;

            if (GamePad.GetState(index).IsButtonDown(Buttons.RightTrigger) && cooldown <= 0)
            {
                cooldown = 20;
                bulletManager.shootTarget(target, this.state, new Vector2(boundingBox.Center.X, boundingBox.Center.Y));
            }

            #region Target
            if (GamePad.GetState(index).IsButtonDown(Buttons.A))
            {
                if(players.ContainsKey(PlayerIndex.One))
                    target = players[PlayerIndex.One];
            }
            if (GamePad.GetState(index).IsButtonDown(Buttons.B) && players.ContainsKey(PlayerIndex.Two))
            {
                if (players.ContainsKey(PlayerIndex.Two))
                    target = players[PlayerIndex.Two];
            }
            if (GamePad.GetState(index).IsButtonDown(Buttons.Y) && players.ContainsKey(PlayerIndex.Three))
            {
                if (players.ContainsKey(PlayerIndex.Three))
                    target = players[PlayerIndex.Three];
            }
            if (GamePad.GetState(index).IsButtonDown(Buttons.X) && players.ContainsKey(PlayerIndex.Four))
            {
                if (players.ContainsKey(PlayerIndex.Four))
                    target = players[PlayerIndex.Four];
            }
            if (!players.ContainsValue(target))
                target = this;
            #endregion

            #endregion
        }
        public void update(List<Wall> walls, BulletManager bm)
        {
            if (!players.ContainsValue(target) && players.Count != 0)
            {
                List<Player> values = Enumerable.ToList(players.Values);
                target = values[rand.Next(players.Count)];
            }
            double angle = Math.Atan2(boundingBox.Center.X - target.boundingBox.Center.X, boundingBox.Center.Y - target.boundingBox.Center.Y);
            boundingBox.Y -= (int)(Math.Cos(angle) * speed);

            if(this.boundingBox.Intersects(target.boundingBox))
            {
                boundingBox.X += 5*(int)(Math.Sin(angle) * speed);
                boundingBox.Y += 5*(int)(Math.Cos(angle) * speed);
                target.health--;
            }

            for (int i = 0; i < bm.targetBullets.Count; i++)
            {
                if (boundingBox.Intersects(bm.targetBullets[i].boundingBox))
                {
                    if (bm.targetBullets[i].direction == Direction.North)
                    {
                        boundingBox.Y -= 5;
                        target = bm.targetBullets[i].target;
                    }
                    if (bm.targetBullets[i].direction == Direction.South)
                    {
                        boundingBox.Y += 5;
                        target = bm.targetBullets[i].target;
                    }
                    if (bm.targetBullets[i].direction == Direction.East)
                    {
                        boundingBox.X += 5;
                        target = bm.targetBullets[i].target;
                    }
                    if (bm.targetBullets[i].direction == Direction.West)
                    {
                        boundingBox.X -= 5;
                        target = bm.targetBullets[i].target;
                    }
                    bm.killTarget(bm.targetBullets[i]);
                    health -= 5;
                }
            }
            foreach (Wall current in walls)
            {
                if (boundingBox.Intersects(current.boundingBox))
                {
                    if ((int)(Math.Cos(angle) * speed) > 0)
                        boundingBox.Y = current.boundingBox.Y + current.boundingBox.Height + 1;
                    else
                        boundingBox.Y = current.boundingBox.Y - boundingBox.Height - 1;
                }
            }

            boundingBox.X -= (int)(Math.Sin(angle) * speed);
            foreach (Wall current in walls)
            {
                if (boundingBox.Intersects(current.boundingBox))
                {
                    if ((int)(Math.Sin(angle) * speed) > 0)
                        boundingBox.X = current.boundingBox.X + current.boundingBox.Width + 1;
                    else
                        boundingBox.X = current.boundingBox.X - boundingBox.Width - 1;
                }
            }

            if (target.index == PlayerIndex.One)
                color = Color.Green;
            if (target.index == PlayerIndex.Two)
                color = Color.Red;
            if (target.index == PlayerIndex.Three)
                color = Color.Yellow;
            if (target.index == PlayerIndex.Four)
                color = Color.Blue;
        }