예제 #1
0
 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;
             }
         }
 }
예제 #2
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();
        }