Advertisement
Guest User

Auto tile script

a guest
Feb 21st, 2014
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. cx = 0; //x for full tile
  2. cy = 6; //y for full tile
  3.  
  4. //Function invoked when the editor wants to know the group of same tiles
  5. function getSameTiles() {
  6.     var ar = new Array();
  7.     //standard 9 tiles block (outer edges + full tile)
  8.     ar.push(new Array(cx + 0, cy + 0));
  9.     ar.push(new Array(cx + 1, cy + 0));
  10.     ar.push(new Array(cx + 2, cy + 0));
  11.     ar.push(new Array(cx + 0, cy + 1));
  12.     ar.push(new Array(cx + 1, cy + 1));
  13.     ar.push(new Array(cx + 2, cy + 1));
  14.     ar.push(new Array(cx + 0, cy + 2));
  15.     ar.push(new Array(cx + 1, cy + 2));
  16.     ar.push(new Array(cx + 2, cy + 2));
  17.  
  18.  
  19.     //standard 4 tiles block (inner corners)
  20.     ar.push(new Array(cx + 3, cy + 1));
  21.     ar.push(new Array(cx + 4, cy + 1));
  22.     ar.push(new Array(cx + 3, cy + 2));
  23.     ar.push(new Array(cx + 4, cy + 2));
  24.    
  25.     return Java.to(ar, "int[][]");
  26. }
  27.  
  28. //Function invoked when the editor wants to request an update using the logic
  29. //Each parameters are booleans and represent:
  30. //up, down, left, right, up-left, up-right, down-left, down-right
  31. //A boolean that is set to true means that the neighbor in that direction is of the same type
  32. function getTile(u, d, l, r, ul, ur, dl, dr) {
  33.     var pos = [cx, cy];
  34.  
  35.     if (!u) {
  36.         if (!l) pos = [cx, cy];
  37.         else if (!r) pos = [cx + 2, cy];
  38.         else pos = [cx + 1, cy + (dl ? 0 : ul ? 2 : 0)];
  39.     } else if (!d) {
  40.         if (!l) pos = [cx, cy + 2];
  41.         else if (!r) pos = [cx + 2, cy + 2];
  42.         else pos = [cx + 1, cy + 2];
  43.     } else if (u) {
  44.         if (!l) pos = [cx, cy + 1];
  45.         else if (!r) pos = [cx + 2, cy + 1];
  46.     }
  47.  
  48.     if (u && d && l && r) {
  49.         if (!ul) pos = [cx + 3, cy + 1];
  50.         else if (!ur) pos = [cx + 4, cy + 1];
  51.         else if (!dl) pos = [cx + 3, cy + 2];
  52.         else if (!dr) pos = [cx + 4, cy + 2];
  53.     }
  54.  
  55.     if (u && d && l && r && ul && ur && dl && dr)
  56.         pos = [cx + 1, cy + 1];
  57.  
  58.  
  59.     return Java.to(pos, "int[]");
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement