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

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

            }
        }
예제 #2
0
파일: Brick.cs 프로젝트: FrankHYB/MarioGame
        //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;
            }
        }