Example #1
0
 public void Update(GameTime gameTime, Player player)
 {
     if (player.Lives > 0)
     {
         for (int i = powerUps.Count - 1; i >= 0; i--)
         {
             if (!powerUps[i].Collided)
             {
                 if (powerUps[i].Bounds.Intersects(player.Bounds))
                 {
                     if (!IntersectPixels(powerUps[i].Transformation, powerUps[i].spriteImage.Width, powerUps[i].spriteImage.Height, powerUps[i].TextureData,
                                             player.Transformation, player.spriteImage.Width, player.spriteImage.Height, player.TextureData))
                     {
                         switch (powerUps[i].Type)
                         {
                             case PowerUpType.LIFE_UP:
                                 if (player.Lives < 8)
                                     player.Lives++;
                                 break;
                             case PowerUpType.WEAPON_UPGRADE:
                                 if (player.WeaponLevel < 3)
                                     player.WeaponLevel++;
                                 break;
                             case PowerUpType.WEAPON_SPEED:
                                 break;
                         }
                         SoundManager.soundEffects["powerup"].Play();
                         powerUps[i].Collided = true;
                     }
                 }
                 powerUps[i].Update(gameTime);
             }
             if (powerUps[i].Collided)
                 powerUps.Remove(powerUps[i]);
         }
     }
 }
Example #2
0
        public void Update(GameTime gameTime, Player player)
        {
            float dt = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (collided || health == 0)
            {
                ParticleManager.particleEffects["SMALL_EXPLOSION"].Trigger(position);
                if (type != EnemyType.SMALL_SPINNER)
                    SoundManager.soundEffects["explosion"].Play();
                int randn = Manager.rand.Next(0,100);
                if (randn <= 5 && type != EnemyType.SMALL_SPINNER)
                {
                    int powerUpTypeChance = Manager.rand.Next(0, 10);
                    if (powerUpTypeChance >= 0 && powerUpTypeChance <= 6)
                        PowerUpManager.PowerUps.Add(new PowerUp(PowerUpType.LIFE_UP, position));
                    else if (powerUpTypeChance > 6 && powerUpTypeChance <= 10)
                        PowerUpManager.PowerUps.Add(new PowerUp(PowerUpType.WEAPON_UPGRADE, position));
                    //else
                       // PowerUpManager.PowerUps.Add(new PowerUp(PowerUpType.WEAPON_SPEED, position));
                }
            }
            if (type == EnemyType.ALIEN) // Follow + Shoot at player
            {
                fireTime += dt;

                float distanceFromPlayer = Vector2.Distance(position, player.Position);

                // Only follow player if the enemy is close enough to the player, else wander around the map
                if (distanceFromPlayer < 200.0F)
                {
                    Vector2 direction = player.Position - position;
                    direction.Normalize();
                    velocity = direction * speed;
                    angle = (float)(Math.Atan2(direction.Y, direction.X));

                    if (fireTime > FIRE_DELAY)
                    {
                        eBullets.Add(new Projectile(ProjectileType.NORMAL_BULLET, player.projectileTextures["NORMAL_BULLET"], position, direction * -1, angle));
                        fireTime = 0;
                    }
                }
                // Wander
                else
                {
                    Vector2 dir = player.Position;
                    Wander(position, ref dir, ref angle, 15.0F);
                    velocity += new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * (1.2F);
                }

                foreach (Projectile eBullet in eBullets)
                {
                    eBullet.Update(gameTime);
                }
            }
            // Armored type enemies evade the player when too close
            else if (type == EnemyType.ARMORED)
            {
                float distanceFromPlayer = Vector2.Distance(position, player.Position);
                if (distanceFromPlayer < 200F)
                {
                    Vector2 seekPosition = 2 * position - player.Position;

                    angle = TurnToFace(position, seekPosition,
                        angle, 44.0F);
                    if (velocity.X < maxVelocity && velocity.Y < maxVelocity)
                        velocity += new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * 1.2F;
                }
                else
                {
                    Vector2 dir = player.Position;
                    Wander(position, ref dir, ref angle, 15.0F);
                    velocity += new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * (1.2F);
                }
            }
            else
            {
                angle += rotation;
            }
            base.Update(gameTime);

            if (type == EnemyType.SMALL_SPINNER || type == EnemyType.LARGE_SPINNER)
            {

            }
            else
                ReflectOffViewport(50);
        }
Example #3
0
        public void Update(GameTime gameTime, Player player)
        {
            float elapsedTime = (float) gameTime.ElapsedGameTime.TotalSeconds;
            if (player.Lives > 0) // Keep spawning enemies until player runs out of lives
            {
                delayTimer = delayTimer.Subtract(gameTime.ElapsedGameTime);

                // Spawn enemies
                if (delayTimer.TotalSeconds <= 0)
                {
                    for (int i = 0; i < rand.Next(1, 2); i++)
                    {
                        spawnChance = rand.Next(100);
                        if (spawnChance <= largeAsteroidChance)
                        {
                            SpawnRandomAsteroid(EnemyType.LARGE_ASTEROID);
                        }
                        else if (spawnChance >= mediumAsteroidChance && spawnChance < smallAsteroidChance)
                        {
                            SpawnRandomAsteroid(EnemyType.MEDIUM_ASTEROID);
                        }
                        else if (spawnChance >= smallAsteroidChance)
                        {
                            SpawnRandomAsteroid(EnemyType.SMALL_ASTEROID);
                        }
                    }
                    if (player.Score > 5000)
                    {
                        if (spawnChance < 10)
                        {
                            SpawnSpinnerGroup(0);
                        }
                        spawnDelay = 1.1F;
                    }
                    if (player.Score > 8000)
                    {
                        if (spawnChance < 15)
                        {
                            for (int i = 0; i < rand.Next(1, 3); i++)
                                SpawnAlien();
                        }
                        if (rand.Next(0, 50) < 10)
                        {
                            for (int i = 0; i < rand.Next(1, 2); i++)
                            {
                                Enemy armored = new Enemy(EnemyType.ARMORED, enemyTextures["ARMORED"], EnemyColor.NONE);
                                armored.Position = new Vector2(rand.Next(100, ActionScreen.background.Width), rand.Next(100, ActionScreen.background.Height));
                                enemies.Add(armored);
                            }
                        }
                        spawnDelay = 1F;
                    }
                    if (player.Score > 15000)
                    {
                        spawnDelay = .9F;
                    }

                    delayTimer = TimeSpan.FromSeconds(spawnDelay);
                }
                player.Collided = false;
                // Update all enemies in the enemies list
                for (int i = enemies.Count - 1; i >= 0; i--)
                {
                    // Only update enemies that have not collided yet (Enemies that are not dead)
                    if (!enemies[i].Collided)
                    {
                        if (enemies[i].Type == EnemyType.SMALL_SPINNER || enemies[i].Type == EnemyType.LARGE_SPINNER)
                        {
                            if (enemies[i].OutOfViewPort(ActionScreen.background))
                            {
                                enemies[i].Collided = true;
                            }
                        }
                        // Collision detection for enemies and player
                        if (enemies[i].Bounds.Intersects(player.Bounds))
                        {
                            // Per pixel collision detection
                            if (!IntersectPixels(enemies[i].Transformation, enemies[i].spriteImage.Width, enemies[i].spriteImage.Height, enemies[i].TextureData,
                                                player.Transformation, player.spriteImage.Width, player.spriteImage.Height, player.TextureData))
                            {
                                enemies[i].Collided = true;
                                player.Collided = true;
                                player.Lives -= 1;
                                if (player.WeaponLevel > 1)
                                    player.WeaponLevel -= 1;
                            }
                        }

                        // Collision detection for enemies and bullets
                        for (int j = player.Bullets.Count - 1; j >= 0; j--)
                        {
                            if (!player.Bullets[j].Collided)
                            {
                                if (enemies[i].Bounds.Intersects(player.Bullets[j].Bounds))
                                {

                                    if (!IntersectPixels(enemies[i].Transformation, enemies[i].spriteImage.Width, enemies[i].spriteImage.Height, enemies[i].TextureData,
                                                        player.Bullets[j].Transformation, player.Bullets[j].spriteImage.Width, player.Bullets[j].spriteImage.Height, player.Bullets[j].TextureData))
                                    {
                                        enemies[i].Health -= player.Bullets[j].Damage;
                                        if (enemies[i].Health <= 0)
                                        {
                                            // Only "downgrade" if enemy is an asteroid
                                            if (enemies[i].Type == EnemyType.SMALL_ASTEROID || enemies[i].Type == EnemyType.MEDIUM_ASTEROID || enemies[i].Type == EnemyType.LARGE_ASTEROID)
                                            {
                                                if (enemies[i].Type == EnemyType.LARGE_ASTEROID || enemies[i].Type == EnemyType.MEDIUM_ASTEROID)
                                                {
                                                    downgradeEnemy(enemies[i]);
                                                    enemies[i].Center = new Vector2(enemies[i].spriteImage.Width / 2, enemies[i].spriteImage.Height / 2);
                                                }
                                                else
                                                {
                                                    enemies[i].Collided = true;
                                                }
                                            }
                                            else
                                            {
                                                enemies[i].Collided = true;
                                            }
                                            player.Score += enemies[i].PointValue;
                                        }
                                        player.Bullets[j].Collided = true;
                                        ParticleManager.particleEffects["Ricoshet"].Trigger(player.Bullets[j].Position);
                                    }
                                }
                                else
                                {
                                    if (player.Bullets[j].OutOfViewPort(ActionScreen.background))
                                    {
                                        player.Bullets[j].Collided = true;
                                        ParticleManager.particleEffects["Ricoshet"].Trigger(player.Bullets[j].Position);
                                    }
                                }
                            }
                            if (player.Bullets[j].Collided)
                            {
                                player.Bullets.Remove(player.Bullets[j]);
                            }
                        }

                        // Collision detection for alien bullets with player
                        if (enemies[i].Type == EnemyType.ALIEN)
                        {
                            for (int j = enemies[i].EBullets.Count - 1; j >= 0; j--)
                            {
                                if (player.Bounds.Intersects(enemies[i].EBullets[j].Bounds))
                                {

                                    if (!IntersectPixels(player.Transformation, player.spriteImage.Width, player.spriteImage.Height, player.TextureData,
                                                        enemies[i].EBullets[j].Transformation, enemies[i].EBullets[j].spriteImage.Width, enemies[i].EBullets[j].spriteImage.Height, enemies[i].EBullets[j].TextureData))
                                    {
                                        enemies[i].EBullets[j].Collided = true;
                                        player.Lives--;
                                    }
                                }
                                if (enemies[i].EBullets[j].Collided)
                                {
                                    enemies[i].EBullets.Remove(enemies[i].EBullets[j]);
                                }
                            }
                        }
                        enemies[i].Update(gameTime, player);
                    }
                    if (enemies[i].Collided)
                    {
                        enemies.Remove(enemies[i]);
                    }
                }
            }
            // Player lost
            else
            {
                player.Collided = false;
            }
            Console.WriteLine("bullet list size: " + player.Bullets.Count);
        }
