コード例 #1
0
        public static Drop[] DropWeapon(Player.Weapon weapon, Vector2 location, ContentManager Content, Drop[] drops)
        {
            Sprite sprite;

            if (weapon == Player.Weapon.LAZERSWORD)
            {
                sprite = new Sprite(Content.Load <Texture2D>("LazerSwordDrop"), location);
            }
            else if (weapon == Player.Weapon.HAMMER)
            {
                sprite = new Sprite(Content.Load <Texture2D>("HammerDrop"), location);
            }
            else if (weapon == Player.Weapon.ROCKETLAUNCHER)
            {
                sprite = new Sprite(Content.Load <Texture2D>("RocketLauncherDrop"), location);
            }
            else
            {
                sprite = new Sprite(Content.Load <Texture2D>("BasicWeaponDrop"), location);
            }
            Drop drop = new Drop(weapon, sprite, Vector2.Zero, 1000);

            if (drops != null && drops.Length != 0)
            {
                Drop[] newDrops = new Drop[drops.Length + 1];

                for (int i = 0; i < drops.Length; i++)
                {
                    newDrops[i + 1] = drops[i];
                }
                newDrops[0] = drop;
                drops       = newDrops;
                return(drops);
            }
            else
            {
                drops    = new Drop[1];
                drops[0] = drop;
                return(drops);
            }
        }
コード例 #2
0
 public void Update(Player player, ContentManager Content, TimeSpan elapsedTime)
 {
     if (drops.Length != 0)
     {
         bool[] deleteThisDrop  = new bool[drops.Length];
         int    numberOfDeletes = 0;
         for (int i = 0; i < drops.Length; i++)
         {
             if (drops[i].Update(player))
             {
                 numberOfDeletes  += 1;
                 deleteThisDrop[i] = true;
             }
             else
             {
                 deleteThisDrop[i] = false;
             }
         }
         Drop[] newdrops           = new Drop[drops.Length - numberOfDeletes];
         int    currentNoOfDeletes = 0;
         for (int i = 0; i < drops.Length; i++)
         {
             if (!deleteThisDrop[i])
             {
                 newdrops[i - currentNoOfDeletes] = drops[i];
             }
             else
             {
                 currentNoOfDeletes += 1;
             }
         }
         drops = newdrops;
     }
     if (bloodParticles.Length != 0)
     {
         bool[] deleteThisParticle = new bool[bloodParticles.Length];
         int    numberOfDeletes    = 0;
         for (int i = 0; i < bloodParticles.Length; i++)
         {
             if (bloodParticles[i].Update(elapsedTime))
             {
                 numberOfDeletes      += 1;
                 deleteThisParticle[i] = true;
             }
             else
             {
                 deleteThisParticle[i] = false;
             }
         }
         Particle[] newBloodParticles  = new Particle[bloodParticles.Length - numberOfDeletes];
         int        currentNoOfDeletes = 0;
         for (int i = 0; i < bloodParticles.Length; i++)
         {
             if (!deleteThisParticle[i])
             {
                 newBloodParticles[i - currentNoOfDeletes] = bloodParticles[i];
             }
             else
             {
                 currentNoOfDeletes += 1;
             }
         }
         bloodParticles = newBloodParticles;
     }
     if (rockets != null)
     {
         bool[] deleteThisRocket = new bool[rockets.Length];
         int    numberOfDeletes  = 0;
         for (int i = 0; i < rockets.Length; i++)
         {
             if (rockets[i].Update(this, player))
             {
                 numberOfDeletes    += 1;
                 deleteThisRocket[i] = true;
             }
             else
             {
                 deleteThisRocket[i] = false;
             }
         }
         Rocket[] newRockets         = new Rocket[rockets.Length - numberOfDeletes];
         int      currentNoOfDeletes = 0;
         for (int i = 0; i < deleteThisRocket.Length; i++)
         {
             if (!deleteThisRocket[i])
             {
                 newRockets[i - currentNoOfDeletes] = rockets[i];
             }
             else
             {
                 currentNoOfDeletes += 1;
             }
         }
         rockets = newRockets;
     }
     if (basicWeaponBullets != null)
     {
         bool[] deleteThisBullet = new bool[basicWeaponBullets.Length];
         int    numberOfDeletes  = 0;
         for (int i = 0; i < basicWeaponBullets.Length; i++)
         {
             if (basicWeaponBullets[i].Update(this, player))
             {
                 numberOfDeletes    += 1;
                 deleteThisBullet[i] = true;
             }
             else
             {
                 deleteThisBullet[i] = false;
             }
         }
         BasicWeaponBullet[] newBasicWeaponBullets = new BasicWeaponBullet[basicWeaponBullets.Length - numberOfDeletes];
         int currentNoOfDeletes = 0;
         for (int i = 0; i < deleteThisBullet.Length; i++)
         {
             if (!deleteThisBullet[i])
             {
                 newBasicWeaponBullets[i - currentNoOfDeletes] = basicWeaponBullets[i];
             }
             else
             {
                 currentNoOfDeletes += 1;
             }
         }
         basicWeaponBullets = newBasicWeaponBullets;
     }
     if (zombies != null)
     {
         bool[] deleteThisZombie        = new bool[zombies.Length];
         int    amountOfZombiesToDelete = 0;
         bool   zombiesToDelete         = false;
         for (int i = 0; i < zombies.Length; i++)
         {
             if (zombies[i].health < 1)
             {
                 player.score += 90;
             }
             if (zombies[i].health < 1 || zombieOutOfBounds(zombies[i]))
             {
                 Random random    = new Random();
                 int    randomNum = random.Next(0, 7);
                 if (randomNum == 6)
                 {
                     drops = Drop.DropWeapon(Drop.GetRandomWeapon(), zombies[i].sprite.vector, Content, drops);
                 }
                 deleteThisZombie[i]      = true;
                 zombiesToDelete          = true;
                 amountOfZombiesToDelete += 1;
             }
             else
             {
                 deleteThisZombie[i] = false;
                 zombies[i].Update(player, this, i);
             }
         }
         if (zombiesToDelete == true)
         {
             Zombie[] newZombies = new Zombie[zombies.Length - amountOfZombiesToDelete];
             int      amountOfZombiesToIgnore = 0;
             for (int i = 0; i < zombies.Length; i++)
             {
                 if (deleteThisZombie[i])
                 {
                     amountOfZombiesToIgnore += 1;
                 }
                 else
                 {
                     newZombies[i - amountOfZombiesToIgnore] = zombies[i];
                 }
             }
             zombies = newZombies;
         }
     }
     spawnTimer -= 1;
     if (spawnTimer <= 0)
     {
         if (zombies.Length <= maxAmountOfZombies)
         {
             //SPAWN NEW ZOMBIE
             Zombie[] newZombies;
             newZombies = new Zombie[zombies.Length + 1];
             int     randomZombieSpawnerIndex = random.Next(0, zombieSpawners.Length);
             Vector2 randomZombieSpawner      = zombieSpawners[randomZombieSpawnerIndex];
             randomZombieSpawner.X += Content.Load <Texture2D>("Player").Width / 2;
             randomZombieSpawner.Y += Content.Load <Texture2D>("Player").Height / 2;
             Zombie newZombie = new Zombie(new Sprite(Content.Load <Texture2D>("Player"), randomZombieSpawner, Color.Green), 0, Content);
             if (zombieCollidesWithZombies(newZombie) == null)
             {
                 newZombies[0] = newZombie;
                 for (int i = 0; i < zombies.Length; i++)
                 {
                     newZombies[i + 1] = zombies[i];
                 }
                 zombies = newZombies;
             }
             timesSpawned += 1;
         }
         if (zombieSpawnAcceleration)
         {
             int timesSpawnedDivision = timesSpawned / 3 * 2;
             if (timesSpawnedDivision < 1)
             {
                 timesSpawnedDivision = 1;
             }
             spawnTimer = random.Next(300, 600) / timesSpawnedDivision;
         }
         else
         {
             spawnTimer = defaultSpawnTimer;
         }
     }
     if (zombies.Length != 0)
     {
         if (playerCollidesWithZombiesPixel(player) && player.delayUntilHit == 0)
         {
             player.health       -= 7;
             player.delayUntilHit = 30;
         }
     }
 }