function timer(){
  infocontext.globalAlpha = 1 ;
  infocontext.fillStyle = 'white';
  infocontext.clearRect(13, 13, 140, 40);

  infocontext.fillStyle = 'yellow';
  infocontext.fillRect(13, 13, 140, 40);
  infocontext.fillStyle = 'black';
  infocontext.font = "16pt sans-serif";

  infocontext.fillText("Time Left:" + timeLeft, 20, 40);
  if(pause == 0){//If game is not paused.

    if(timeLeft>0){//Time running.
        timeLeft = timeLeft - 1;
    }else{//Time's up.
      //Time's up in level 1.
      if(gamelevel == 1){
        gamelevel = 2;
        score1 = score;//save level1 score.
        score = 0; //clear up score.
        //Rebuild the food.
        foodArray = [[50, 300],[10, 450],[150, 400],[250, 450],[350, 300]];
        timeLeft = 10;

        //start level 2.
        produceLevelTwoBug();
        alert('Awesome!\nReady for Level 2?');
        timer();
        return;
      }else{//time's up in level 2.
        gamelevel = 0;
        score2 = score;
        score = 0;
        timeLeft = 10;
        sethighscore(score1, 1);
        sethighscore(score2, 2);
        alert('Game Over!\n' + 'Level 1 Score: ' + score1 + '\nLevel 2 Score: ' + score2);
        //Go back to start page.
        window.location.href = "a2.html";
         return;
      }
      return;
    }
    //Timer keep running.
    setTimeout(function(){requestAnimationFrame(timer);}, 1000);
  }else{
    requestAnimationFrame(timer);
  }
}
/*-------------------------------
  Function to set up the timer.
--------------------------------*/
Function to set up the timer.
Function to set up the timer .
function timer(){
  infocontext.globalAlpha = 1 ;
  infocontext.fillStyle = 'white';
  infocontext.clearRect(13, 13, 140, 40);
  infocontext.fillStyle = 'yellow';
  infocontext.fillRect(13, 13, 140, 40);
  infocontext.fillStyle = 'black';
  infocontext.font = "16pt sans-serif";
  infocontext.fillText("Time Left:" + timeLeft, 20, 40);
  if(pause == 0){
    if(timeLeft>0){
        timeLeft = timeLeft - 1;
    }else{
      if(gamelevel == 1){
        gamelevel = 2;
        score1 = score;
        score = 0; 
        foodArray = [[50, 300],[10, 450],[150, 400],[250, 450],[350, 300]];
        timeLeft = 10;
        produceLevelTwoBug();
        alert('Awesome!\nReady for Level 2?');
        timer();
        return;
      }else{
        gamelevel = 0;
        score2 = score;
        score = 0;
        timeLeft = 10;
        sethighscore(score1, 1);
        sethighscore(score2, 2);
        alert('Game Over!\n' + 'Level 1 Score: ' + score1 + '\nLevel 2 Score: ' + score2);
        window.location.href = "a2.html";
         return;
      }
      return;
    }
    setTimeout(function(){requestAnimationFrame(timer);}, 1000);
  }else{
    requestAnimationFrame(timer);
  }
}
function timer ( ) { infocontext . globalAlpha = 1 ; infocontext . fillStyle = 'white' ; infocontext . clearRect ( 13 , 13 , 140 , 40 ) ; infocontext . fillStyle = 'yellow' ; infocontext . fillRect ( 13 , 13 , 140 , 40 ) ; infocontext . fillStyle = 'black' ; infocontext . font = "16pt sans-serif" ; infocontext . fillText ( "Time Left:" + timeLeft , 20 , 40 ) ; if ( pause == 0 ) { if ( timeLeft > 0 ) { timeLeft = timeLeft - 1 ; } else { if ( gamelevel == 1 ) { gamelevel = 2 ; score1 = score ; score = 0 ; foodArray = [ [ 50 , 300 ] , [ 10 , 450 ] , [ 150 , 400 ] , [ 250 , 450 ] , [ 350 , 300 ] ] ; timeLeft = 10 ; produceLevelTwoBug ( ) ; alert ( 'Awesome!\nReady for Level 2?' ) ; timer ( ) ; return ; } else { gamelevel = 0 ; score2 = score ; score = 0 ; timeLeft = 10 ; sethighscore ( score1 , 1 ) ; sethighscore ( score2 , 2 ) ; alert ( 'Game Over!\n' + 'Level 1 Score: ' + score1 + '\nLevel 2 Score: ' + score2 ) ; window . location . href = "a2.html" ; return ; } return ; } setTimeout ( function ( ) { requestAnimationFrame ( timer ) ; } , 1000 ) ; } else { requestAnimationFrame ( timer ) ; } }
Function to set up the timer.
Function to set up the timer .
//If game is not paused. //Time running. //Time's up. //Time's up in level 1. //save level1 score. //clear up score. //Rebuild the food. //start level 2. //time's up in level 2. //Go back to start page. //Timer keep running.