Example #4
0
        private float spawnDelay = 1.2F; // Time between each enemy spawn

        #endregion Fields

        #region Constructors

        public EnemyManager(Player player)
        {
            enemies = new List<Enemy>();
            delayTimer = TimeSpan.FromSeconds(spawnDelay);
        }
Example #5
0
        public void LoadContent(ContentManager content)
        {
            // Load particles
            particleManager.addEffect("SMALL_EXPLOSION", content.Load<ParticleEffect>("Particle Effects/Explosion-Red"));
            particleManager.addEffect("SMALL_EXPLOSION2", content.Load<ParticleEffect>("Particle Effects/Explosion-Orange"));
            particleManager.addEffect("MEDIUM_EXPLOSION_PINK", content.Load<ParticleEffect>("Particle Effects/Explosion-Medium-Pink"));
            particleManager.addEffect("LARGE_EXPLOSION_BLUE", content.Load<ParticleEffect>("Particle Effects/Large-Explosion-Blue-Remake"));
            particleManager.addEffect("Ship-Trail-Blue", content.Load<ParticleEffect>("Particle Effects/Ship-Trail-Blue"));
            particleManager.addEffect("MissleTrail-Orange", content.Load<ParticleEffect>("Particle Effects/MissleTrail-Orange"));
            particleManager.addEffect("Ricoshet", content.Load<ParticleEffect>("Particle Effects/Ricochet-Yellow"));
            particleManager.addEffect("WarpIn", content.Load<ParticleEffect>("Particle Effects/WarpIn2"));
            particleManager.LoadContent(content);

            score = content.Load<SpriteFont>("Fonts/scoreFont");
            livesIcon = content.Load<Texture2D>("lives_icon");
            background = new Background(content.Load<Texture2D>("grid_background"));

            player = new Player(content.Load<Texture2D>("PlayerShip"));
            crosshair = content.Load<Texture2D>("crosshair");

            // Load enemy textures
            enemyManager = new EnemyManager(player);
            enemyManager.enemyTextures.Add("SMALL_ASTEROID_RED", content.Load<Texture2D>("SMALL_ASTEROID_RED"));
            enemyManager.enemyTextures.Add("SMALL_ASTEROID_BLUE", content.Load<Texture2D>("SMALL_ASTEROID_BLUE"));
            enemyManager.enemyTextures.Add("SMALL_ASTEROID_GREEN", content.Load<Texture2D>("SMALL_ASTEROID_GREEN"));
            enemyManager.enemyTextures.Add("SMALL_ASTEROID_PINK", content.Load<Texture2D>("SMALL_ASTEROID_PINK"));
            enemyManager.enemyTextures.Add("SMALL_ASTEROID_PURPLE", content.Load<Texture2D>("SMALL_ASTEROID_PURPLE"));

            enemyManager.enemyTextures.Add("MEDIUM_ASTEROID_RED", content.Load<Texture2D>("MEDIUM_ASTEROID_RED"));
            enemyManager.enemyTextures.Add("MEDIUM_ASTEROID_BLUE", content.Load<Texture2D>("MEDIUM_ASTEROID_BLUE"));
            enemyManager.enemyTextures.Add("MEDIUM_ASTEROID_GREEN", content.Load<Texture2D>("MEDIUM_ASTEROID_GREEN"));
            enemyManager.enemyTextures.Add("MEDIUM_ASTEROID_PINK", content.Load<Texture2D>("MEDIUM_ASTEROID_PINK"));
            enemyManager.enemyTextures.Add("MEDIUM_ASTEROID_PURPLE", content.Load<Texture2D>("MEDIUM_ASTEROID_PURPLE"));

            enemyManager.enemyTextures.Add("LARGE_ASTEROID_RED", content.Load<Texture2D>("LARGE_ASTEROID_RED"));
            enemyManager.enemyTextures.Add("LARGE_ASTEROID_BLUE", content.Load<Texture2D>("LARGE_ASTEROID_BLUE"));
            enemyManager.enemyTextures.Add("LARGE_ASTEROID_GREEN", content.Load<Texture2D>("LARGE_ASTEROID_GREEN"));
            enemyManager.enemyTextures.Add("LARGE_ASTEROID_PINK", content.Load<Texture2D>("LARGE_ASTEROID_PINK"));
            enemyManager.enemyTextures.Add("LARGE_ASTEROID_PURPLE", content.Load<Texture2D>("LARGE_ASTEROID_PURPLE"));

            enemyManager.enemyTextures.Add("LARGE_SPINNER_BLUE", content.Load<Texture2D>("LARGE_SPINNER_BLUE"));
            enemyManager.enemyTextures.Add("SMALL_SPINNER_PINK", content.Load<Texture2D>("SMALL_SPINNER_Pink"));

            enemyManager.enemyTextures.Add("ALIEN", content.Load<Texture2D>("ALIEN"));
            enemyManager.enemyTextures.Add("ARMORED", content.Load<Texture2D>("ArmoredEnemy"));

            // Load projectile textures
            player.projectileTextures.Add("NORMAL_BULLET", content.Load<Texture2D>("Projectile2"));
            player.projectileTextures.Add("NORMAL_MISSLE", content.Load<Texture2D>("NORMAL_MISSLE"));

            PowerUpManager.PowerUpTextures.Add("LIFE_UP", content.Load<Texture2D>("powerup_lifeup"));
            PowerUpManager.PowerUpTextures.Add("WEAPON_UPGRADE", content.Load<Texture2D>("powerup_weaponPower"));

            // Load sounds
            SoundManager.soundEffects.Add("player_weapon", content.Load<SoundEffect>("Sounds/fire_laser1"));
            SoundManager.soundEffects.Add("explosion", content.Load<SoundEffect>("Sounds/sound_explosion"));
            SoundManager.soundEffects.Add("powerup", content.Load<SoundEffect>("Sounds/sound_powerup"));

            backgroundLoop = content.Load<Song>("Sounds/particleillusionloop");
            MediaPlayer.Play(backgroundLoop);
            MediaPlayer.IsRepeating = true;
            PauseOverlay = content.Load<Texture2D>("pause_overlay");

            cam = new Camera();
            bloom.Settings = BloomSettings.PresetSettings[6];
            bloom.Visible = true;
        }