コード例 #1
0
        public void RunGameLoopOnce()
        {
            // Process player actions
            Players.ForEach(player =>
            {
                if (player.IsKilled)
                {
                    if (player.DeathTimer++ < Constants.DeathTimeLimit)
                    {
                        return;
                    }
                    RespawnPlayer(player);
                }

                if (player.ActionType == null)
                {
                    return;
                }
                player.ActionType.Process(player, this);
                player.ActionType = null;
            });

            // Process all Actors
            ActorList.ForEach(actor => actor.Process(this));

            // Move bullets forward by one
            BulletList.ForEach(bullet => bullet.Process(this));

            // Remove dead shots
            List <Bullet> deadBullets = BulletList.Where(x => x.Collided == true).ToList();

            deadBullets.ForEach(x => BulletList.Remove(x));
        }
コード例 #2
0
        /// <summary>
        /// Manages all the bullets and their collisions on screen as well as remove them from their list if they are inActive
        /// Does NOT move the bullets since that needs to be frame dependent and this can be on a different thread
        /// </summary>
        private void BulletManage()
        {
            //Manage enemy bullets
            if (BulletList.Count > 0)
            {
                int count = BulletList.Count;
                for (int i = 0; i < count; i++)
                {
                    Bullet currB = BulletList[i];
                    currB.CheckCollision(P1);

                    //Take the bullet out of the list if the collision check caused it to be inactive
                    if (!currB.IsActive)
                    {
                        BulletList.Remove(currB);
                    }

                    count = BulletList.Count;
                }
            }

            //Manage player bullets
            if (PlayerBulletList.Count > 0)
            {
                int count = PlayerBulletList.Count;
                for (int i = 0; i < count; i++)
                {
                    PlayerBullet currPB = PlayerBulletList[i];
                    currPB.CheckCollision(EnemyList);

                    //Take the bullet out of the list if the collision check caused it to be inactive
                    if (!currPB.IsActive)
                    {
                        PlayerBulletList.Remove(currPB);
                    }

                    //Updates the for loop boundary since a bullet could be added before it finishes
                    count = PlayerBulletList.Count;
                }
            }
        }
コード例 #3
0
        public override void Update(GameTime gameTime)
        {
            foreach (BulletClass bullet in bulletList)                         //removing the bullet from the bulletlist once it travels far enough that player can't see it
            {
                bool breakOut = false;                                         //is the bullet to be removed from the list?

                foreach (Walls wall in wallList)                               //check for each existing wall
                {
                    if (bullet.BoundingBox.Intersects(wall.BoundingBox))       //if intersects
                    {
                        if (bullet.BulletFromWhatWeapon == WEAPONTYPE.GRENADE) //if the bullet fired is a grenade, it will expode and do damage regardless
                        {
                            explodeGrenade  = true;
                            grenadePosition = bullet.Position;
                            BulletList.Remove(bullet);
                            breakOut = true;
                            break;
                        }
                        else if (!wall.IsDestroyable) //if the wall isn't destoryable, remove bullet
                        {
                            MediaPlayer.Play(sfxBulletImpactConcrete);
                            bulletList.Remove(bullet); //remove this bullet
                            breakOut = true;           //set break out of foreach loop
                            break;                     //break out of this first loop
                        }
                        else if (wall.IsDestroyable && wall.WallHealth > 0)
                        {
                            MediaPlayer.Play(sfxBulletImpactWood);
                            wall.WallHealth     -= bullet.BulletWallDmg;
                            bullet.BulletDmg     = (int)(bullet.BulletDmg * 0.75f);
                            bullet.BulletWallDmg = (int)(bullet.BulletWallDmg * 0.5f);
                        }
                    }
                }

                if (breakOut) //if breakout of foreach bullet loop is true
                {
                    break;    //break
                }
                else
                {
                    bullet.Position += bullet.Increment; //if not, increment the bullet
                }

                if ((bullet.Position.X > 100 || bullet.Position.Z > 100) || (bullet.Position.X < -100 || bullet.Position.Z < -100)) //if the bullet is too far outside of player view
                {
                    bulletList.Remove(bullet);                                                                                      //remove bullet
                    break;                                                                                                          //break out of list so it doesn't error out
                }

                Vector3 bbMin = bullet.BoundingBox.Min + bullet.Increment; //incrementing the bullet bounding box
                Vector3 bbMax = bullet.BoundingBox.Max + bullet.Increment;
                bullet.BoundingBox = new BoundingBox(bbMin, bbMax);
            }

            //if grenade is exploding, this happens when grenade impacts the wall
            if (explodeGrenade)
            {
                sfxGrenadeExplosion.Play();
                sfxGrenadeTinnitus.Play();

                //the bounding boxes for deciding how much damage to apply
                BoundingBox grenadeRadiusHalfDMG = new BoundingBox(bbMinHalf + grenadePosition, bbMaxHalf + grenadePosition);
                BoundingBox grenadeRadiusFullDMG = new BoundingBox(bbMinFull + grenadePosition, bbMaxFull + grenadePosition);
                BoundingBox playerHalfDMG        = new BoundingBox(bbPMinHalf + grenadePosition, bbPMaxHalf + grenadePosition);
                BoundingBox playerFullDMG        = new BoundingBox(bbPMinFull + grenadePosition, bbPMaxFull + grenadePosition);

                foreach (Walls wall in wallList) //see if walls are destoryable
                {
                    if (wall.IsDestroyable && wall.BoundingBox.Intersects(grenadeRadiusFullDMG))
                    {
                        wall.WallHealth -= 200; //magic numbers for wall damage
                    }
                    else if (wall.IsDestroyable && wall.BoundingBox.Intersects(grenadeRadiusHalfDMG))
                    {
                        wall.WallHealth -= 70;
                    }
                }

                //for player damage, uses difference bounding boxes for max and half damage
                if (playerFullDMG.Intersects(playerBoundingBox))
                {
                    playerHealth -= 50;
                }
                else if (playerHalfDMG.Intersects(playerBoundingBox))
                {
                    playerHealth -= 25;
                }

                explodeGrenade = false;
            }

            base.Update(gameTime);
        }