Esempio n. 1
0
        public void ItemCollisionTest(SoundEffects sound, HUD hud, IList<IItem> items)
        {
            Rectangle marioRectangle = myMario.GetRectangle();
            Rectangle itemRectangle;
            Rectangle intersectionRectangle;
            Queue<IItem> doomedItems = new Queue<IItem>();
            foreach (IItem item in items)
            {
                itemRectangle = item.GetRectangle();
                intersectionRectangle = Rectangle.Intersect(marioRectangle, itemRectangle);
                if (!intersectionRectangle.IsEmpty)
                {
                    // todo
                    switch (item.GetItemName())
                    {
                        case "Coin":
                            //myMario.Coin();
                            hud.addCoinMario();
                            hud.increaseScoreMario(Constants.coinValue);
                            hud.achievements.CoinGet();
                            break;
                        case "Mushroom":
                            sound.Powerup();
                            myMario.Mushroom();
                            hud.increaseScoreMario(Constants.mushroomValue);
                            hud.achievements.MushroomGet();
                            break;
                        case "Fireflower":
                            sound.Powerup();
                            myMario.Fireflower();
                            hud.increaseScoreMario(Constants.fireflowerValue);
                            hud.achievements.FlowerGet();
                            break;
                        case "Oneup":
                            sound.OneUp();
                            hud.extraLifeMario();
                            hud.increaseScoreMario(Constants.oneUpValue);
                            break;
                        case "Star":
                            sound.Powerup();
                            myMario.Star();
                            hud.increaseScoreMario(Constants.starValue);
                            hud.achievements.StarGet();
                            break;
                        default:
                            // nothing
                            break;
                    }
                    doomedItems.Enqueue(item);

                }
            }
            while (doomedItems.Count() > 0)
            {
                IItem item = doomedItems.Dequeue();
                items.Remove(item);

            }
        }
Esempio n. 2
0
        //this is coupled with a few things it doesn't need to be.
        public void Hit(IList<IItem> items, bool isMario, bool isBig, HUD hud, SoundEffects sound)
        {
            switch (state)
            {
                case BrickState.bstar:
                    sound.Popup();
                    IItem star = new Items.Star(xPosition, yPosition - 16, camera);
                    items.Add(star);
                    state = BrickState.qempty;
                    BrickSprite = new Sprites.HitQBlockSprite();
                    break;

                case BrickState.bcoin:
                    sound.Coin();
                    IItem c;
                    //make the coin noise
                    c = new Items.Coin(xPosition, yPosition - Constants.tileLength, camera);
                    items.Add(c);
                    if (isMario)
                    {
                        hud.increaseScoreMario(Constants.brokenBrickValue);
                        hud.addCoinMario();
                    }
                    else
                    {
                        hud.increaseScoreLuigi(Constants.brokenBrickValue);
                        hud.addCoinLuigi();
                    }
                    state = BrickState.qempty;
                    BrickSprite = new Sprites.HitQBlockSprite();
                    break;

                case BrickState.bempty:
                    if (isBig)
                    {
                        sound.BreakBlock();
                        if (isMario)
                        {
                            hud.increaseScoreMario(Constants.brokenBrickValue);
                        }
                        else
                        {
                            hud.increaseScoreLuigi(Constants.brokenBrickValue);
                        }
                        state = BrickState.destroyed;
                        BrickSprite = null;
                    }
                    break;

                case BrickState.qitem:
                    IItem i;
                    sound.Popup();
                    if (!isBig) {
                        i = new Items.Mushroom(xPosition, yPosition - Constants.tileLength, camera);
                    }

                    else {
                        i = new Items.Fireflower(xPosition, yPosition - Constants.tileLength, camera);
                    }
                    items.Add(i);
                    state = BrickState.qempty;
                    BrickSprite = new Sprites.HitQBlockSprite();
                    break;

                case BrickState.qlife:
                    items.Add(new Items.Oneup(xPosition, yPosition - Constants.tileLength, camera));
                    state = BrickState.qempty;
                    BrickSprite = new Sprites.HitQBlockSprite();
                    break;

                case BrickState.qcoin:
                    sound.Coin();
                    //make the coin noise
                    c = new Items.Coin(xPosition, yPosition - Constants.tileLength, camera);
                    items.Add(c);
                    if (isMario)
                    {
                        hud.increaseScoreMario(Constants.brokenBrickValue);
                        hud.addCoinMario();
                    }
                    else
                    {
                        hud.increaseScoreLuigi(Constants.brokenBrickValue);
                        hud.addCoinLuigi();
                    }
                    state = BrickState.qempty;
                    BrickSprite = new Sprites.HitQBlockSprite();
                    break;
                default:
                    break;
            }
        }