 				{
 					itemsToAnimate.splice(i,1);
 					this.removeChild(itemToTrack);
-				}
+					if(itemToTrack.foodItemType == 1)
+					{
+						gameState = "idle";
+						initQuiz();
+						gamePaused = true;
+					}
+				}
+				
+				/*if(itemToTrack.bounds.intersects(hero.bounds)&& itemToTrack.foodItemType == 1)
+				{
+					itemsToAnimate.splice(i,1);
+					this.removeChild(itemToTrack);
+				} */
+				
+				
 				if(itemToTrack.x < -50)
 				{
 					itemsToAnimate.splice(i,1);

		
		private function onGameTick(event:Event):void
		{
			switch(gameState)
			{
				case "idle":
					//take off
					if(hero.x < stage.stageWidth * 0.5 * 0.5)
					{
						hero.x += ((stage.stageWidth * 0.5 * 0.5 + 10)-hero.x)*0.05;
						hero.y = stage.stageHeight * 0.5;
						
						playerSpeed += (MIN_SPEED - playerSpeed)* 0.05;
						bg.speed = playerSpeed * elapsed;
					}
					else
					{
						gameState = "flying";
					}
					break;
				case "flying":
				
					if(hitObstacle <= 0)
					{
						hero.y -= (hero.y - touchY) * 0.1;
						
						if(-(hero.y - touchY)<150 && -(hero.y - touchY)>-150)
						{
							hero.rotation = deg2rad(-(hero.y -touchY) * 0.2);
						}
						if(hero.y > gameArea.bottom - hero.height * 0.5)
						{
							hero.y = gameArea.bottom - hero.height * 0.5;
							hero.rotation = deg2rad(0);
						}
						if(hero.y < gameArea.top + hero.height * 0.5)
						{
							hero.y = gameArea.top + hero.height * 0.5;
							hero.rotation = deg2rad(0);
						}

					}
					else
					{
						hitObstacle--;
						cameraShake();
					}
					 
					playerSpeed -= (playerSpeed - MIN_SPEED) * 0.01;
					bg.speed = playerSpeed * elapsed;
					scoreDistance += (playerSpeed * elapsed)*0.1;
					
					initObstacle();
					animateObstacles();
					
					createFoodItems();
					animateItems();
					break;
				case "over":
				break;
			}
		}
		

			// Calcualte the time it takes for a frame to pass, in milliseconds.
			elapsed = (timeCurrent - timePrevious) * 0.001; 
		}
		
		private function initQuiz():void
		{
			fontRegular = Fonts.getFont("Regular");
			
			statusT = new TextField(480, 600, "", fontRegular.fontName, fontRegular.fontSize, 0xffffff);
			statusT.x = 0;
			statusT.y = 100;
			statusT.hAlign = HAlign.CENTER;
			statusT.vAlign = VAlign.TOP;
			this.addChild(statusT);
			
			/* quiz button */
			 var yPosition:Number = 300;
	
			prevButton = new Button(GameAssets.getAtlas().getTexture("welcome_playButton"));
			prevButton.x = 30;
			prevButton.y = yPosition;
			//prevButton.addEventListener(Event.TRIGGERED, prevHandler);
			this.addChild(prevButton);
			

            nextButton = new Button(GameAssets.getAtlas().getTexture("welcome_playButton"));
            nextButton.x = prevButton.x + prevButton.width + 40;
            nextButton.y = yPosition;
            //nextButton.addEventListener(Event.TRIGGERED, nextHandler);
            this.addChild(nextButton);

            finishButton = new Button(GameAssets.getAtlas().getTexture("welcome_playButton"));
            finishButton.x = nextButton.x + nextButton.width + 40;
            finishButton.y = yPosition;
            finishButton.addEventListener(Event.TRIGGERED, finishHandler);
            this.addChild(finishButton);
			
			quizQuestions = new Array();
            createQuestions();
			
			addAllQuestions();
            hideAllQuestions();
            firstQuestion();
			
			
		}
		
		private function createQuestions() {
            quizQuestions.push(new QuizQuestion("What color is an orange?",
                                                            0,
                                                            "Orange",
                                                            "Blue",
                                                            "Purple",
                                                            "Brown"));
            quizQuestions.push(new QuizQuestion("What is the shape of planet earth?",
                                                            2,
                                                            "Flat",
                                                            "Cube",
                                                            "Round",
                                                            "Shabby"));
            quizQuestions.push(new QuizQuestion("Who created SpiderMan?",
                                                            1,
                                                            "Jack Kirby",
                                                            "Stan Lee and Steve Ditko",
                                                            "Stan Lee",
                                                            "Steve Ditko",
                                                            "none of the above"));
            quizQuestions.push(new QuizQuestion("Who created Mad?",
                                                            1,
                                                            "Al Feldstein",
                                                            "Harvey Kurtzman",
                                                            "William M. Gaines",
                                                            "Jack Davis",
                                                            "none of the above"));
        }
		
		 private function showMessage(theMessage:String) {
            statusT.text = theMessage;
            statusT.x = 200;
        }
        private function addAllQuestions() {
            for(var i:int = 0; i < quizQuestions.length; i++) {
                this.addChild(quizQuestions[i]);
            }
        }
        private function hideAllQuestions() {
            for(var i:int = 0; i < quizQuestions.length; i++) {
                quizQuestions[i].visible = false;
            }
        }
        private function firstQuestion() {
            currentQuestion = quizQuestions[0];
            currentQuestion.visible = true;
        }
        private function prevHandler(event:Event) {
            showMessage("");
            if(currentIndex > 0) {
                currentQuestion.visible = false;
                currentIndex--;
                currentQuestion = quizQuestions[currentIndex];
                currentQuestion.visible = true;
            } else {
                showMessage("sebelumnya");
            }
        }
        private function nextHandler(event:Event) {
            showMessage("error");
			trace("user: "+currentQuestion.userAnswer)
            if(currentQuestion.userAnswer < 0) {
                showMessage("sesudahnya");
                return;
            }
            if(currentIndex < (quizQuestions.length - 1)) {
                currentQuestion.visible = false;
                currentIndex++;
                currentQuestion = quizQuestions[currentIndex];
                currentQuestion.visible = true;
            } else {
                showMessage("That's all the questions! Click Finish to Score, or Previous to go back");
            }
        }
        private function finishHandler(event:Event) {
            showMessage("");
            var finished:Boolean = true;
            for(var i:int = 0; i < quizQuestions.length; i++) {
                if(quizQuestions[i].userAnswer == 0) {
                    finished = false;
                    break;
                }
            }
			trace(quizQuestions.length)
            if(finished || currentIndex == quizQuestions.length -1) {
                prevButton.visible = false;
                nextButton.visible = false;
                finishButton.visible = false;
                hideAllQuestions();
                computeScore();
            } else {
                showMessage("belum selesai semua");
            }
			
			gamePaused = false;
        }
        private function computeScore() {
            for(var i:int = 0; i < quizQuestions.length; i++) {
                if(quizQuestions[i].userAnswer == quizQuestions[i].correctAnswer) {
                    score++;
                }
            }
            showMessage("You answered " + score + " correct out of " + quizQuestions.length + " questions.");
			//trace("You answered " + score + " correct out of " + quizQuestions.length + " questions.")
        }
		
	}
	
}
