示例#1
0
        public void InitializeGame()
        {
            health = new Healthbar(graphicsDevice);
            health.Initialize();

            floor = new Floor(graphicsDevice);
            floor.Initialize();

            ExplosionManager.Initialize(graphicsDevice);

            EntityManager.Add(Ship.Instance);

            camera = new Camera(graphicsDevice);
        }
示例#2
0
        static void HandleCollisions()
        {
            // handle collisions between bullets and enemy1
            for (int i = 0; i < enemy1.Count; i++)
            {
                for (int j = 0; j < playerbullets.Count; j++)
                {
                    if (IsColliding(enemy1[i], playerbullets[j]))
                    {
                        enemy1[i].health--;
                        playerbullets[j].IsExpired = true;
                        Game1.PlayerShoot.Play(0.4f, 0.8f, 0);
                        ExplosionManager.Add(new Explosion(enemy1[i].Position, 0, 2));
                        if (enemy1[i].health <= 0)
                        {
                            Game1.Explode.Play(0.4f, Game1.NextFloat(rand, 0.4f, 0.4f), 0);
                            ExplosionManager.Add(new Explosion(enemy1[i].Position, 0, 63));
                            enemy1[i].IsExpired = true;
                        }
                    }
                }
            }

            // handle collisions between bullets and enemy2
            for (int i = 0; i < enemy2.Count; i++)
            {
                for (int j = 0; j < playerbullets.Count; j++)
                {
                    if (IsColliding(enemy2[i], playerbullets[j]))
                    {
                        enemy2[i].health--;
                        playerbullets[j].IsExpired = true;
                        Game1.PlayerShoot.Play(0.4f, 0.8f, 0);
                        ExplosionManager.Add(new Explosion(enemy2[i].Position, 0, 2));
                        if (enemy2[i].health <= 0)
                        {
                            Game1.Explode.Play(0.4f, Game1.NextFloat(rand, 0.4f, 0.4f), 0);
                            ExplosionManager.Add(new Explosion(enemy2[i].Position, 0, 63));
                            enemy2[i].IsExpired = true;
                        }
                    }
                }
            }

            // handle collisions between bullets and player
            for (int i = 0; i < enemybullets.Count; i++)
            {
                if (IsColliding(Ship.Instance, enemybullets[i]))
                {
                    Healthbar.Hit();
                    enemybullets[i].IsExpired = true;
                    Game1.EnemyShoot.Play(0.4f, -0.8f, 0);
                }
            }

            // handle collisions between bullets and boss shield
            for (int i = 0; i < shield.Count; i++)
            {
                for (int j = 0; j < playerbullets.Count; j++)
                {
                    if (IsColliding(shield[i], playerbullets[j]))
                    {
                        shield[i].health--;
                        boss[0].health--;
                        playerbullets[j].IsExpired = true;
                        Game1.PlayerShoot.Play(0.4f, 0.8f, 0);
                        ExplosionManager.Add(new Explosion(shield[i].Position, 0, 2));
                        if (shield[i].health <= 0)
                        {
                            Game1.Explode.Play(0.4f, Game1.NextFloat(rand, 0.4f, 0.4f), 0);
                            ExplosionManager.Add(new Explosion(shield[i].Position, 0, 63));
                            shield[i].IsExpired = true;
                        }
                    }
                }
            }

            // handle collisions between bullets and boss core
            for (int i = 0; i < core.Count; i++)
            {
                for (int j = 0; j < playerbullets.Count; j++)
                {
                    if (IsColliding(core[i], playerbullets[j]))
                    {
                        core[i].health--;
                        boss[0].health--;
                        playerbullets[j].IsExpired = true;
                        Game1.PlayerShoot.Play(0.4f, 0.8f, 0);
                        ExplosionManager.Add(new Explosion(core[i].Position, 0, 2));
                        if (core[i].health <= 0)
                        {
                            Game1.Explode.Play(0.4f, Game1.NextFloat(rand, 0.4f, 0.4f), 0);
                            ExplosionManager.Add(new Explosion(core[i].Position, 0, 63));
                            core[i].IsExpired = true;
                        }
                    }
                }
            }

            //remove boss when cores destroyed
            if (core.Count > 0)
            {
                bossSpawned = true;
            }
            else if ((core.Count == 0) && (bossSpawned == true))
            {
                for (int i = 0; i < turret.Count; i++)
                {
                    turret[i].IsExpired = true;
                }
                ExplosionManager.Add(new Explosion(boss[0].Position, 0, 63));
                boss[0].IsExpired = true;
                bossSpawned       = false;
            }
        }