Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var xsnake={};
  2. var xpsnake;
  3. var xptail=[];
  4. var xtail=[];
  5. var xtotal=0;
  6.  
  7. function xsnake_dir(x,y){
  8.     xsnake.xdir=x;
  9.     xsnake.ydir=y;
  10. }
  11.  
  12. function xeat(){
  13.  
  14.     var d= euclideanDistance(xsnake.x,xsnake.y,food.x,food.y);
  15.     if(d < 1){
  16.         xtotal++;
  17.         console.log(xtotal);
  18.         document.getElementById("cscore").innerHTML = "Computer Score = " + xtotal;
  19.         return true;
  20.     }
  21.     else{
  22.         return false;
  23.     }
  24. }
  25.  
  26. function xinit_snake(){
  27.     xsnake.x=100;
  28.     xsnake.y=100;
  29.     xsnake.xdir=1;
  30.     xsnake.ydir=0;
  31.    
  32.     var geometry = new THREE.BoxGeometry(20,20,20);
  33.     var cubeMaterials = [
  34.         new THREE.MeshBasicMaterial({color:0x2c156b, transparent:true, opacity:0.5, side: THREE.DoubleSide}),
  35.         new THREE.MeshBasicMaterial({color:0x2c156b, transparent:true, opacity:0.5, side: THREE.DoubleSide}),
  36.         new THREE.MeshBasicMaterial({color:0x2c156b, transparent:true, opacity:0.5, side: THREE.DoubleSide}),
  37.         new THREE.MeshBasicMaterial({color:0x2c156b, transparent:true, opacity:0.5, side: THREE.DoubleSide}),
  38.         new THREE.MeshBasicMaterial({color:0x4c11ef, transparent:true, opacity:0.5, side: THREE.DoubleSide}),
  39.         new THREE.MeshBasicMaterial({color:0x2c156b, transparent:true, opacity:0.5, side: THREE.DoubleSide}),
  40.     ];
  41.     var material = new THREE.MeshFaceMaterial(cubeMaterials);
  42.     xpsnake = new THREE.Mesh(geometry, material);
  43.     xpsnake.position.set(xsnake.x,xsnake.y,6);
  44.     scene.add( xpsnake);
  45.    
  46.  
  47. }
  48.  
  49.  
  50. function xupdate_snake(){
  51.     for(var i=0;i<xtail.length-1;i++){
  52.         xtail[i]=xtail[i+1];
  53.     }
  54.     if(xtotal>=1){
  55.         temp ={}
  56.         temp.x=xsnake.x;
  57.         temp.y=xsnake.y;
  58.         temp.xdir=xsnake.xdir;
  59.         temp.ydir=xsnake.ydir;
  60.         xtail[xtotal-1]=temp;
  61.     }
  62.     xsnake.x=xsnake.x+xsnake.xdir*20;
  63.     xsnake.y=xsnake.y+xsnake.ydir*20;
  64.  
  65.     for(var i=0;i<xtail.length;i++){
  66.         xptail[i].position.set(xtail[i].x,xtail[i].y,6)
  67.     }
  68.     xpsnake.position.set(xsnake.x,xsnake.y,6);
  69. }
  70.  
  71. function xdeath(){
  72.     for(var i=0;i<xtail.length;i++){
  73.         var d = euclideanDistance(xsnake.x,xsnake.y,xtail[i].x,xtail[i].y);
  74.         if(d<1){
  75.             console.log("I died in xdeath")
  76.             xtotal=0;
  77.             document.getElementById("cscore").innerHTML = "Computer Score = 0";
  78.             while(xtail.length){
  79.                 xtail.pop();
  80.             }
  81.             while(xptail.length){
  82.                 scene.remove(xptail.pop());
  83.             }
  84.         }
  85.     }
  86.    
  87. }
  88. function detect_xsnake_collision_to_snake(){
  89.     for(var i=0;i<python_tail.length;i++){
  90.         var d=euclideanDistance(xsnake.x,xsnake.y,python_tail[i].x,python_tail[i].y);
  91.         if(d<1){
  92.             console.log("I died after collision with other snake")
  93.             xtotal=0;
  94.             while(xtail.length){
  95.                 xtail.pop();
  96.             }
  97.             while(xptail.length){
  98.                 scene.remove(xptail.pop());
  99.             }
  100.  
  101.             xsnake.x=random(-200,200);
  102.             xsnake.y=random(-200,200);;
  103.             xsnake.xdir=1;
  104.             xsnake.ydir=0;
  105.             xpsnake.position.set(xsnake.x,xsnake.y,6)
  106.         }
  107.     }
  108. }
  109. function random_xsnake(){
  110.     var ii=random(0,100);
  111.             if(ii<70)return;
  112.  
  113.             var i=random(0,100);
  114.  
  115.                     if(i>=0&&i<=25) {
  116.                         xsnake_dir(0,1);
  117.                     }
  118.                     else if(i>=26&&i<=50) {
  119.                         xsnake_dir(-1,0);
  120.                     }
  121.                     if(i>=51&&i<=75) {
  122.                         xsnake_dir(0,-1);
  123.                     }
  124.                     if(i>=76&&i<=102) {
  125.                         xsnake_dir(1,0);
  126.                     }
  127.  
  128.     // var xd_ = 0;
  129.     // var yd_ = 0;
  130.  
  131.     // if(food.x - xsnake.x < 0){
  132.     //     xd_ = -1;
  133.     // }else if(food.x - xsnake.x > 0){
  134.     //     xd_ = 1;
  135.     // }
  136.  
  137.     // if(food.y - xsnake.y < 0){
  138.     //     yd_ = -1;
  139.     // }else if(food.y - xsnake.y > 0){
  140.     //     yd_ = 1;
  141.     // }
  142.  
  143.     // if(xsnake.xdir + xd_ == 0){
  144.     //     console.log("x prob")
  145.     //     xsnake_dir(0, 1);
  146.     //     return ;
  147.     // }
  148.     // else if(xsnake.ydir + yd_ == 0){
  149.     //     console.log("yprob")
  150.     //     xsnake_dir(1,0);
  151.     //     return ;
  152.     // }
  153.  
  154.     // if(xd_ == 0 && yd_ == 0){
  155.     //  //   var ii=random(0,100);
  156.     //         // if(ii<70)return;
  157.  
  158.     //         var i=random(0,100);
  159.  
  160.     //                 if(i>=0&&i<=25) {
  161.     //                     xsnake_dir(0,1);
  162.     //                 }
  163.     //                 else if(i>=26&&i<=50) {
  164.     //                     xsnake_dir(-1,0);
  165.     //                 }
  166.     //                 if(i>=51&&i<=75) {
  167.     //                     xsnake_dir(0,-1);
  168.     //                 }
  169.     //                 if(i>=76&&i<=102) {
  170.     //                     xsnake_dir(1,0);
  171.     //                 }
  172.     //                 return;
  173.     // }
  174.        
  175.  
  176.    
  177.  
  178.     // var i = random(0,100);
  179.     // if(i < 50){
  180.     //     xsnake_dir(xd_, 0);
  181.     // }else{
  182.     //     xsnake_dir(0, yd_);
  183.     // }
  184.  
  185. }
  186.  
  187. function xhit_wall(){
  188.     if(xsnake.x>200||xsnake.x<-200||xsnake.y>200||xsnake.y<-200){
  189.         console.log("I collided with wall")
  190.         xtotal=0;
  191.         document.getElementById("cscore").innerHTML = "Computer Score = 0";
  192.         while(xtail.length){
  193.             xtail.pop();
  194.         }
  195.         while(xptail.length){
  196.             scene.remove(xptail.pop());
  197.         }
  198.         xsnake.x=0;
  199.         xsnake.y=0;
  200.         xsnake.xdir=1;
  201.         xsnake.ydir=0;
  202.         xpsnake.position.set(0,0,6);
  203.     }
  204. }
  205.  
  206. var food={};
  207. var pfood;
  208. var time_interval_food=0;
  209.  
  210. function pickLocation(){
  211.     var cols =random(-10,10);
  212.     var rows =random(-10,10);
  213.     cols=Math.floor(cols);
  214.     rows=Math.floor(rows);
  215.     food.x=cols*20;
  216.     food.y=rows*20;
  217. }
  218.  
  219. function init_food(){
  220.     pickLocation();
  221.    
  222.     var geometry = new THREE.BoxGeometry(20,20,10);
  223.     var cubeMaterials = [
  224.         new THREE.MeshBasicMaterial({color:0xa12834, transparent:true, opacity:0.5, side: THREE.DoubleSide}),
  225.         new THREE.MeshBasicMaterial({color:0xa12834, transparent:true, opacity:0.5, side: THREE.DoubleSide}),
  226.         new THREE.MeshBasicMaterial({color:0xa12834, transparent:true, opacity:0.5, side: THREE.DoubleSide}),
  227.         new THREE.MeshBasicMaterial({color:0xa12834, transparent:true, opacity:0.5, side: THREE.DoubleSide}),
  228.         new THREE.MeshBasicMaterial({color:0xfc071f, transparent:true, opacity:0.5, side: THREE.DoubleSide}),
  229.         new THREE.MeshBasicMaterial({color:0xa12834, transparent:true, opacity:0.5, side: THREE.DoubleSide}),
  230.     ];
  231.     var material = new THREE.MeshFaceMaterial(cubeMaterials);
  232.     pfood = new THREE.Mesh( geometry, material );
  233.     pfood.position.set(food.x,food.y,6);
  234.     scene.add( pfood );
  235. }
  236.  
  237. function update_food(){
  238.     time_interval_food=0;
  239.     pickLocation();
  240.     pfood.position.set(food.x,food.y,6);
  241. }
  242.  
  243. function xadd_tail_element(){
  244.     console.log("why am i not here?")
  245.     temp= {}
  246.     temp.x=xsnake.x;
  247.     temp.y=xsnake.y;
  248.     temp.xdir=xsnake.xdir;
  249.     temp.ydir=xsnake.ydir;
  250.     xtail.push(temp);
  251.  
  252.    
  253.     var geometry = new THREE.BoxGeometry(20,20,20);
  254.     var cubeMaterials = [
  255.         new THREE.MeshBasicMaterial({color:0x174d17, transparent:true, opacity:0.5, side: THREE.DoubleSide}),
  256.         new THREE.MeshBasicMaterial({color:0x174d17, transparent:true, opacity:0.5, side: THREE.DoubleSide}),
  257.         new THREE.MeshBasicMaterial({color:0x174d17, transparent:true, opacity:0.5, side: THREE.DoubleSide}),
  258.         new THREE.MeshBasicMaterial({color:0x174d17, transparent:true, opacity:0.5, side: THREE.DoubleSide}),
  259.         new THREE.MeshBasicMaterial({color:0x00ff00, transparent:true, opacity:0.5, side: THREE.DoubleSide}),
  260.         new THREE.MeshBasicMaterial({color:0x174d17, transparent:true, opacity:0.5, side: THREE.DoubleSide}),
  261.     ];
  262.     var material = new THREE.MeshFaceMaterial(cubeMaterials);
  263.     xptail.push(new THREE.Mesh( geometry, material ));
  264.     xptail[xptail.length-1].position.set(xtail[xtail.length-1].x,xtail[xtail.length-1].y,6);
  265.     scene.add(xptail[xptail.length-1]);
  266. }
  267.  
  268. var python = {};
  269. var python_tail = [];
  270. var python_tail_count = 0;
  271. var player_score = 0;
  272.  
  273. function keypressed(){
  274.     document.addEventListener( 'keydown' , function( event ) {
  275.         switch( event.keyCode ){
  276.             case 38:
  277.                 if(python.ydir != 0)
  278.                     break;
  279.                
  280.                 python.xdir = 0;
  281.                 python.ydir = 1;
  282.                 break;
  283.             case 40:
  284.                 if(python.ydir != 0)
  285.                     break;
  286.                
  287.                 python.xdir = 0;
  288.                 python.ydir = -1;
  289.                 break;
  290.             case 37:
  291.                 if(python.xdir != 0)
  292.                     break;
  293.                
  294.                 python.xdir = -1;
  295.                 python.ydir = 0;
  296.                 break;
  297.             case 39:
  298.                 if(python.xdir != 0)
  299.                     break;
  300.                
  301.                 python.xdir = 1;
  302.                 python.ydir = 0;
  303.                 break;
  304.         }
  305.     });
  306. }
  307.  
  308.  
  309. function eat(){
  310.     if( euclideanDistance( python.x , python.y , food.x , food.y ) < 1){
  311.         player_score = player_score + 1;
  312.         document.getElementById("pscore").innerHTML = "Player Score : " + player_score;
  313.         return 1;
  314.     }
  315.     return 0;
  316. }
  317.  
  318. function starting_position(){
  319.     python.x = 0;
  320.     python.y = 0;
  321.     python.xdir = Math.floor((Math.random() * 3) - 1);
  322.     if(python.xdir == 0){
  323.         python.ydir = Math.floor(Math.random() * 2);
  324.         if(python.ydir == 0)
  325.             python.ydir = -1;
  326.         else python.ydir = 1;
  327.     }else{
  328.         python.ydir = 0;
  329.     }
  330.     // console.log(python.xdir + " : " + python.ydir);
  331. }
  332.  
  333. function player_snake_setup(){
  334.  
  335.     starting_position();
  336.     // python.x = 0;
  337.     // python.y = 0;
  338.     // python.xdir = Math.floor((Math.random() * 3) - 1);
  339.     // if(python.xdir == 0){
  340.     //     python.ydir = Math.floor(Math.random() * 2);
  341.     //     if(python.ydir == 0)
  342.     //         python.ydir = -1;
  343.     // }else{
  344.     //     python.ydir = 0;
  345.     // }
  346.     // console.log("Y this kolaveri di?")
  347.        
  348.     var geometry = new THREE.BoxGeometry( 20 , 20 , 20 );
  349.     var cubeMaterials = [
  350.         new THREE.MeshBasicMaterial( {color:0xa8794c, isMeshBasicMaterial: true} ),
  351.         new THREE.MeshBasicMaterial( {color:0xa8794c, isMeshBasicMaterial: true} ),
  352.         new THREE.MeshBasicMaterial( {color:0xa8794c, isMeshBasicMaterial: true} ),
  353.         new THREE.MeshBasicMaterial( {color:0xa8794c, isMeshBasicMaterial: true} ),
  354.         new THREE.MeshBasicMaterial( {color:0x4e032b, isMeshBasicMaterial: true} ),
  355.         new THREE.MeshBasicMaterial( {color:0xa8794c, isMeshBasicMaterial: true} ),
  356.     ];
  357.     var material = new THREE.MeshFaceMaterial( cubeMaterials );
  358.     python.head = new THREE.Mesh( geometry , material );
  359.     python.head.position.set( python.x , python.y , 6 );
  360.     scene.add( python.head );
  361. }
  362.  
  363. function update_snake(){
  364.     for(var i=0;i<python_tail.length-1;i++){
  365.         python_tail[i].x=python_tail[i+1].x;
  366.         python_tail[i].y=python_tail[i+1].y;
  367.         python_tail[i].xdir=python_tail[i+1].xdir;
  368.         python_tail[i].ydir=python_tail[i+1].ydir;
  369.     }
  370.     if(python_tail_count>=1){
  371.         temp ={}
  372.         python_tail[python_tail_count-1].x=python.x;
  373.         python_tail[python_tail_count-1].y=python.y;
  374.         python_tail[python_tail_count-1].xdir=python.xdir;
  375.         python_tail[python_tail_count-1].ydir=python.ydir;
  376.     }
  377.     python.x=python.x+python.xdir*20;
  378.     python.y=python.y+python.ydir*20;
  379.  
  380.     for(var i=0;i<python_tail.length;i++){
  381.         python_tail[i].cube.position.set(python_tail[i].x,python_tail[i].y,6);  
  382.     }
  383.     python.head.position.set(python.x,python.y,6);
  384. }
  385.  
  386. function death(){
  387.     for(var i=0;i<python_tail.length;i++){
  388.         var d = euclideanDistance(python.x,python.y,python_tail[i].x,python_tail[i].y);
  389.         if(d<1){
  390.            
  391.             player_score = 0;
  392.             document.getElementById("pscore").innerHTML = "Player Score : " + player_score;
  393.             python_tail_count=0;
  394.             for(var i=0;i<python_tail.length;i++){
  395.                 scene.remove(python_tail[i].cube);
  396.             }
  397.             while(python_tail.length){
  398.                 python_tail.pop();
  399.             }
  400.         }
  401.     }
  402.  
  403.    
  404. }
  405.  
  406. function detect_snake_collision_to_xsnake(){
  407.     for(var i=0;i<xtail.length;i++){
  408.         var d=euclideanDistance(python.x,python.y,xtail[i].x,xtail[i].y);
  409.         if(d<1){
  410.             player_score = 0;
  411.             document.getElementById("pscore").innerHTML = "Player Score : " + player_score;
  412.             python_tail_count=0;
  413.             for(var i=0;i<python_tail.length;i++){
  414.                 scene.remove(python_tail[i].cube);
  415.             }
  416.             while(python_tail.length){
  417.                 python_tail.pop();
  418.             }
  419.  
  420.             // python.x=random(-200,200);
  421.             // python.y=random(-200,200);;
  422.             // python.xdir=1;
  423.             // python.ydir=0;
  424.             starting_position();
  425.             python.head.position.set(python.x,python.y,6)
  426.            
  427.         }
  428.     }  
  429. }
  430.  
  431. function hit_wall(){
  432.     if(python.x>200||python.x<-200||python.y>200||python.y<-200){
  433.         player_score = 0;
  434.         document.getElementById("pscore").innerHTML = "Player Score : " + player_score;
  435.         python_tail_count=0;
  436.         for(var i=0;i<python_tail.length;i++){
  437.             scene.remove(python_tail[i].cube);
  438.         }
  439.         while(python_tail.length){
  440.             python_tail.pop();
  441.         }
  442.         // python.x=0;
  443.         // python.y=0;
  444.         // python.xdir=1;
  445.         // python.ydir=0;
  446.         starting_position();
  447.         python.head.position.set(0,0,6);
  448.     }
  449. }
  450.  
  451. function add_tail_element(){
  452.     temp= {}
  453.     temp.x=python.x;
  454.     temp.y=python.y;
  455.     temp.xdir=python.xdir;
  456.     temp.ydir=python.ydir;
  457.    
  458.  
  459.    
  460.     var geometry = new THREE.BoxGeometry(20,20,20);
  461.     var cubeMaterials = [
  462.         new THREE.MeshBasicMaterial({color:0x4e032b, isMeshBasicMaterial: true}),
  463.         new THREE.MeshBasicMaterial({color:0x4e032b, isMeshBasicMaterial: true}),
  464.         new THREE.MeshBasicMaterial({color:0x4e032b, isMeshBasicMaterial: true}),
  465.         new THREE.MeshBasicMaterial({color:0x4e032b, isMeshBasicMaterial: true}),
  466.         new THREE.MeshBasicMaterial({color:0xb3aaa2, isMeshBasicMaterial: true}),
  467.         new THREE.MeshBasicMaterial({color:0x4e032b, isMeshBasicMaterial: true}),
  468.     ];
  469.  
  470.     var material = new THREE.MeshFaceMaterial(cubeMaterials);
  471.    
  472.     temp.cube=new THREE.Mesh( geometry, material );
  473.    
  474.     python_tail.push(temp);
  475.    
  476.     python_tail[python_tail.length-1].cube.position.set(python_tail[python_tail.length-1].x,python_tail[python_tail.length-1].y,6);
  477.    
  478.     scene.add(python_tail[python_tail.length-1].cube);
  479. }
  480.  
  481. var scene;
  482. var camera;
  483. var renderer;
  484.  
  485. function random ( a , b ) {
  486.     return Math.random() * ( b - a ) + a;
  487. }
  488.  
  489. function euclideanDistance( p , q , a , b ){
  490.     var x = p - a;
  491.     var y = q - b;
  492.     return Math.sqrt( ( x * x ) + ( y * y ) );
  493. }
  494.  
  495. function detect_head_head_collision(){
  496.     var d=euclideanDistance(xsnake.x,xsnake.y,python.x,python.y);
  497.     if(d<1){
  498.         python_tail_count=0;
  499.         for(var i=0;i<python_tail.length;i++){
  500.             scene.remove(python_tail[i].cube);
  501.         }
  502.             while(python_tail.length){
  503.                 python_tail.pop();
  504.             }
  505.             xtotal=0;
  506.             while(xtail.length){
  507.                 xtail.pop();
  508.             }
  509.             while(xptail.length){
  510.                 scene.remove(xptail.pop());
  511.             }
  512.  
  513.             python.x=random(-200,200);
  514.             python.y=random(-200,200);
  515.             python.xdir=1;
  516.             python.ydir=0;
  517.             python.head.position.set(python.x,python.y,6);
  518.  
  519.             xsnake.x=random(-200,200);
  520.             xsnake.y=random(-200,200);
  521.             xsnake.xdir=1;
  522.             xsnake.ydir=0;
  523.             xpsnake.position.set(xsnake.x,xsnake.y,6)
  524.     }
  525. }
  526.  
  527. function fence(){
  528.         var geometry = new THREE.BoxGeometry( 20 , 420 , 30 );
  529.         var left_bar = [
  530.             new THREE.MeshBasicMaterial( {color:0x03174e} ),
  531.             new THREE.MeshBasicMaterial( {color:0x03174e} ),
  532.             new THREE.MeshBasicMaterial( {color:0x03174e} ),
  533.             new THREE.MeshBasicMaterial( {color:0x03174e} ),
  534.             new THREE.MeshBasicMaterial( {color:0x0144fd} ),
  535.             new THREE.MeshBasicMaterial( {color:0x03174e} ),
  536.         ];
  537.         var material = new THREE.MeshFaceMaterial( left_bar );
  538.         var left = new THREE.Mesh( geometry , material );
  539.         left.position.set( -220 , 0 , 6 );
  540.         scene.add( left );
  541.    
  542.        
  543.         var geometry = new THREE.BoxGeometry( 460 , 20 , 30 );
  544.         var bottom_bar = [
  545.             new THREE.MeshBasicMaterial( {color:0x11255d} ),
  546.             new THREE.MeshBasicMaterial( {color:0x11255d} ),
  547.             new THREE.MeshBasicMaterial( {color:0x11255d} ),
  548.             new THREE.MeshBasicMaterial( {color:0x11255d} ),
  549.             new THREE.MeshBasicMaterial( {color:0x0144fd} ),
  550.             new THREE.MeshBasicMaterial( {color:0x11255d} ),
  551.         ];
  552.         var material = new THREE.MeshFaceMaterial( bottom_bar );
  553.         var bottom = new THREE.Mesh( geometry , material );
  554.         bottom.position.set( 0 , -220 , 6 );
  555.         scene.add( bottom );
  556.  
  557.         var geometry = new THREE.BoxGeometry( 20 , 420 , 30 );
  558.         var right_bar = [
  559.             new THREE.MeshBasicMaterial( {color:0x03174e} ),
  560.             new THREE.MeshBasicMaterial( {color:0x03174e} ),
  561.             new THREE.MeshBasicMaterial( {color:0x03174e} ),
  562.             new THREE.MeshBasicMaterial( {color:0x03174e} ),
  563.             new THREE.MeshBasicMaterial( {color:0x0144fd} ),
  564.             new THREE.MeshBasicMaterial( {color:0x03174e} ),
  565.         ];
  566.         var material = new THREE.MeshFaceMaterial( right_bar );
  567.         var right = new THREE.Mesh( geometry , material );
  568.         right.position.set( 220 , 0 , 6 );
  569.         scene.add( right );
  570.  
  571.         var geometry = new THREE.BoxGeometry( 460 , 20 , 30 );
  572.         var top_bar = [
  573.             new THREE.MeshBasicMaterial( {color:0x11255d} ),
  574.             new THREE.MeshBasicMaterial( {color:0x11255d} ),
  575.             new THREE.MeshBasicMaterial( {color:0x11255d} ),
  576.             new THREE.MeshBasicMaterial( {color:0x11255d} ),
  577.             new THREE.MeshBasicMaterial( {color:0x0144fd} ),
  578.             new THREE.MeshBasicMaterial( {color:0x11255d} ),
  579.         ];
  580.         var material = new THREE.MeshFaceMaterial( top_bar );
  581.         var top = new THREE.Mesh( geometry , material );
  582.         top.position.set(0 , 220 , 6);
  583.         scene.add( top );
  584. }
  585.  
  586. function setup(){
  587.     scene = new THREE.Scene();
  588.  
  589.     var aspect_ratio = window.innerWidth / window.innerHeight;
  590.     camera = new THREE.PerspectiveCamera( 40 , aspect_ratio , 1 , 1000 );
  591.     camera.position.set( 0 , 0 , 700 );
  592.     camera.lookAt( 0 , 0 , 0 );
  593.  
  594.     renderer = new THREE.WebGLRenderer();
  595.     renderer.setSize( window.innerWidth , window.innerHeight );
  596.     document.body.appendChild( renderer.domElement );
  597. }
  598.  
  599. function base(){
  600.     var geometry = new THREE.PlaneGeometry( 410 , 410 );
  601.     var material = new THREE.MeshBasicMaterial( {color: 0x1eacdc , side: THREE.DoubleSide , linewidth: 5 } );  ///change
  602.     var plane = new THREE.Mesh( geometry , material );
  603.     scene.add( plane );
  604. }
  605.  
  606. function main() {
  607.     setup();
  608.     base();
  609.     fence();
  610.     player_snake_setup();
  611.     keypressed();
  612.     xinit_snake();
  613.     init_food();
  614.     renderer.render( scene, camera );
  615.     var animate = function () {
  616.  
  617.     setTimeout( function() {
  618.         requestAnimationFrame( animate );
  619.     }, 4000 / 30 );
  620.         renderer.render( scene, camera );
  621.         if(eat()== 1){
  622.             python_tail_count++;
  623.             time_interval_food=0;
  624.             add_tail_element();
  625.             update_food();
  626.         }
  627.         if(xeat()== true){
  628.             time_interval_food=0;
  629.             xadd_tail_element();
  630.             update_food();
  631.         }
  632.         if(time_interval_food>150){
  633.             time_interval_food=0;
  634.             update_food();
  635.         }
  636.         time_interval_food++;
  637.         update_snake();
  638.         xupdate_snake();
  639.         death();
  640.         xdeath();
  641.         hit_wall();
  642.         xhit_wall();
  643.         random_xsnake();
  644.         detect_head_head_collision();
  645.         detect_xsnake_collision_to_snake();
  646.         detect_snake_collision_to_xsnake();
  647.         // keypressed();
  648.     };
  649.     animate();
  650. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement