コード例 #1
0
        public static void Update()
        {
            //Determine whether the player tapped the screen
            var touches = Touch.GetData(0);

            if (Director.Instance.CurrentScene == startScene)
            {
                scoreLabel.Text = "Touch to start";


                if (touches.Count > 0 && !keyPressed)
                {
                    Touch.GetData(0).Clear();
                    Director.Instance.ReplaceScene(gameScene);
                    keyPressed = true;
                }
            }
            else if (Director.Instance.CurrentScene == gameScene)
            {
                //If tapped, inform the bird.
                if (touches.Count > 0)
                {
                    bird.Tapped();
                }

                //Update the bird.
                bird.Update(0.0f);

                if (bird.Alive)
                {
                    //Move the background.
                    background.Update(0.0f);

                    //Update the obstacles.
                    foreach (Obstacle obstacle in obstacles)
                    {
                        obstacle.Update(0.0f);
                    }
                    foreach (Obstacle obstacle in obstacles)
                    {
                        if (obstacle.HasCollidedWith(bird.Sprite))
                        {
                            bird.Alive        = false;
                            bird.Sprite.Color = Colors.Black;
                        }
                        if (obstacle.HasPassed(bird.Sprite))
                        {
                            score++;
                        }
                    }
                    scoreLabel.Text = "" + score;
                }
                if (!bird.Alive)
                {
                    Director.Instance.ReplaceScene(endScene);
                }
            }
            else if (Director.Instance.CurrentScene == endScene)
            {
                scoreLabel.Text = "You dead";
                score           = 0;
                bird.reset();
                bird.Sprite.Color = Colors.White;

                obstacles[0].reset(Director.Instance.GL.Context.GetViewport().Width *0.5f);
                obstacles[1].reset(Director.Instance.GL.Context.GetViewport().Width);

                if (touches.Count > 0 && !keyPressed)
                {
                    Director.Instance.ReplaceScene(startScene);
                    keyPressed = true;
                }
            }
            if (touches.Count == 0 && keyPressed)
            {
                keyPressed = false;
            }
        }