Пример #1
0
        }     //end method

        #region Entity & Collision Handling (enemies, bullets, etc)
        /// <summary>
        /// simple method that calls Update() on each bullet in the bullet lists
        /// </summary>
        private void HandleBullets()
        {
            for (int i = 0; i < playerBullets.Count; i++)
            {
                playerBullets[i].Update();
                if (OffScreen.Check((int)screen.Y, (int)screen.X, playerBullets[i].BoundingBox) || playerBullets[i].FlaggedForRemoval == true)
                {
                    playerBullets.RemoveAt(i);
                    i--;//dont want to skip anyhting in the list
                }
            }
            for (int i = 0; i < enemyBullets.Count; i++)
            {
                //if (enemyBullets[i] != null) --> no longer using array (see top of class)
                //{
                enemyBullets[i].Update();
                if (OffScreen.Check((int)screen.Y, (int)screen.X, enemyBullets[i].BoundingBox) || enemyBullets[i].FlaggedForRemoval == true)
                {
                    enemyBullets.RemoveAt(i);
                    i--;//dont want to skip anything in the list!
                    //   }
                }//end null check
            }
            //TODO: handle other bullet types
            //TODO: include offscreen check
        }
Пример #2
0
        /// <summary>
        /// Calls or handles all the updating and spawning for all enemies in the game
        /// </summary>
        private void HandleEnemies(TimeSpan time)
        {
            //////////////////////////////////////
            //TODO: add game state conditionals//
            /////////////////////////////////////
            Random aGen = new Random();

            if (aGen.Next(0, 101) % 35 == 0)
            {
                enemies.Add(new HomingEnemy(aGen.Next(30, (int)screen.X), -50, 3, "homingEnemy", (float)selectedDifficulty, playerOne.Centre));
                enemies.Add(new Enemy(aGen.Next(30, (int)screen.X), -50, 2, "enemy", (float)selectedDifficulty));
                if (aGen.Next() % 2 == 0)
                {
                    enemies.Add(new DiagonalEnemy(-50, aGen.Next(30, 401), 2, "enemy2", (float)selectedDifficulty));
                    enemies.Add(new HorizontalEnemy((int)screen.X, aGen.Next(0, (int)screen.Y - 50), 2, "enemyh", (float)selectedDifficulty));
                }
                else
                {
                    enemies.Add(new DiagonalEnemy((int)screen.X, aGen.Next(30, 401), 2, "enemy2", (float)selectedDifficulty));
                    enemies.Add(new HorizontalEnemy(-50, aGen.Next(0, (int)screen.Y - 50), 2, "enemyh", (float)selectedDifficulty));
                }

                if (playerOne.Score % 250 == 5)
                {
                    enemies.Add(new Boss(aGen.Next(10, 331), -100, 4, "boss", (float)selectedDifficulty));
                }
            }

            for (int i = 0; i < enemies.Count; i++)
            {
                if (enemies[i].IsBoss)                                     //try
                {                                                          //only works for boss, else will throw NotImplementedException, which will be caught and enemy will update normally
                    enemies[i].Update(ref enemyBullets, playerOne.Centre); //tell enemy to update
                }
                else //enemy is normal      //catch //(NotImplementedException ex)
                {
                    enemies[i].Update();
                }
                //remove the enemy if is is dead or if it is off the screen and it's allowance is up
                if (enemies[i].Health <= 0 || (OffScreen.Check((int)screen.Y, (int)screen.X, enemies[i].BoundingBox) == true && enemies[i].OffScreenAllowance <= 0))
                {
                    if (enemies[i].Health <= 0)
                    {   //if player killed the enemy, then add particle effects
                        Vector2   origin       = new Vector2(enemies[i].Location.X + enemies[i].CollisionMask.Bounds.Center.X, enemies[i].Location.Y + enemies[i].CollisionMask.Bounds.Center.Y);
                        Explosion newExplosion = new Explosion(origin, enemies[i].ExplosionSize, 5, 3, time);
                        particleEffectsList.Add(newExplosion);
                        playerOne.EnemiesKilled++;
                    }
                    enemies.RemoveAt(i);
                    i--;//we dont want to skip anything in the list
                }
            }//end for
        }//end HandleEnemies()
Пример #3
0
        public void Update()
        {
            Random aGen = new Random();

            for (int i = 0; i < particleArray.Length; i++)
            {
                particleArray[i].CurrentPosition += particleArray[i].Direction;

                if (rotateStars == true)
                {
                    float originalRotation = particleArray[i].Rotation;
                    particleArray[i].Rotation = originalRotation + 0.01f;
                }

                //if the particle is off the screen, return it to the top
                if (OffScreen.Check(screenBounds.Height, screenBounds.Width, particleArray[i].CurrentPosition, particleArray[i].Texture.Width, particleArray[i].Texture.Height))
                {
                    particleArray[i].CurrentPosition = new Vector2(aGen.Next(0, screenBounds.Width), 0);
                } //end if
            }     //end for
        }         //end Update()