Exemplo n.º 1
0
        /*
         * public override void Update(GameTime dt)
         * {
         *  // Update players
         *  players.ForEach(delegate(Player p)
         *  {
         *      p.Update(dt);
         *  });
         *
         *  // Update Asteroids
         *  asteroidManager.Update(dt);
         *
         *  CheckCollisions();
         * }
         * */

        /*
         * public override void Draw(SpriteBatch spriteBatch)
         * {
         *  // Render Players
         *  players.ForEach(delegate(Player p)
         *  {
         *      p.Draw(spriteBatch);
         *  });
         *
         *  // Render Asteroids
         *  asteroidManager.Draw(spriteBatch);
         * }
         * */

        /*
         * public override void OnEvent(Event e)
         * {
         *  if (e.EventType == EventType.NEW_GAME)
         *  {
         *      InitGame();
         *  }
         *  base.OnEvent(e);
         * }
         */

        public void CheckCollisions()
        {
            asteroidManager.Asteroids.ForEach(delegate(Asteroid a)
            {
                players.ForEach(delegate(Player p)
                {
                    // Check for collisions between Asteroids and Players
                    if (Collision.BoundingSphere(a, p) == true)
                    {
                        asteroidManager.HandleCollision(a, p);
                    }

                    // Check for collisions with bullets
                    p.Bullets.ForEach(delegate(Bullet b)
                    {
                        // Bullets - Asteroids
                        if (Collision.BoundingSphere(b, a))
                        {
                            asteroidManager.HandleCollision(a, b);
                        }

                        // Bullets - Players
                        if (Collision.BoundingSphere(b, p))
                        {
                            p.HandleCollision(b);
                        }
                    });
                });
            });
        }
Exemplo n.º 2
0
        public void CheckMultiplayerCollisions()
        {
            foreach (NetworkGamer gamer in networkSession.AllGamers)
            {
                Player p = gamer.Tag as Player;

                asteroidManager.Asteroids.ForEach(delegate(Asteroid a)
                {
                    // Check for collisions between Asteroids and Players
                    if (Collision.BoundingSphere(a, p) == true)
                    {
                        asteroidManager.HandleCollision(a, p);

                        // Notifiy others players on the ship death
                        // SendLocalShipDeath();
                    }

                    // Check for collisions with bullets
                    for (int i = 0; i < p.Bullets.Length; i++)
                    {
                        Bullet b = p.Bullets[i];

                        if (b != null)
                        {
                            // Bullets - Asteroids
                            if (Collision.BoundingSphere(b, a))
                            {
                                asteroidManager.HandleCollision(a, b);
                            }
                        }
                    }
                });
            }
        }