Guest User

Untitled

a guest
Apr 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var positions, size, X, Y;
  2.  
  3. positions[] = 0;
  4. size = 0;
  5.  
  6. for (Y=0; Y<map_height()-1; Y+=1)// Generate a node in all possible floor pixels
  7. {
  8.     for (X=0; X<map_width()-1; X+=1)
  9.     {
  10.         if !position_meeting(X, Y, Obstacle) and position_meeting(X, Y+1, Obstacle)
  11.         {
  12.             positions[size, 0] = X;
  13.             positions[size, 1] = Y;
  14.             size += 1;
  15.         }
  16.     }
  17. }
  18.  
  19. var inRow, i, nodeList, newNode, node;
  20. inRow = 0;
  21. nodeList = ds_list_create();
  22.  
  23. for(i=0; i<size; i+=1)// Get rid of all those that are in a horizontal row, save the edges.
  24. {
  25.     if !inRow// The beginning of a row
  26.     {
  27.         newNode = instance_create(positions[i, 0], positions[i, 1], Node);
  28.         ds_list_add(nodeList, newNode);
  29.         ds_list_add(newNode.network, newNode)
  30.         inRow = 1;
  31.     }
  32.     else if i < size-1
  33.     {
  34.         if positions[i, 0]+1 != positions[i+1, 0] or positions[i, 1] != positions[i+1, 1]// If this is the last node
  35.         {
  36.             newNode = instance_create(positions[i, 0], positions[i, 1], Node);
  37.             ds_list_add(nodeList, newNode);
  38.             ds_list_add(newNode.network, newNode);
  39.            
  40.             // Make a connection between this node and the last one
  41.             node = ds_list_find_value(nodeList, ds_list_size(nodeList)-2)
  42.             ds_list_add(newNode.connections, node)
  43.             ds_list_add(newNode.distance, point_distance(newNode.x, newNode.y, node.x, node.y))
  44.             ds_list_add(newNode.commands, sign(newNode.x-node.x))
  45.             ds_list_add(newNode.network, node)
  46.             ds_list_add(node.connections, newNode)
  47.             ds_list_add(node.distance, point_distance(newNode.x, newNode.y, node.x, node.y))
  48.             ds_list_add(node.commands, sign(node.x-newNode.x))
  49.             ds_list_add(node.network, newNode)
  50.            
  51.             inRow = 0;
  52.         }
  53.     }
  54.     else// The last node in the list
  55.     {
  56.         newNode = instance_create(positions[i, 0], positions[i, 1], Node);
  57.         ds_list_add(nodeList, newNode);
  58.         ds_list_add(newNode.network, newNode);
  59.        
  60.         // Make a connection between this node and the last one
  61.         node = ds_list_find_value(nodeList, ds_list_size(nodeList)-2)
  62.         ds_list_add(newNode.connections, node)
  63.         ds_list_add(newNode.distance, point_distance(newNode.x, newNode.y, node.x, node.y))
  64.         ds_list_add(newNode.commands, sign(newNode.x-node.x))
  65.         ds_list_add(newNode.network, node)
  66.         ds_list_add(node.connections, newNode)
  67.         ds_list_add(node.distance, point_distance(newNode.x, newNode.y, node.x, node.y))
  68.         ds_list_add(node.commands, sign(node.x-newNode.x))
  69.         ds_list_add(node.network, newNode)
  70.        
  71.         inRow = 0;
  72.     }
  73. }
  74.  
  75. for(i=0; i<ds_list_size(nodeList); i+=1)// Get rid of long stairs, save the edges (again). Also get rid of any in a spawnroom
  76. {
  77.     node = ds_list_find_value(nodeList, i)
  78.    
  79.     if collision_circle(node.x, node.y, 5, SpawnRoom, 1, 1)
  80.     {
  81.         with node
  82.         {
  83.             ds_list_delete(nodeList, ds_list_find_index(nodeList, id))
  84.             instance_destroy()
  85.         }
  86.         continue
  87.     }
  88.    
  89.     // Remove one-step stairs
  90.  
  91.     newNode = instance_position(node.x-6, node.y+6, Node)// Top-right to Bottom-left stairs first.
  92.     while newNode
  93.     {
  94.         X = newNode.x
  95.         Y = newNode.y
  96.  
  97.         with newNode
  98.         {
  99.             ds_list_delete(nodeList, ds_list_find_index(nodeList, id))
  100.             instance_destroy()
  101.         }
  102.        
  103.         newNode = instance_position(X-6, Y+6, Node)
  104.  
  105.         if newNode
  106.         {
  107.             if !instance_position(newNode.x-6, newNode.y+6, Node)// If the next node is the last one, spare it
  108.             {
  109.                 connectNode(node, newNode, point_distance(node.x, node.y, newNode.x, newNode.y), sign(newNode.x-node.x))
  110.                 connectNode(newNode, node, point_distance(node.x, node.y, newNode.x, newNode.y), sign(node.x-newNode.x))
  111.                 break;
  112.             }
  113.         }
  114.     }
  115.    
  116.     newNode = instance_position(node.x+6, node.y+6, Node)// Top-left to Bottom-right stairs.
  117.     while newNode
  118.     {
  119.         X = newNode.x;
  120.         Y = newNode.y;
  121.  
  122.         with newNode
  123.         {
  124.             ds_list_delete(nodeList, ds_list_find_index(nodeList, id));
  125.             instance_destroy();
  126.         }
  127.        
  128.         newNode = instance_position(X+6, Y+6, Node);
  129.  
  130.         if newNode
  131.         {
  132.             if !instance_position(newNode.x+6, newNode.y+6, Node)// If the next node is the last one, spare it
  133.             {
  134.                 connectNode(node, newNode, point_distance(node.x, node.y, newNode.x, newNode.y), sign(newNode.x-node.x))
  135.                 connectNode(newNode, node, point_distance(node.x, node.y, newNode.x, newNode.y), sign(node.x-newNode.x))
  136.                 break;
  137.             }
  138.         }
  139.     }
  140.    
  141.    
  142.     // Remove double stairs
  143.    
  144.     newNode = instance_position(node.x-12, node.y+6, Node)// Top-right to Bottom-left stairs first.
  145.     while newNode
  146.     {
  147.         X = newNode.x
  148.         Y = newNode.y
  149.  
  150.         with newNode
  151.         {
  152.             ds_list_delete(nodeList, ds_list_find_index(nodeList, id))
  153.             instance_destroy()
  154.         }
  155.        
  156.         newNode = instance_position(X-12, Y+6, Node)
  157.  
  158.         if newNode
  159.         {
  160.             if !instance_position(newNode.x-12, newNode.y+6, Node)// If the next node is the last one, spare it
  161.             {
  162.                 /*connectNode(node, newNode, point_distance(node.x, node.y, newNode.x, newNode.y), sign(newNode.x-node.x))
  163.                 connectNode(newNode, node, point_distance(node.x, node.y, newNode.x, newNode.y), sign(node.x-newNode.x))*/
  164.                 break;
  165.             }
  166.         }
  167.     }
  168.    
  169.     newNode = instance_position(node.x+12, node.y+6, Node)// Top-left to Bottom-right stairs.
  170.     while newNode
  171.     {
  172.         X = newNode.x;
  173.         Y = newNode.y;
  174.  
  175.         with newNode
  176.         {
  177.             ds_list_delete(nodeList, ds_list_find_index(nodeList, id));
  178.             instance_destroy();
  179.         }
  180.        
  181.         newNode = instance_position(X+12, Y+6, Node);
  182.  
  183.         if newNode
  184.         {
  185.             if !instance_position(newNode.x+12, newNode.y+6, Node)// If the next node is the last one, spare it
  186.             {
  187.                 /*connectNode(node, newNode, point_distance(node.x, node.y, newNode.x, newNode.y), sign(newNode.x-node.x))
  188.                 connectNode(newNode, node, point_distance(node.x, node.y, newNode.x, newNode.y), sign(node.x-newNode.x))*/
  189.                 break;
  190.             }
  191.         }
  192.     }
  193. }
  194.  
  195. for(i=0; i<ds_list_size(nodeList); i+=1)// Remove nodes almost directly underneath another node.
  196. {
  197.     node = ds_list_find_value(nodeList, i);
  198.    
  199.     for(a=i; a<ds_list_size(nodeList); a+=1)
  200.     {
  201.         newNode = ds_list_find_value(nodeList, a)
  202.         if abs(newNode.x-node.x) == 1 and point_distance(newNode.x, newNode.y, node.x, node.y) <= 40
  203.         {
  204.             if collision_line(newNode.x, newNode.y, node.x-sign(node.x-newNode.x), node.y, Obstacle, 1, 1) <= 0
  205.             {
  206.                 with newNode
  207.                 {
  208.                     ds_list_delete(nodeList, ds_list_find_index(nodeList, id));
  209.                     instance_destroy();
  210.                 }
  211.             }
  212.         }
  213.     }
  214. }
  215.  
  216. /*for(i=0; i<ds_list_size(nodeList); i+=1)// Move nodes up, and remove any nodes that can't do that.
  217. {
  218.     node = ds_list_find_value(nodeList, i);
  219.    
  220.     if collision_line(node.x, node.y, node.x, node.y-30, Obstacle, 1, 1) > 0
  221.     {
  222.         with node
  223.         {
  224.             ds_list_delete(nodeList, ds_list_find_index(nodeList, id));
  225.             instance_destroy();
  226.         }
  227.     }
  228.     else
  229.     {
  230.         node.y -= 30
  231.     }
  232. }*/
  233.  
  234. ds_list_destroy(nodeList)
Add Comment
Please, Sign In to add comment