public void update(List<Wall> walls, BulletManager bm)
 {
     for (int i = 0; i < enemys.Count; i++ )
     {
         enemys[i].update(walls, bm);
         if (enemys[i].health <= 0)
         {
             enemys.Remove(enemys[i]);
             i--;
         }
     }
 }
        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 PlayerManager(ContentManager Content, BulletManager bm, Camera cam, int numPlayers)
 {
     players = new Dictionary<PlayerIndex, Player>();
     if (GamePad.GetState(PlayerIndex.One).IsConnected && numPlayers > 0)
     {
         players.Add(PlayerIndex.One, new Player(PlayerIndex.One, Content, bm, players, new Vector2(100, 100)));
     }
     if (GamePad.GetState(PlayerIndex.Two).IsConnected && numPlayers > 1)
     {
         players.Add(PlayerIndex.Two, new Player(PlayerIndex.Two, Content, bm, players, new Vector2(100, 200)));
     }
     if (GamePad.GetState(PlayerIndex.Three).IsConnected && numPlayers > 2)
     {
         players.Add(PlayerIndex.Three, new Player(PlayerIndex.Three, Content, bm, players, new Vector2(200, 100)));
     }
     if (GamePad.GetState(PlayerIndex.Four).IsConnected && numPlayers > 3)
     {
         players.Add(PlayerIndex.Four, new Player(PlayerIndex.Four, Content, bm, players, new Vector2(200, 200)));
     }
     camera = cam;
 }
        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"));
        }
        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;
        }