Exemple #1
0
        public void Update(GameTime theGameTime, Player player)
        {
            if (Create > 0)
            {
                this.AddEnemy();
                Create--;
            }

            foreach (Enemy enemy in enemies)
                enemy.Update(theGameTime, player);
        }
 public void HandleItemCollision(Player player, ItemHandler items, SoundHandler sounds)
 {
     playerRectangle = new Rectangle((int)player.X - player.W / 2, (int)player.Y - player.H / 2, player.W, player.H);
     foreach (Item item in items.items)
         if (item.Visible)
         {
             itemRectangle = new Rectangle((int)item.X - item.W / 4, (int)item.Y - item.H / 4, item.W / 2, item.H / 2);
             if (playerRectangle.Intersects(itemRectangle))
             {
                 if(item.Color == Color.Red)
                 {
                     sounds.PlayPickUp(0);
                     player.Score += 5;
                 }
                 else if (item.Color == Color.Green)
                 {
                     sounds.PlayPickUp(1);
                     player.Score += 10;
                     if (item.Type != 0)
                     {
                         player.Boost = true;
                         player.BoostQuantity = item.Type * 10;
                         sounds.PlayBoost();
                     }
                 }
                 else if (item.Color == Color.Blue)
                 {
                     sounds.PlayPickUp(2);
                     player.Score += 15;
                     if (item.Type != 0)
                     {
                         player.Shield = true;
                         player.ShieldTime = item.Type * 5f;
                         sounds.PlayShiled();
                     }
                 }
                 item.Visible = false;
             }
         }
 }
 public void HandleBulletCollisions(Player player, EnemyHandler enemies, SoundHandler sounds)
 {
     playerRectangle = new Rectangle((int)player.X, (int)player.Y, player.W, player.H);
     foreach (Enemy enemy in enemies.enemies)
             foreach (Bullet b in enemy.bullets)
                 if (b.Visible)
                 {
                     bulletRectangle = new Rectangle((int)b.X, (int)b.Y, 3, 3);
                     if (bulletRectangle.Intersects(playerRectangle))
                     {
                         b.Visible = false;
                         sounds.PlayHurt();
                         if (!player.Shield)
                         {
                             player.Hitpoints -= 10;
                         }
                         else
                         {
                             player.ShieldTime /= 2;
                         }
                     }
                 }
 }
Exemple #4
0
        public void Update(GameTime theGameTime, Player player)
        {
            if (reloadTime < initReloadTime)
                reloadTime += (float)theGameTime.ElapsedGameTime.TotalSeconds;
            else
                reloadTime = initReloadTime;

             dx = (player.X - this.X);
             dy = (player.Y - this.Y);
             dist = dx * dx + dy * dy;

            if (reloadTime == initReloadTime && dist <= radius * radius)
                this.UpdateAttack();

            if (bullets.Count > 0)
                foreach (Bullet b in bullets)
                    if (b.Visible)
                        b.Update(theGameTime);

            this.RemoveBullets();
        }
Exemple #5
0
        protected override void Initialize()
        {
            currentLevel = 1;
            levelChanged = true;
            currentState = State.Start;

            player = new Player();
            items = new ItemHandler(this.Content);
            enemies = new EnemyHandler(this.Content);
            collisions = new CollisionHandler();
            sounds = new SoundHandler();

            base.Initialize();
        }