Advertisement
Guest User

obj_astar_step

a guest
Feb 12th, 2018
848
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. if (keyboard_check_pressed(vk_space))
  2. {
  3. //reset the previous path - make blue nodes white
  4. //and recolour start and end nodes
  5. for (var i=0;i<ds_list_size(pathNodes);++i)
  6. {
  7. var inst = ds_list_find_value(pathNodes,i);
  8. with (inst)
  9. {
  10. image_blend = c_white;
  11. }
  12. }
  13. with (startNode)
  14. {
  15. image_blend = c_green;
  16. }
  17.  
  18. with (endNode)
  19. {
  20. image_blend = c_red;
  21. }
  22.  
  23. ds_list_clear(pathNodes); //clear the list of nodes
  24. //find the path between start and end nodes
  25. //and make the variable true if a path is found, else false
  26. found = scr_findPath(startNode,endNode,pathNodes,maxRange);
  27. //colour all the nodes between the start and end nodes with a blue colour
  28. for (var i=1;i<ds_list_size(pathNodes)-1;++i)
  29. {
  30. var inst = ds_list_find_value(pathNodes,i);
  31. with (inst)
  32. {
  33. image_blend = c_blue;
  34. }
  35. }
  36. }
  37.  
  38. //left click = make selected node a start node
  39. if (mouse_check_button_pressed(mb_left))
  40. {
  41. var inst = instance_nearest(mouse_x,mouse_y,obj_node);
  42.  
  43. with (inst)
  44. {
  45. if (distance_to_point(mouse_x,mouse_y) <= radius)
  46. {
  47. with (obj_astar.startNode)
  48. {
  49. image_blend = c_white;
  50. }
  51.  
  52. obj_astar.startNode = inst;
  53. image_blend = c_green;
  54. }
  55. }
  56. }
  57.  
  58. //left click = make selected node an end node
  59. if (mouse_check_button_pressed(mb_right))
  60. {
  61. var inst = instance_nearest(mouse_x,mouse_y,obj_node);
  62.  
  63. with (inst)
  64. {
  65. if (distance_to_point(mouse_x,mouse_y) <= radius)
  66. {
  67. with (obj_astar.endNode)
  68. {
  69. image_blend = c_white;
  70. }
  71.  
  72. obj_astar.endNode = inst;
  73. image_blend = c_red;
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement