Exemple #1
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;
         }
     }
 }
Exemple #2
0
        public void Draw(SpriteBatch spriteBatch, ContentManager Content, Player player, int playerNo, Player[] players)
        {
            spriteBatch.Draw(background, new Rectangle(0, 0, levelWidth, levelHeight), backgroundColor);

            foreach (Solid solid in backSolids)
            {
                solid.sprite.Draw(spriteBatch);
            }

            foreach (Drop drop in drops)
            {
                drop.Draw(spriteBatch, Content);
            }

            foreach (Solid solid in solids)
            {
                solid.sprite.Draw(spriteBatch);
            }

            foreach (Vector2 spawner in zombieSpawners)
            {
                spriteBatch.Draw(Content.Load <Texture2D>("ZombieSpawner"), spawner, Color.White);
            }

            if (zombies != null)
            {
                for (int i = 0; i < zombies.Length; i++)
                {
                    Zombie currentZombie = zombies[i];
                    currentZombie.Draw(spriteBatch);
                }
            }

            foreach (Player p in players)
            {
                if (p.isDead)
                {
                    spriteBatch.Draw(Content.Load <Texture2D>("GraveStone"), p.sprite.vector - new Vector2(p.sprite.getTexture().Width / 2, p.sprite.getTexture().Height / 2), Color.White);
                }
                else
                {
                    p.Draw(spriteBatch, Content);
                }
            }

            foreach (Particle particle in bloodParticles)
            {
                particle.Draw(spriteBatch, Content);
            }

            foreach (BasicWeaponBullet bullet in basicWeaponBullets)
            {
                bullet.Draw(spriteBatch);
            }

            foreach (Rocket rocket in rockets)
            {
                rocket.Draw(spriteBatch, Content);
            }

            if (zombies != null)
            {
                for (int i = 0; i < zombies.Length; i++)
                {
                    if (playerNo == 1)
                    {
                        if (CHZ.options.player1CameraRotation)
                        {
                            String  health       = zombies[i].health.ToString();
                            Vector2 healthOrigin = zombies[i].Font.MeasureString(health) / 2;
                            spriteBatch.DrawString(zombies[i].Font, health, CHZ.RotateVector2(new Vector2(zombies[i].sprite.getX(), zombies[i].sprite.getY() + zombies[i].sprite.getTexture().Height / 4 * 3), player.playerRotation, new Vector2(zombies[i].sprite.getX(), zombies[i].sprite.getY())), Color.Black, player.playerRotation, healthOrigin, 1.0f, SpriteEffects.None, 0.5f);
                        }
                        else
                        {
                            String  health       = zombies[i].health.ToString();
                            Vector2 healthOrigin = zombies[i].Font.MeasureString(health) / 2;
                            spriteBatch.DrawString(zombies[i].Font, health, new Vector2(zombies[i].sprite.getX(), zombies[i].sprite.getY() + zombies[i].sprite.getTexture().Height / 4 * 3), Color.Black, 0, healthOrigin, 1.0f, SpriteEffects.None, 0.5f);
                        }
                    }
                    else if (playerNo == 2)
                    {
                        if (CHZ.options.player2CameraRotation)
                        {
                            String  health       = zombies[i].health.ToString();
                            Vector2 healthOrigin = zombies[i].Font.MeasureString(health) / 2;
                            spriteBatch.DrawString(zombies[i].Font, health, CHZ.RotateVector2(new Vector2(zombies[i].sprite.getX(), zombies[i].sprite.getY() + zombies[i].sprite.getTexture().Height / 4 * 3), player.playerRotation, new Vector2(zombies[i].sprite.getX(), zombies[i].sprite.getY())), Color.Black, player.playerRotation, healthOrigin, 1.0f, SpriteEffects.None, 0.5f);
                        }
                        else
                        {
                            String  health       = zombies[i].health.ToString();
                            Vector2 healthOrigin = zombies[i].Font.MeasureString(health) / 2;
                            spriteBatch.DrawString(zombies[i].Font, health, new Vector2(zombies[i].sprite.getX(), zombies[i].sprite.getY() + zombies[i].sprite.getTexture().Height / 4 * 3), Color.Black, 0, healthOrigin, 1.0f, SpriteEffects.None, 0.5f);
                        }
                    }
                }
            }

            foreach (Solid solid in foreSolids)
            {
                solid.sprite.Draw(spriteBatch);
            }
        }
Exemple #3
0
        public void DrawWithoutHealth(SpriteBatch spriteBatch, ContentManager Content, Player[] players)
        {
            spriteBatch.Draw(background, new Rectangle(0, 0, levelWidth, levelHeight), backgroundColor);

            foreach (Solid solid in backSolids)
            {
                solid.sprite.Draw(spriteBatch);
            }

            foreach (Drop drop in drops)
            {
                drop.Draw(spriteBatch, Content);
            }

            foreach (Solid solid in solids)
            {
                solid.sprite.Draw(spriteBatch);
            }

            foreach (Vector2 spawner in zombieSpawners)
            {
                spriteBatch.Draw(Content.Load <Texture2D>("ZombieSpawner"), spawner, Color.White);
            }

            foreach (Player p in players)
            {
                if (p.isDead)
                {
                    spriteBatch.Draw(Content.Load <Texture2D>("GraveStone"), p.sprite.vector - new Vector2(p.sprite.getTexture().Width / 2, p.sprite.getTexture().Height / 2), Color.White);
                }
                else
                {
                    p.Draw(spriteBatch, Content);
                }
            }

            for (int i = 0; i < zombies.Length; i++)
            {
                Zombie currentZombie = zombies[i];
                currentZombie.Draw(spriteBatch);
            }

            foreach (Particle particle in bloodParticles)
            {
                particle.Draw(spriteBatch, Content);
            }

            foreach (BasicWeaponBullet bullet in basicWeaponBullets)
            {
                bullet.Draw(spriteBatch);
            }

            foreach (Rocket rocket in rockets)
            {
                rocket.Draw(spriteBatch, Content);
            }

            foreach (Solid solid in foreSolids)
            {
                solid.sprite.Draw(spriteBatch);
            }
        }