JAVASCRIPT   106

snake.js

Guest on 27th July 2021 08:35:48 AM

  1. //
  2. //<riboso.js>
  3. //
  4. //
  5.  
  6. var LAST_MOD_DATE = "Oct 25"
  7.  
  8.  
  9. var game;
  10.  
  11. var AMINO_COUNT = 30;
  12. var AMINO_SPEED = 0.1;  /* [cell]/[updating_time] */
  13. var SNAKE_SPEED = 0.25;  /* [cell]/[updating_time] */
  14.  
  15. var game;
  16. var player;
  17.  
  18. function Amino(amino_num){
  19.   var obj = this;
  20.   var amino_array = new Array("A","C","D","E","F","G","H","I","K","L","M","N","P","Q","R","S","T","V","W","Y");
  21.   var walk_anim  = new Array(amino_array[amino_num%20]+".png");
  22.   var crash_anim = new Array(amino_array[amino_num%20]+"o.png");
  23.   var rl_anim = new Array(amino_array[amino_num%20]+"rlR.png");
  24.   var ud_anim = new Array(amino_array[amino_num%20]+"udR.png");
  25.   var ul_anim = new Array(amino_array[amino_num%20]+"ulR.png");
  26.   var ur_anim = new Array(amino_array[amino_num%20]+"urR.png");
  27.   var dl_anim = new Array(amino_array[amino_num%20]+"dlR.png");
  28.   var dr_anim = new Array(amino_array[amino_num%20]+"drR.png");
  29.   var u_anim = new Array(amino_array[amino_num%20]+"u_R.png");
  30.   var d_anim = new Array(amino_array[amino_num%20]+"d_R.png");
  31.   var r_anim = new Array(amino_array[amino_num%20]+"r_R.png");
  32.   var l_anim = new Array(amino_array[amino_num%20]+"l_R.png");
  33.   var j_anim = new Array(amino_array[amino_num%20]+"j_R.png");
  34.   /*
  35.   [pipe direction]
  36.     u      u      u      u      u      u    
  37.   l | r  l - r  l + r  l + r  l + r  l + r
  38.     d      d      d      d      d      d  
  39.   [ud]   [rl]   [ur]    [ul]   [dr]   [dl]
  40.  
  41.  */
  42.   obj.sprite = game.createSprite();
  43.   obj.sprite.initAnim(walk_anim);
  44.   obj.sprite.setXY(randFloat(XMAX), randFloat(YMAX));
  45.   obj.vx = randSign()*AMINO_SPEED;
  46.   obj.vy = randSign()*AMINO_SPEED;
  47.   obj.crash = false;
  48.   obj.dir   = "r";  /* direction:"u","d","l","r" */
  49.   obj.chdirnum = 0;
  50.  
  51.   obj.snake_num = -1;
  52.   obj.xprev = Array(game.Nstepoc);
  53.   obj.yprev = Array(game.Nstepoc);
  54.   obj.dprev = Array(game.Nstepoc);
  55.  
  56.   for (var i=0;i<game.Nstepoc;++i){
  57.     obj.xprev[i] = obj.sprite.getX();
  58.     obj.yprev[i] = obj.sprite.getY();
  59.     obj.dprev[i] = 'r';
  60.    }
  61.  
  62.   /*
  63.   >> obj.snake_num <<
  64.      if (snake_num== 0,1,2,..i,..,game.lensnake-1), then this Amino is i-th unit of the snake.
  65.      if (snake_num==-1),then this Amino is not in snake.
  66.    
  67.      The Ribosome corresponds [game.lensnake]-th element of the snake.
  68.  
  69.      The snake is composed of:  [0]-[1]-[2]...-[i]-...[lensnake-1]-[Ribosome]
  70.  
  71.   >> game.snaked_amino_num[] <<
  72.  
  73.     game.snaked_amino_num[i] : amino_number of i-th element of the snake.
  74.  
  75.   >> How to update (x,y) of snaked Amino ? <<
  76.  
  77.    Each snaked_amino has previous (x,y) for the past [game.Nstep_for_one_cell]-steps
  78.    in amino.xprev[] and amino.yprev[].
  79.  
  80.    game.Nstep_for_one_cell is defined as  1.0/SNAKE_SPEED.
  81.  
  82.    ** i-th snaked_amino updates its (x,y),
  83.       as [Nstep_for_one_cell]-before-(x,y) in the (i+1)-th snaked_amino.
  84.  
  85.  */
  86.  
  87.  
  88.  
  89.   obj.sprite.onUpdate=function(){
  90.  
  91.     /** non-snaked state **/
  92.     if (obj.snake_num<0){
  93. //      var x = obj.sprite.getX() + obj.vx;
  94. //      var y = obj.sprite.getY() + obj.vy;
  95. //      if ((x<0)||(x>XMAX)) {obj.vx = -obj.vx;}
  96. //      if ((y<0)||(y>YMAX)) {obj.vy = -obj.vy;}
  97. //      obj.sprite.setXY(x,y);
  98. //      obj.sprite.stepAnim();
  99.       //Hit Checking
  100.  //     if (game.testHitSprite(obj.sprite)){
  101.  //       if (!obj.crash){
  102.  //         obj.sprite.initAnim(crash_anim)
  103.  //         obj.crash = true;
  104.  //       }
  105.  //     }
  106.  //    else{
  107.  //       obj.sprite.initAnim(walk_anim)
  108.  //       obj.crash = false;
  109.  //       }
  110.    }  
  111.    
  112.    /** snaked state **/
  113.    if (obj.snake_num>=0){
  114.  
  115.      /*** [1] Set position ***/
  116.            
  117.       /** (x0,y0)  : position for previous amino */
  118.       /** (x ,y )  : position for current  amino */
  119.  
  120.       if (obj.snake_num<(game.lensnake-1)){
  121.          var post_anum = game.snaked_amino_num[obj.snake_num+1];
  122.          var x = game.amino[post_anum].xprev[game.Nstepoc-1];
  123.          var y = game.amino[post_anum].yprev[game.Nstepoc-1];
  124.       }
  125.  
  126.       if (obj.snake_num==(game.lensnake-1)){
  127.          var x = game.ribosome.xprev[game.Nstepoc-1];
  128.          var y = game.ribosome.yprev[game.Nstepoc-1];
  129.       }
  130.      
  131.       if ((x>=0)&&(x<CELL_XCOUNT)&&(y>=0)&&(y<CELL_YCOUNT)){ obj.sprite.setXY(x,y);}
  132.  
  133.  
  134.      /*** [2] Set previous position (xprev[],yprev[],dprev[]) ***/
  135.      /* xprev[0]:current_pos, [1]:1-step before, [2]:2-step before,.. [Nstepoc-1]: (Nsteppoc-1)-th step before  */
  136.  
  137.       for (var i=(game.Nstepoc-1);i>=1;--i){
  138.        obj.xprev[i] = obj.xprev[i-1];
  139.        obj.yprev[i] = obj.yprev[i-1];
  140.        obj.dprev[i] = obj.dprev[i-1];
  141.       }
  142.  
  143.       obj.xprev[0] = obj.sprite.getX();
  144.       obj.yprev[0] = obj.sprite.getY();
  145.  
  146.       var dx = obj.xprev[0] - obj.xprev[1];
  147.       var dy = obj.yprev[0] - obj.yprev[1];
  148.  
  149.            if ((dx==0.0) && (dy> 0.0)) obj.dir = 'd';
  150.       else if ((dx==0.0) && (dy< 0.0)) obj.dir = 'u';
  151.       else if ((dx> 0.0) && (dy==0.0)) obj.dir = 'r';
  152.       else if ((dx< 0.0) && (dy==0.0)) obj.dir = 'l';
  153.       else if ((dx==0.0) && (dy==0.0)) obj.dir = obj.dprev[1];
  154.    
  155.       obj.dprev[0] = obj.dir;
  156.      
  157.       obj.chdirnum = -1;
  158.       for (var i=0;i<(game.Nstepoc-1);++i){
  159.           if (obj.dprev[i]!=obj.dprev[i+1]){ obj.chdirnum = i; }
  160.       }
  161.  
  162.      /*** [3] Set pipe types of images  ***/
  163.  
  164.   /*
  165.    The snake is composed of:  [0]-[1]-[2]...-[i]-...[lensnake-1]-[Ribosome]
  166.  
  167.   [pipe direction]
  168.     u      u      u      u      u      u    
  169.   l | r  l - r  l + r  l + r  l + r  l + r
  170.     d      d      d      d      d      d  
  171.   [ud]   [rl]   [ur]    [ul]   [dr]   [dl]
  172.  
  173.  */
  174.  
  175.       if (obj.snake_num < (game.lensnake-1)) {
  176.         var dir0 = game.amino[post_anum].dprev[game.Nstepoc-1];
  177.         var dir1 = game.amino[post_anum].dprev[0];
  178.         var chdirnum = game.amino[post_anum].chdirnum;
  179.       }
  180.       else{
  181.         var dir0 = game.ribosome.dprev[game.Nstepoc-1];
  182.         var dir1 = game.ribosome.dprev[0];
  183.         var chdirnum = game.ribosome.chdirnum;
  184.       }
  185.  
  186.      fchdirnum = 1.0*chdirnum/1.0/game.Nstepoc;
  187.      var fthre1 = 0.6;
  188.      var fthre2 = 0.9;
  189.  
  190. /*  [ud]   [rl]   [ur]    [ul]   [dr]   [dl]  */
  191.       var pipemode = 'C';
  192.      
  193.       if (pipemode=='A'){    
  194.         /* 'A'nimation: three images are connected when amino changes its direction */
  195.             if ((dir0=='r') && (dir1=='r')) obj.sprite.initAnim(rl_anim);
  196.        else if ((dir0=='l') && (dir1=='l')) obj.sprite.initAnim(rl_anim);
  197.        else if ((dir0=='u') && (dir1=='u')) obj.sprite.initAnim(ud_anim);
  198.        else if ((dir0=='d') && (dir1=='d')) obj.sprite.initAnim(ud_anim);
  199.        else if ((dir0=='r') && (dir1=='l')) obj.sprite.initAnim(rl_anim);
  200.        else if ((dir0=='l') && (dir1=='r')) obj.sprite.initAnim(rl_anim);
  201.        else if ((dir0=='u') && (dir1=='d')) obj.sprite.initAnim(ud_anim);
  202.        else if ((dir0=='d') && (dir1=='u')) obj.sprite.initAnim(ud_anim);
  203.      
  204.        else if ((dir0=='r') && (dir1=='d')){
  205.               if (fchdirnum<=fthre1){obj.sprite.initAnim(rl_anim);}
  206.          else if (fchdirnum<=fthre2){obj.sprite.initAnim(dl_anim);}
  207.          else                       {obj.sprite.initAnim(d_anim);}
  208.        }
  209.        else if ((dir0=='r') && (dir1=='u')){
  210.               if (fchdirnum<=fthre1){obj.sprite.initAnim(rl_anim);}
  211.          else if (fchdirnum<=fthre2){obj.sprite.initAnim(ul_anim);}
  212.          else                       {obj.sprite.initAnim(u_anim);}
  213.        }
  214.        else if ((dir0=='l') && (dir1=='d')){
  215.               if (fchdirnum<=fthre1){obj.sprite.initAnim(rl_anim);}
  216.          else if (fchdirnum<=fthre2){obj.sprite.initAnim(dr_anim);}
  217.          else                       {obj.sprite.initAnim(d_anim);}
  218.        }
  219.        else if ((dir0=='l') && (dir1=='u')){
  220.               if (fchdirnum<=fthre1){obj.sprite.initAnim(rl_anim);}
  221.          else if (fchdirnum<=fthre2){obj.sprite.initAnim(ur_anim);}
  222.          else                       {obj.sprite.initAnim(u_anim);}
  223.        }
  224.  
  225.        else if ((dir0=='u') && (dir1=='r')){
  226.               if (fchdirnum<=fthre1){obj.sprite.initAnim(ud_anim);}
  227.         else  if (fchdirnum<=fthre2){obj.sprite.initAnim(dr_anim);}
  228.          else                       {obj.sprite.initAnim(r_anim);}
  229.        }
  230.        else if ((dir0=='u') && (dir1=='l')){
  231.               if (fchdirnum<=fthre1){obj.sprite.initAnim(ud_anim);}
  232.          else if (fchdirnum<=fthre2){obj.sprite.initAnim(dl_anim);}
  233.          else                       {obj.sprite.initAnim(l_anim);}
  234.        }
  235.        else if ((dir0=='d') && (dir1=='r')){
  236.               if (fchdirnum<=fthre1){obj.sprite.initAnim(ud_anim);}
  237.          else if (fchdirnum<=fthre2){obj.sprite.initAnim(ur_anim);}
  238.          else                       {obj.sprite.initAnim(r_anim);}
  239.        }
  240.        else if ((dir0=='d') && (dir1=='l')){
  241.               if (fchdirnum<=fthre1){obj.sprite.initAnim(ud_anim);}
  242.          else if (fchdirnum<=fthre2){obj.sprite.initAnim(ul_anim);}
  243.          else                       {obj.sprite.initAnim(l_anim);}
  244.        }
  245.  
  246.        else obj.sprite.initAnim(crash_anim);
  247.       }
  248.      
  249.      if (pipemode=='T'){    
  250.         /* 'T'wo images : using only two type of pipes 'rl' and 'ud' */
  251.             if (obj.dir=='r') obj.sprite.initAnim(rl_anim);
  252.        else if (obj.dir=='l') obj.sprite.initAnim(rl_anim);
  253.        else if (obj.dir=='u') obj.sprite.initAnim(ud_anim);
  254.        else if (obj.dir=='d') obj.sprite.initAnim(ud_anim);
  255.        else obj.sprite.initAnim(crash_anim);
  256.      }
  257.  
  258.       if (pipemode=='C'){    
  259.         /* 'C'utting pipes on changing direction */
  260.             if ((dir0=='r') && (obj.dir=='r') && (dir1=='r')) obj.sprite.initAnim(rl_anim);
  261.        else if ((dir0=='l') && (obj.dir=='l') && (dir1=='l')) obj.sprite.initAnim(rl_anim);
  262.        else if ((dir0=='u') && (obj.dir=='u') && (dir1=='u')) obj.sprite.initAnim(ud_anim);
  263.        else if ((dir0=='d') && (obj.dir=='d') && (dir1=='d')) obj.sprite.initAnim(ud_anim);
  264.      
  265.        else if ((dir0=='r') && (obj.dir=='r') && (dir1=='d')) obj.sprite.initAnim(l_anim);
  266.        else if ((dir0=='r') && (obj.dir=='r') && (dir1=='u')) obj.sprite.initAnim(l_anim);
  267.        else if ((dir0=='l') && (obj.dir=='l') && (dir1=='d')) obj.sprite.initAnim(r_anim);
  268.        else if ((dir0=='l') && (obj.dir=='l') && (dir1=='u')) obj.sprite.initAnim(r_anim);
  269.        else if ((dir0=='d') && (obj.dir=='d') && (dir1=='r')) obj.sprite.initAnim(u_anim);
  270.        else if ((dir0=='d') && (obj.dir=='d') && (dir1=='l')) obj.sprite.initAnim(u_anim);
  271.        else if ((dir0=='u') && (obj.dir=='u') && (dir1=='r')) obj.sprite.initAnim(d_anim);
  272.        else if ((dir0=='u') && (obj.dir=='u') && (dir1=='l')) obj.sprite.initAnim(d_anim);
  273.  
  274.        else if ((dir0=='r') && (obj.dir=='d') && (dir1=='d')) obj.sprite.initAnim(d_anim);
  275.        else if ((dir0=='r') && (obj.dir=='u') && (dir1=='u')) obj.sprite.initAnim(u_anim);
  276.        else if ((dir0=='l') && (obj.dir=='d') && (dir1=='d')) obj.sprite.initAnim(d_anim);
  277.        else if ((dir0=='l') && (obj.dir=='u') && (dir1=='u')) obj.sprite.initAnim(u_anim);
  278.        else if ((dir0=='d') && (obj.dir=='r') && (dir1=='r')) obj.sprite.initAnim(r_anim);
  279.        else if ((dir0=='d') && (obj.dir=='l') && (dir1=='l')) obj.sprite.initAnim(l_anim);
  280.        else if ((dir0=='u') && (obj.dir=='r') && (dir1=='r')) obj.sprite.initAnim(r_anim);
  281.        else if ((dir0=='u') && (obj.dir=='l') && (dir1=='l')) obj.sprite.initAnim(l_anim);
  282.        else if (obj.dir=='r') obj.sprite.initAnim(rl_anim);
  283.        else if (obj.dir=='l') obj.sprite.initAnim(rl_anim);
  284.        else if (obj.dir=='d') obj.sprite.initAnim(ud_anim);
  285.        else if (obj.dir=='u') obj.sprite.initAnim(ud_anim);
  286.        else obj.sprite.initAnim(crash_anim);
  287.       }
  288.  
  289.  
  290.       if (pipemode=='J'){    
  291.             if ((dir0=='r') && (obj.dir=='r') && (dir1=='r')) obj.sprite.initAnim(rl_anim);
  292.        else if ((dir0=='l') && (obj.dir=='l') && (dir1=='l')) obj.sprite.initAnim(rl_anim);
  293.        else if ((dir0=='u') && (obj.dir=='u') && (dir1=='u')) obj.sprite.initAnim(ud_anim);
  294.        else if ((dir0=='d') && (obj.dir=='d') && (dir1=='d')) obj.sprite.initAnim(ud_anim);
  295.        else if ((dir0=='d') && (obj.dir=='d') && (dir1=='r')) obj.sprite.initAnim(u_anim);
  296.        else if ((dir0=='d') && (obj.dir=='d') && (dir1=='l')) obj.sprite.initAnim(u_anim);
  297.        else if ((dir0=='u') && (obj.dir=='u') && (dir1=='r')) obj.sprite.initAnim(d_anim);
  298.        else if ((dir0=='u') && (obj.dir=='u') && (dir1=='l')) obj.sprite.initAnim(d_anim);
  299.        else if ((dir0=='r') && (obj.dir=='r') && (dir1=='d')) obj.sprite.initAnim(l_anim);
  300.        else if ((dir0=='r') && (obj.dir=='r') && (dir1=='u')) obj.sprite.initAnim(l_anim);
  301.        else if ((dir0=='l') && (obj.dir=='l') && (dir1=='d')) obj.sprite.initAnim(r_anim);
  302.        else if ((dir0=='l') && (obj.dir=='l') && (dir1=='u')) obj.sprite.initAnim(r_anim);
  303.        else  obj.sprite.initAnim(j_anim);
  304.       }
  305.  
  306.  
  307.    }  
  308.  
  309.  
  310.   }  
  311.  
  312. }
  313.  
  314.  
  315.  
  316. function Ribosome(){
  317.   var obj = this;
  318.   var ribowalk_anim = new Array("riboRed.png");
  319.   obj.sprite = game.createSprite();
  320.   obj.sprite.initAnim(ribowalk_anim);
  321.   obj.sprite.setXY(randFloat(XMAX), randFloat(YMAX));
  322.   obj.xprev = Array(game.Nstepoc);
  323.   obj.yprev = Array(game.Nstepoc);
  324.   obj.dprev = Array(game.Nstepoc);
  325.  
  326. //  obj.vx = randSign()*AMINO_SPEED;
  327. //  obj.vy = randSign()*AMINO_SPEED;
  328.   obj.vx = 0;
  329.   obj.vy = 0;
  330.   obj.dir = 'r';
  331.   obj.chdirnum = -1;
  332.  
  333.  
  334.   obj.sprite.onUpdate=function(){
  335.     var x = obj.sprite.getX();
  336.     var y = obj.sprite.getY();
  337.  
  338. /*
  339.     if (game.isKey(KEY_LEFT))  x -= 1;
  340.     if (game.isKey(KEY_RIGHT)) x += 1;
  341.     if (game.isKey(KEY_UP))    y -= 1;
  342.     if (game.isKey(KEY_DOWN))  y += 1;
  343.  */  
  344.     if (game.isKey(KEY_LEFT))  {obj.vx = -SNAKE_SPEED; obj.vy = 0.0;}
  345.     if (game.isKey(KEY_RIGHT)) {obj.vx =  SNAKE_SPEED; obj.vy = 0.0;}
  346.     if (game.isKey(KEY_UP))    {obj.vx =  0.0; obj.vy = -SNAKE_SPEED;}
  347.     if (game.isKey(KEY_DOWN))  {obj.vx =  0.0; obj.vy =  SNAKE_SPEED;}
  348.    
  349.     /** [1] Set new position **/
  350.     x = obj.sprite.getX() + obj.vx;
  351.     y = obj.sprite.getY() + obj.vy;
  352.  
  353.     if (x<0)    x = 0;
  354.     if (x>XMAX) x = XMAX;
  355.     if (y<0)    y = 0;
  356.     if (y>YMAX) y = YMAX;
  357.  
  358.     obj.sprite.setXY(x,y);
  359.  
  360.  
  361.  
  362.     for (var i=(game.Nstepoc-1);i>=1;--i){
  363.       obj.xprev[i] = obj.xprev[i-1];
  364.       obj.yprev[i] = obj.yprev[i-1];
  365.       obj.dprev[i] = obj.dprev[i-1];
  366.     }
  367.  
  368.     obj.xprev[0] = obj.sprite.getX();
  369.     obj.yprev[0] = obj.sprite.getY();
  370.  
  371.     var dx = obj.xprev[0] - obj.xprev[1];
  372.     var dy = obj.yprev[0] - obj.yprev[1];
  373.  
  374.          if ((dx==0.0) && (dy> 0.0)) obj.dir = 'd';
  375.     else if ((dx==0.0) && (dy< 0.0)) obj.dir = 'u';
  376.     else if ((dx> 0.0) && (dy==0.0)) obj.dir = 'r';
  377.     else if ((dx< 0.0) && (dy==0.0)) obj.dir = 'l';
  378.     else if ((dx==0.0) && (dy==0.0)) obj.dir = obj.dprev[1];
  379.    
  380.     obj.dprev[0] = obj.dir;
  381.  
  382.     obj.chdirnum = -1;
  383.     for (var i=0;i<(game.Nstepoc-1);++i){
  384.        if (obj.dprev[i]!=obj.dprev[i+1]){ obj.chdirnum = i; }
  385.     }
  386.  
  387.  
  388.     var hit_amino_num = game.testHitNonSnakeAminoNum(obj.sprite);
  389.  
  390.     if (hit_amino_num>=0){
  391.        if (game.amino[hit_amino_num].snake_num<0){
  392.         game.amino[hit_amino_num].snake_num = game.lensnake;
  393.         game.snaked_amino_num[game.lensnake] = hit_amino_num;
  394.         var cur_x = obj.sprite.getX();
  395.         var cur_y = obj.sprite.getY();
  396.         game.amino[hit_amino_num].dir = obj.dir;
  397.         for (var i=0;i<game.Nstepoc;++i){
  398.           game.amino[hit_amino_num].xprev[i] = obj.xprev[i];
  399.           game.amino[hit_amino_num].yprev[i] = obj.yprev[i];
  400.           game.amino[hit_amino_num].dprev[i] = obj.dprev[i];
  401.          }
  402.         game.amino[hit_amino_num].sprite.setXY(cur_x,cur_y);  
  403.  
  404.         for (var i=0;i<game.Nstepoc;++i){
  405.           obj.xprev[i] = cur_x + 0.5*obj.vx * (game.Nstepoc -i);
  406.           obj.yprev[i] = cur_y + 0.5*obj.vy * (game.Nstepoc -i);
  407.           obj.dprev[i] = obj.dir;
  408.         }
  409.         obj.sprite.setXY(obj.xprev[0],obj.yprev[0]);
  410.        // for (var a=0;a<game.lensnake;++a){
  411.        //   var aa = game.snaked_amino_num[a];
  412.        //   for (var i=0;i<(game.Nstepoc-1);++i){
  413.        //     game.amino[aa].xprev[i] = game.amino[aa].xprev[game.Nstepoc-1];
  414.        //     game.amino[aa].yprev[i] = game.amino[aa].yprev[game.Nstepoc-1];
  415.        //     game.amino[aa].dprev[i] = game.amino[aa].dprev[game.Nstepoc-1];
  416.        //  }
  417.        // }
  418.         game.lensnake += 1;
  419.         game.setScore(game.lensnake);
  420.        }
  421.    }
  422.  
  423.     obj.sprite.stepAnim(ribowalk_anim);
  424.   }
  425. }
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433. function main(){
  434.   var i;
  435.   game = new Game();
  436.   game.Nstepoc = Math.floor(1.0/SNAKE_SPEED)-1;  /* Number of steps for moving one cell  */
  437.   game.Nstepoc = Math.floor(1.0/SNAKE_SPEED);  /* Number of steps for moving one cell  */
  438.  
  439.  
  440.  /** Make ribosome and amino molecules **/
  441.   game.ribosome = new Ribosome();
  442.   game.amino    = new Array();
  443.  
  444.   for (i=0;i<AMINO_COUNT;i++){ game.amino[i] = new Amino(randInt(20)); }
  445.  
  446.  /* <CAUTION!!>
  447.  
  448.    sprite number 0 always corresponds to "ribosome".
  449.    For amino acids, [amimo_number]  = [sprite_number] - 1;
  450.                     [sprite_number] = [amino_number]  + 1;
  451.  */
  452.  
  453.  
  454.  /** Let several amino into snaked states **/
  455.   game.lensnake = 0
  456.   //game.setScore(game.lensnake);
  457.   game.setScore(game.sprite.length);
  458.   game.ribosome.sprite.setXY(game.lensnake,YMAX/2);
  459.   game.ribosome.vx = SNAKE_SPEED;
  460.   game.ribosome.vy = 0.0;
  461.  
  462.   game.snaked_amino_num = new Array(AMINO_COUNT);
  463.   for (var i=0;i<AMINO_COUNT;i++){ game.snaked_amino_num[i] = -1;}
  464.  
  465.   //for (var i=0;i<game.lensnake;i++){
  466.   //  game.amino[i].snake_num = i;
  467.   //  game.snaked_amino_num[i] = i;
  468.   //  game.amino[i].sprite.setXY(game.lensnake,YMAX/2);
  469.   //  for (var j=0;j<game.Nstepoc;++j){
  470.   //    game.amino[i].xprev[j] = game.lensnake;
  471.   //    game.amino[i].yprev[j] = YMAX/2;
  472.   //  }
  473.   //}  
  474. }

Raw Paste


Login or Register to edit or fork this paste. It's free.