Advertisement
Guest User

Enemy Move test code (not working)

a guest
Aug 8th, 2019
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. update ()
  2.     {
  3.    
  4. /* 
  5.     Phaser.Utils.Array.Each(
  6.             ghostg.getChildren(),
  7.             this.physics.moveToObject,
  8.             this.physics,
  9.             ball, 55); 
  10.     */
  11.  
  12.     Phaser.Utils.Array.Each(
  13.             ghostg.getChildren(),
  14.             ghostGrid,
  15.             this); 
  16.        
  17.         function ghostGrid(g){
  18.             var gtilex=Phaser.Math.FloorTo(g.x/16);
  19.             var gtiley=Phaser.Math.FloorTo(g.y/16);
  20.             entityMap.putTileAt(1, gtilex, gtiley);
  21.         }
  22.        
  23.             Phaser.Utils.Array.Each(
  24.             ghostg.getChildren(),
  25.             ghostMoveCheck,
  26.             this); 
  27.        
  28.         function ghostMoveCheck(g){
  29.             var gcloset;
  30.             var gtileX = [0,0];
  31.             var gtileY = [0,0];
  32.             var pdist = [0,0];
  33.             gtileX[0]=Phaser.Math.FloorTo(g.x/16)-1;
  34.             gtileX[1]=Phaser.Math.FloorTo(g.x/16);
  35.             gtileX[2]=Phaser.Math.FloorTo(g.x/16)+1;
  36.             gtileX[3]=Phaser.Math.FloorTo(g.x/16)+1;
  37.             gtileX[4]=Phaser.Math.FloorTo(g.x/16)+1;
  38.             gtileX[5]=Phaser.Math.FloorTo(g.x/16);
  39.             gtileX[6]=Phaser.Math.FloorTo(g.x/16)-1;
  40.             gtileX[7]=Phaser.Math.FloorTo(g.x/16)-1;
  41.             gtileY[0]=Phaser.Math.FloorTo(g.y/16)-1;
  42.             gtileY[1]=Phaser.Math.FloorTo(g.y/16)-1;
  43.             gtileY[2]=Phaser.Math.FloorTo(g.y/16)-1;
  44.             gtileY[3]=Phaser.Math.FloorTo(g.y/16);
  45.             gtileY[4]=Phaser.Math.FloorTo(g.y/16)+1;
  46.             gtileY[5]=Phaser.Math.FloorTo(g.y/16)+1;
  47.             gtileY[6]=Phaser.Math.FloorTo(g.y/16)+1;
  48.             gtileY[7]=Phaser.Math.FloorTo(g.y/16);
  49.             pdist[0]=Phaser.Math.Distance.Between(g.x-16,g.y-16,ball.x,ball.y);
  50.             pdist[1]=Phaser.Math.Distance.Between(g.x,g.y-16,ball.x,ball.y);
  51.             pdist[2]=Phaser.Math.Distance.Between(g.x+16,g.y-16,ball.x,ball.y);
  52.             pdist[3]=Phaser.Math.Distance.Between(g.x+16,g.y,ball.x,ball.y);
  53.             pdist[4]=Phaser.Math.Distance.Between(g.x+16,g.y+16,ball.x,ball.y);
  54.             pdist[5]=Phaser.Math.Distance.Between(g.x,g.y+16,ball.x,ball.y);
  55.             pdist[6]=Phaser.Math.Distance.Between(g.x-16,g.y+16,ball.x,ball.y);
  56.             pdist[7]=Phaser.Math.Distance.Between(g.x-16,g.y,ball.x,ball.y);
  57.            
  58.            
  59.            
  60.             var closest=Math.min(pdist[0],pdist[1],pdist[2],pdist[3],pdist[4],pdist[5],pdist[6],pdist[7]);
  61.             //console.log(closest);
  62.             var i;
  63.             for (i=0;i<7;i++){
  64.                 if (pdist[i]=closest){
  65.                     gcloset=i;
  66.                 }
  67.  
  68.             }
  69.             console.log(gtileX[gcloset]*16);
  70.            
  71.             if (map.hasTileAt(gtileX[gcloset], gtileY[gcloset],wallsLayer)==false || entityMap.hasTileAt(gtileX[gcloset], gtileY[gcloset])==false){
  72.                 this.physics.moveTo(g,gtileX[gcloset]*16,gtileY[gcloset]*16)
  73.             } else  {
  74.                 pdist[gcloset]=5000;
  75.                 /*var i;
  76.             for (i=0;i<7;i++){
  77.                 if (pdist[i]=closest){
  78.                     gcloset=i;
  79.                 }
  80.             }
  81.             if (map.hasTileAt(gtileX[gcloset], gtileY[gcloset],wallsLayer)==false || entityMap.hasTileAt(gtileX[gcloset], gtileY[gcloset])==false){
  82.                 this.physics.moveTo(g,gtileX[gcloset],gtileY[gcloset])
  83.             } else  {
  84.                 pdist[gcloset]=5000;
  85.                 var i;
  86.             for (i=0;i<7;i++){
  87.                 if (pdist[i]=closest){
  88.                     gcloset=i;
  89.                 }
  90.             }
  91.             if (map.hasTileAt(gtileX[gcloset], gtileY[gcloset],wallsLayer)==false || entityMap.hasTileAt(gtileX[gcloset], gtileY[gcloset])==false){
  92.                 this.physics.moveTo(g,gtileX[gcloset],gtileY[gcloset])
  93.             } else  {
  94.                 pdist[gcloset]=5000;
  95.                 var i;
  96.             for (i=0;i<7;i++){
  97.                 if (pdist[i]=closest){
  98.                     gcloset=i;
  99.                 }
  100.             }
  101.             if (map.hasTileAt(gtileX[gcloset], gtileY[gcloset],wallsLayer)==false || entityMap.hasTileAt(gtileX[gcloset], gtileY[gcloset])==false){
  102.                 this.physics.moveTo(g,gtileX[gcloset],gtileY[gcloset])
  103.             } else  {
  104.                 pdist[gcloset]=5000;
  105.                 var i;
  106.             for (i=0;i<7;i++){
  107.                 if (pdist[i]=closest){
  108.                     gcloset=i;
  109.                 }
  110.             }
  111.             if (map.hasTileAt(gtileX[gcloset], gtileY[gcloset],wallsLayer)==false || entityMap.hasTileAt(gtileX[gcloset], gtileY[gcloset])==false){
  112.                 this.physics.moveTo(g,gtileX[gcloset],gtileY[gcloset])
  113.             } else  {
  114.                 pdist[gcloset]=5000;
  115.                 var i;
  116.             for (i=0;i<7;i++){
  117.                 if (pdist[i]=closest){
  118.                     gcloset=i;
  119.                 }
  120.             }
  121.             if (map.hasTileAt(gtileX[gcloset], gtileY[gcloset],wallsLayer)==false || entityMap.hasTileAt(gtileX[gcloset], gtileY[gcloset])==false){
  122.                 this.physics.moveTo(g,gtileX[gcloset],gtileY[gcloset])
  123.             } else  {
  124.                 pdist[gcloset]=5000;
  125.                 var i;
  126.             for (i=0;i<7;i++){
  127.                 if (pdist[i]=closest){
  128.                     gcloset=i;
  129.                 }
  130.             }
  131.             if (map.hasTileAt(gtileX[gcloset], gtileY[gcloset],wallsLayer)==false || entityMap.hasTileAt(gtileX[gcloset], gtileY[gcloset])==false){
  132.                 this.physics.moveTo(g,gtileX[gcloset],gtileY[gcloset])
  133.             } else  {
  134.             }
  135.             }  
  136.            
  137.     }}}}*/}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement