function produceLevelOneBug(){
  if(pause ==0 && gamelevel == 1){
     //ind means food's index the food list.
      var startX, startY=0, targerX, targerY, ind;
      startX = (Math.random() * 390 + 10);

      targerX = findCloestFood(startX, startY)[0];
      targerY = findCloestFood(startX, startY)[1];
      ind = findCloestFood(startX, startY)[2];

      //Randomly select which bug to produce.
      if (Math.random() <= 0.3){
        BugtoFood(startX, startY, targerX, targerY, ind, 150, 'black',gamelevel);
      }else if (0.3 < Math.random() <= 0.6) {
        BugtoFood(startX, startY, targerX, targerY, ind, 75, 'red',gamelevel);
      }else{
        BugtoFood(startX, startY, targerX, targerY, ind, 60, 'orange',gamelevel);
      }

      setTimeout(function(){
            requestAnimationFrame(produceLevelOneBug);
      }, (Math.random() * 2000 + 1000));
    }else{
     requestAnimationFrame(produceLevelOneBug);
    }

  }
/*------------------------------------
  Main loop for level 1 game.
  One bug will produced each loop.
--------------------------------------*/
Main loop for level 1 game.
One bug will produced each loop.
Main loop for level 1 game . One bug will produced each loop .
function produceLevelOneBug(){
  if(pause ==0 && gamelevel == 1){
      var startX, startY=0, targerX, targerY, ind;
      startX = (Math.random() * 390 + 10);
      targerX = findCloestFood(startX, startY)[0];
      targerY = findCloestFood(startX, startY)[1];
      ind = findCloestFood(startX, startY)[2];
      if (Math.random() <= 0.3){
        BugtoFood(startX, startY, targerX, targerY, ind, 150, 'black',gamelevel);
      }else if (0.3 < Math.random() <= 0.6) {
        BugtoFood(startX, startY, targerX, targerY, ind, 75, 'red',gamelevel);
      }else{
        BugtoFood(startX, startY, targerX, targerY, ind, 60, 'orange',gamelevel);
      }
      setTimeout(function(){
            requestAnimationFrame(produceLevelOneBug);
      }, (Math.random() * 2000 + 1000));
    }else{
     requestAnimationFrame(produceLevelOneBug);
    }
  }
function produceLevelOneBug ( ) { if ( pause == 0 && gamelevel == 1 ) { var startX , startY = 0 , targerX , targerY , ind ; startX = ( Math . random ( ) * 390 + 10 ) ; targerX = findCloestFood ( startX , startY ) [ 0 ] ; targerY = findCloestFood ( startX , startY ) [ 1 ] ; ind = findCloestFood ( startX , startY ) [ 2 ] ; if ( Math . random ( ) <= 0.3 ) { BugtoFood ( startX , startY , targerX , targerY , ind , 150 , 'black' , gamelevel ) ; } else if ( 0.3 < Math . random ( ) <= 0.6 ) { BugtoFood ( startX , startY , targerX , targerY , ind , 75 , 'red' , gamelevel ) ; } else { BugtoFood ( startX , startY , targerX , targerY , ind , 60 , 'orange' , gamelevel ) ; } setTimeout ( function ( ) { requestAnimationFrame ( produceLevelOneBug ) ; } , ( Math . random ( ) * 2000 + 1000 ) ) ; } else { requestAnimationFrame ( produceLevelOneBug ) ; } }
Main loop for level 1 game.
Main loop for level 1 game .
//ind means food's index the food list. //Randomly select which bug to produce.