/** * 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; } } }
/** * 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; } } } }
/** * 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); }
/** * 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--; } } }