Ejemplo n.º 1
0
 public bool IfCollide(Rectangle rect)
 {
     if (block0.IfCollide(rect))
     {
         return(true);
     }
     if (block1.IfCollide(rect))
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 2
0
        protected override void Update(GameTime gameTime)
        {
            // 允许游戏退出
            if (ifWin == false)
            {
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                {
                    this.Exit();
                }
            }
            else
            {
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                {
                    SAMusicManager.PlaySoundEffect("Sound/Coin");
                    ifWin = false;
                    bird.Clean();
                }
            }

            while (TouchPanel.IsGestureAvailable)
            {
                GestureSample gesture = TouchPanel.ReadGesture();
                if (gesture.GestureType == GestureType.Tap)
                {
                    Rectangle temp = new Rectangle((int)(gesture.Position.X), (int)(gesture.Position.Y), 1, 1);
                    if (ifWin == false)
                    {
                        if (soundOn.IfCollide(temp))
                        {
                            SAMusicManager.IfPlaySound = !SAMusicManager.IfPlaySound;
                        }
                        else
                        {
                            bird.Fly();
                        }
                    }
                    else
                    {
                        if (buttons[0].Intersects(temp))
                        {
                            SAMusicManager.PlaySoundEffect("Sound/Coin");
                            ifWin = false;
                            bird.Clean();
                        }
                        else if (buttons[1].Intersects(temp))
                        {
                            SAMusicManager.PlaySoundEffect("Sound/Coin");
                            GameData.RateGame();
                            ifWin = false;
                            bird.Clean();
                        }
                    }
                }
            }
            if (ifWin == false)
            {
                bird.Update();
                // TODO: 在此处添加更新逻辑
                foreach (Block b in blocks)
                {
                    b.Update(bird);
                }

                if (bird.IfWin)
                {
                    ifWin = true;
                    SAMusicManager.PlaySoundEffect("Sound/win");
                }
            }

            base.Update(gameTime);
        }