コード例 #1
0
    /**
     * Method to create a middle pipe.
     **/
    private void CreateMiddlePipes(float height, float xPosition)
    {
        // Set up Pipe Head
        Transform pipeHeadTop    = Instantiate(GameAssets.GetInstance().pfPipeHead);
        Transform pipeHeadBottom = Instantiate(GameAssets.GetInstance().pfPipeHead);
        float     pipeHeadYPositionTop;
        float     pipeHeadYPositionBottom;

        pipeHeadYPositionTop    = 5 - PIPE_HEAD_HEIGHT * .5f;
        pipeHeadYPositionBottom = -5 + PIPE_HEAD_HEIGHT * .5f;

        pipeHeadTop.position    = new Vector3(xPosition, pipeHeadYPositionTop);
        pipeHeadBottom.position = new Vector3(xPosition, pipeHeadYPositionBottom);

        // Set up Pipe Body
        Transform pipeBody = Instantiate(GameAssets.GetInstance().pfPipeBody);

        pipeBody.position = new Vector3(xPosition, -5f);

        SpriteRenderer pipeBodySpriteRenderer = pipeBody.GetComponent <SpriteRenderer>();

        pipeBodySpriteRenderer.size = new Vector2(PIPE_WIDTH, height);

        BoxCollider2D pipeBodyBoxCollider = pipeBody.GetComponent <BoxCollider2D>();

        pipeBodyBoxCollider.size   = new Vector2(PIPE_WIDTH, height);
        pipeBodyBoxCollider.offset = new Vector2(0f, height * .5f);

        MiddlePipe middlePipe = new MiddlePipe(pipeHeadTop, pipeHeadBottom, pipeBody);

        middlePipeList.Add(middlePipe);
    }
コード例 #2
0
    /**
     * Method to draw the question.
     */
    private void drawQuestion()
    {
        Bird bird = Bird.GetInstance();

        for (int i = 0; i < middlePipeList.Count; i++)
        {
            MiddlePipe middlePipe = middlePipeList[i];

            if (middlePipe.GetXPosition() > 40f && middlePipe.GetXPosition() < 41f && isWaitingQuestion == false)
            {
                isWaitingQuestion = true;
                state             = State.WaitingToStart;
                bird.stopQuestion();
                isWaitingFeedback = false;
                isWaitingReady    = false;
            }

            if (middlePipe.GetXPosition() < -20f && middlePipe.GetXPosition() > -21f && isWaitingFeedback == false)
            {
                isWaitingFeedback = true;
                state             = State.WaitingToStart;
                bird.stopFeedback();
                isWaitingQuestion = false;
                isWaitingAnswer   = false;
            }
        }
    }
コード例 #3
0
 /**
  * Method to update the game.
  */
 private void Update()
 {
     if (state == State.Playing)
     {
         HandlePipeMovement();
         HandlePipeSpawning();
         HandleGround();
         HandleClouds();
         drawQuestion();
         if (isWaitingIndex == false)
         {
             getRandomIndex();
             getQuestion();
             getFeedback();
             getRightAnswer();
             getWrongAnswer();
             randomNumber = Random.Range(0, 2);
             upperAnswer();
             Debug.Log(upperAnswerIsRight());
             Debug.Log(randomNumber);
         }
         for (int i = 0; i < middlePipeList.Count; i++)
         {
             MiddlePipe middlePipe = middlePipeList[i];
             if (middlePipe.GetXPosition() > 0 && middlePipe.GetXPosition() < 0.2 && isWaitingAnswer == false)
             {
                 if (isUpperGap() == true && upperAnswerIsRight() == true)
                 {
                     answer = "Goed";
                 }
                 if (isUpperGap() == true && upperAnswerIsRight() == false)
                 {
                     answer = "Fout";
                 }
                 if (isUpperGap() == false && upperAnswerIsRight() == true)
                 {
                     answer = "Fout";
                 }
                 if (isUpperGap() == false && upperAnswerIsRight() == false)
                 {
                     answer = "Goed";
                 }
                 isWaitingAnswer = true;
             }
             if (middlePipe.GetXPosition() < -25 && middlePipe.GetXPosition() > -26 && isWaitingIndex == true && isWaitingReady == false)
             {
                 feedback.RemoveAt(randomIndex);
                 questions.RemoveAt(randomIndex);
                 rightAnswers.RemoveAt(randomIndex);
                 wrongAnswers.RemoveAt(randomIndex);
                 isWaitingIndex = false;
                 isWaitingReady = true;
             }
         }
     }
 }
コード例 #4
0
 /**
  * Method to check if Bird is going to pass the middlepipe.
  */
 private bool isMiddlePipe()
 {
     for (int i = 0; i < middlePipeList.Count; i++)
     {
         MiddlePipe middlePipe = middlePipeList[i];
         if (middlePipe.GetXPosition() < 5f && middlePipe.GetXPosition() > -5f)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #5
0
    /**
     * Method to move the pipes.
     **/
    private void HandlePipeMovement()
    {
        for (int i = 0; i < pipeList.Count; i++)
        {
            Pipe pipe = pipeList[i];

            bool isToTheRightOfBird = pipe.GetXPosition() > BIRD_X_POSITION;
            pipe.Move();
            if (isToTheRightOfBird && pipe.GetXPosition() <= BIRD_X_POSITION && pipe.IsBottom())
            {
                // Pipe passed Bird
                pipesPassedCount++;
                SoundManager.PlaySound(SoundManager.Sound.Score);
            }

            if (pipe.GetXPosition() < PIPE_DESTROY_X_POSITION)
            {
                // Destroy Pipe
                pipe.DestroySelf();
                pipeList.Remove(pipe);
                i--;
            }
        }

        for (int i = 0; i < middlePipeList.Count; i++)
        {
            MiddlePipe middlePipe = middlePipeList[i];
            middlePipe.Move();

            if (middlePipe.GetXPosition() < PIPE_DESTROY_X_POSITION)
            {
                // Destroy Pipe
                middlePipe.DestroySelf();
                middlePipeList.Remove(middlePipe);
                i--;
            }
        }
    }