public Stage1Screen(PlayerCharacter pc, Stage stage, EnemyList eList, FoodList fList)
 {
     player1 = pc;
     this.stage = stage;
     enemies = eList;
     foods = fList;
     TransitionOnTime = TimeSpan.FromSeconds(1.5);
     TransitionOffTime = TimeSpan.FromSeconds(0.5);
 }
        // Currently implementing basic rectangular collisions. May implement more complex collisions later. Basics first.
        public static void updateCollisions(PlayerCharacter pc, List<Enemy> enemyList, List<Food> foodList, FoodList foods, Rectangle fieldBound)
        {
            // Checks for fireballs hitting enemies.
            foreach (Enemy enemy in enemyList)
            {
                foreach (Bullet bullet in pc.getBullets())
                {
                    Rectangle bulletRect = bullet.getRect();
                    // If the fireball rectangle intersects the enemy rectangle hit the enemy.
                    if(bulletRect.Intersects(enemy.getRect()) &&
                        bullet.inPlay && enemy.alive)
                    {
                        enemy.Hit(pc, foods, foodList);
                        bullet.inPlay = false;
                    }
                }

                foreach (Bullet bullet in enemy.getBullets())
                {
                    Rectangle bulletRect = bullet.getRect();

                    // If an enemy hits the player character while the player is not respawning then you're dead. :(
                    if (bulletRect.Intersects(pc.getRect()) && bullet.inPlay && pc.alive && !pc.respawning)
                    {
                        pc.Hit();
                        bullet.inPlay = false;
                    }
                }

                // Don't run into enemies. You'll die.
                if(enemy.getRect().Intersects(pc.getRect()) && enemy.alive && pc.alive)
                {
                    enemy.Die();
                    pc.Hit();
                    pc.PlayEnemyDeath();
                }
            }

            // Check food collisions.
            foreach (Food food in foodList)
            {
                if (food.getRect().Intersects(pc.getRect()) & (pc.alive | pc.respawning))
                {
                    pc.eatFood(food);
                }
            }
        }
Exemple #3
0
 // If enemy is hit by a bullet as determined in the Collisions class do this.
 public virtual void Hit(PlayerCharacter pc, FoodList foods, List<Food> foodList)
 {
     pc.PlayEnemyHit();
     health--;
     if (health <= 0)
     {
         alive = false;
         pc.PlayEnemyDeath();
         //stop timer
         time.Stop();
         //time.Close();
         enemyTime.Stop();
         enemyTime.Close();
         if (isBoss)
         {
             foodList.Add(foods.getRandomFood(
                 new Vector2(position.X + center.X - 16, position.Y + center.Y),
                 new Vector2(0, 1),
                 .2f));
             foodList.Add(foods.getRandomFood(
                 new Vector2(position.X + center.X - 48, position.Y + center.Y),
                 new Vector2(0, 1),
                 .2f));
         }
         else if(rand.Next(0, 100) < 20)
         {
             foodList.Add(foods.getRandomFood(
                 new Vector2(position.X + center.X - 32, position.Y + center.Y),
                 new Vector2(0, 1),
                 .2f));
         }
         pc.addToScore(this);
         pc.PlayEnemyDeath();
     }
 }
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent()
        {
            if (content == null)
                content = new ContentManager(ScreenManager.Game.Services, "Content");

            gameFont = content.Load<SpriteFont>("gamefont");
            // Create a new SpriteBatch, which can be used to draw textures.
            viewportRect = new Rectangle(0, 0,
              (int)(this.ScreenManager.GraphicsDevice.Viewport.Width * .75f),
              this.ScreenManager.GraphicsDevice.Viewport.Height);
            enemyFieldBound = new Rectangle(
                -(int)(this.ScreenManager.GraphicsDevice.Viewport.Width * .25f),
                -(int)(this.ScreenManager.GraphicsDevice.Viewport.Height * .25f),
                (int)(this.ScreenManager.GraphicsDevice.Viewport.Width * 1.5f),
                (int)(this.ScreenManager.GraphicsDevice.Viewport.Height * 1.5f));

            if (enemies == null) enemies = new EnemyList(content);
            if (foods == null) foods = new FoodList(content);
            if (stage == null) stage = new Stage1(content, this.ScreenManager.GraphicsDevice, enemies);
            if (player1 == null)
            {
                player1 = new PlayerCharacter(
                content.Load<Texture2D>("PC\\player_flying"),
                content.Load<Texture2D>("PC\\player_death"),
                content.Load<Texture2D>("Bullets\\fireball0001"),
                content.Load<Texture2D>("Food\\foodgauge"),
                content.Load<Texture2D>("Food\\foodbar"),
                viewportRect);
                player1.LoadSounds(content);
            }
            healthBarBG = content.Load<Texture2D>("Enemies\\healthBar");
            healthBarFill = content.Load<Texture2D>("Enemies\\healthBarFill");
            UIFont = content.Load<SpriteFont>("UI");

            // A real game would probably have more content than this sample, so
            // it would take longer to load. We simulate that by delaying for a
            // while, giving you a chance to admire the beautiful loading screen.
            Thread.Sleep(1000);
            backgroundMusic = content.Load<SoundEffect>("Sounds\\backgroundmusic");

            instance = backgroundMusic.CreateInstance();
            instance.IsLooped = true;
            instance.Play();

            // once the load has finished, we use ResetElapsedTime to tell the game's
            // timing mechanism that we have just finished a very long frame, and that
            // it should not try to catch up.
            ScreenManager.Game.ResetElapsedTime();
        }
Exemple #5
0
        // Currently implementing basic rectangular collisions. May implement more complex collisions later. Basics first.

        public static void updateCollisions(PlayerCharacter pc, List <Enemy> enemyList, List <Food> foodList, FoodList foods, Rectangle fieldBound)
        {
            // Checks for fireballs hitting enemies.
            foreach (Enemy enemy in enemyList)
            {
                foreach (Bullet bullet in pc.getBullets())
                {
                    Rectangle bulletRect = bullet.getRect();
                    // If the fireball rectangle intersects the enemy rectangle hit the enemy.
                    if (bulletRect.Intersects(enemy.getRect()) &&
                        bullet.inPlay && enemy.alive)
                    {
                        enemy.Hit(pc, foods, foodList);
                        bullet.inPlay = false;
                    }
                }

                foreach (Bullet bullet in enemy.getBullets())
                {
                    Rectangle bulletRect = bullet.getRect();

                    // If an enemy hits the player character while the player is not respawning then you're dead. :(
                    if (bulletRect.Intersects(pc.getRect()) && bullet.inPlay && pc.alive && !pc.respawning)
                    {
                        pc.Hit();
                        bullet.inPlay = false;
                    }
                }

                // Don't run into enemies. You'll die.
                if (enemy.getRect().Intersects(pc.getRect()) && enemy.alive && pc.alive)
                {
                    enemy.Die();
                    pc.Hit();
                    pc.PlayEnemyDeath();
                }
            }

            // Check food collisions.
            foreach (Food food in foodList)
            {
                if (food.getRect().Intersects(pc.getRect()) & (pc.alive | pc.respawning))
                {
                    pc.eatFood(food);
                }
            }
        }