public void Update(Player player, List<Enemy> Enemies, List<Asteroid> Astroids, List<Projectile> Projectiles)
        {
            for (int i = 0; i < Projectiles.Count; i++)
            {
                for (int ii = 0; ii < Enemies.Count; ii++)
                {
                    // Enemies
                    if (Projectiles[i].CollisionBox.Intersects(Enemies[ii].CollisionBox) && Projectiles[i].ShooterShip != Enemies[ii].myShip && Projectiles[i].EnemyProjectile == false)
                    {
                        Projectiles[i].Active = false;
                        DamageShip(Projectiles[i].ProjectileDamage, Enemies[ii].myShip);
                    }

                }

                // Player
                if (Projectiles[i].CollisionBox.Intersects(player.CollisionBox) && Projectiles[i].ShooterShip != player.myShip)
                {
                    Projectiles[i].Active = false;
                    DamageShip(Projectiles[i].ProjectileDamage, player.myShip);
                }

            }

            for (int i = 0; i < Enemies.Count; i++)
            {
                if (player.CollisionBox.Intersects(Enemies[i].CollisionBox))
                {
                    Enemies[i].myShip.Health = 0;
                    DamageShip(50, player.myShip); // Replace hard coded value with a variable
                }
            }

            for (int i = 0; i < Astroids.Count; i++)
            {
                if (player.CollisionBox.Intersects(Astroids[i].CollisionBox))
                {
                    Astroids[i].Health = 0;
                }
                for (int ii = 0; ii < Projectiles.Count; ii++)
                {
                    if (IntersectPixels(Projectiles[ii].myTransform, Projectiles[ii].Width, Projectiles[ii].Height, Projectiles[ii].TextureData, Astroids[i].myTransform, Astroids[i].Width, Astroids[i].Height, Astroids[i].TextureData))
                    {
                        Projectiles[ii].Active = false;
                        Astroids[i].Health -= Projectiles[ii].ProjectileDamage;
                    }
                }
            }

            // Check for game over
            if (player.myShip.Health <= 0)
                Game1.gameState = Game1.GameState.GameOver;
        }
示例#2
0
 /// <summary>
 /// Allows the game to perform any initialization it needs to before starting to run.
 /// This is where it can query for any required services and load any non-graphic
 /// related content.  Calling base.Initialize will enumerate through any components
 /// and initialize them as well.
 /// </summary>
 public void Initialize(ContentManager Content, GraphicsDevice graphicsDevice)
 {
     // TODO: Add your initialization logic here
     spawnManager = new SpawnManager(xmlEngine);
     player = new Player(xmlEngine);
     xmlEngine.PhraseWeaponXML();
     xmlEngine.PhraseShipXML();
     spawnManager.Initialize(graphicsDevice, Content);
     projectileManager.Initialize();
     player.Initialize();
     hudManager = new HudManager(player);
     hudManager.Initialize();
 }
示例#3
0
 public HudManager(Player player)
 {
     playerRef = player;
 }