Ejemplo n.º 1
0
 void UpdateY()
 {
     position.Y += currentSpeed;
     if (position.Y + Size.Y > GameData.LEFT_TOP_Y + GameData.BORDER_WIDTH)
     {
         if (index > 0)
         {
             SAMusicManager.PlaySoundEffect("Sound/Collide");
         }
         Clean();
         Fly();
     }
     else
     {
         if (position.Y < GameData.LEFT_TOP_Y)
         {
             position.Y = GameData.LEFT_TOP_Y;
         }
         currentSpeed += GRAVITY;
         if (currentSpeed > MAX_DOWN_SPEED)
         {
             currentSpeed = MAX_DOWN_SPEED;
         }
     }
 }
Ejemplo n.º 2
0
        protected override void LoadContent()
        {
            // 创建新的 SpriteBatch,可将其用于绘制纹理。
            spriteBatch = new SpriteBatch(GraphicsDevice);
            //注册 Global
            SAGlobal.Setup(this, spriteBatch, graphics);
            //注册MusicManager
            SAMusicManager.Setup();
            winSprite  = new SASimpleSprite("Images/win");
            font       = Content.Load <SpriteFont>("Font/ScoreFont");
            background = new SASimpleSprite("Images/background");
            frame      = new SASimpleSprite("Images/frame");
            soundOn    = new SASimpleSprite("Images/tile", new Rectangle(10, 340, 66, 54), new Vector2(390, 720), Color.White);
            soundOff   = new SASimpleSprite("Images/tile", new Rectangle(90, 340, 66, 54), new Vector2(390, 720), Color.White);

            scorePositions    = new Vector2[2];
            scorePositions[0] = new Vector2(292, 62);
            scorePositions[1] = new Vector2(381, 62);
            bird   = new Bird();
            blocks = new List <Block>();
            Block block0 = new Block();

            block0.Reset();
            block0.SetLeft(0);
            Block block1 = new Block();

            block1.Reset();
            block1.SetLeft(333);
            blocks.Add(block0);
            blocks.Add(block1);
            buttons    = new Rectangle[2];
            buttons[0] = new Rectangle(80, 380, 124, 54);
            buttons[1] = new Rectangle(278, 380, 124, 54);
        }
Ejemplo n.º 3
0
 public void Update(Bird bird)
 {
     if (IfCollide(bird.rectangle))
     {
         if (bird.index > 0)
         {
             SAMusicManager.PlaySoundEffect("Sound/Collide");
         }
         bird.Clean();
     }
     MoveLeft(GameData.MOVESPEED);
     if (CanRelease())
     {
         SAMusicManager.PlaySoundEffect("Sound/Coin");
         bird.Add();
         Reset();
     }
 }
Ejemplo n.º 4
0
 public void Fly()
 {
     this.currentSpeed = -JUMP_SPEED;
     SAMusicManager.PlaySoundEffect("Sound/Jump");
 }
Ejemplo n.º 5
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);
        }