public void update(WallManager walls)
 {
     int newCamX = 0;
     List<Player> values = Enumerable.ToList(players.Values);
     foreach (Player current in values)
     {
         current.update(walls);
         newCamX += current.boundingBox.X;
     }
     if (players.Count != 0)
         newCamX /= players.Count;
     else
         Game1.state = GameState.GameOver;
     camera.Pos = new Vector2(newCamX, camera.Pos.Y);
 }
        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 startGame(int p)
        {
            ground = Content.Load<Texture2D>("ground");

            Texture2D fireball = Content.Load<Texture2D>("Fireball"); ;
            bullets = new BulletManager(fireball);

            walls = new WallManager(cam, GraphicsDevice);
            players = new PlayerManager(Content, bullets, cam, p);

            enemies = new EnemyManager(Content, players.players);

            spawn = new Spawner[10];

            Texture2D spawner = Content.Load<Texture2D>("spawner");

            for (int i = 0; i < 10; i++)
            {
                int y = 10;
                if((i+1)%2 == 1)
                    y = 420;
                spawn[i] = new Spawner(enemies, new Vector2((800 * i) + 10, y), cam, spawner);
            }

            ui = new UI(players.players, cam);
            item = new Item(new Vector2(Game1.width - 100 ,215) , players, Content.Load<Texture2D>("Treasure"));
        }