Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Mazerunner instructions while in "walking" state
  2.  
  3. //Refresh list of valid cells (VOID cells)
  4. mr_get_list(wx, wy);
  5.  
  6. //Check to see if list is empty, if so, go to "backtracking" state
  7. if ds_list_size(list) == 0 {
  8.     state = mazerunner.backtracking;
  9.     exit;
  10. }
  11.  
  12. //Check to see if current direction is a valid direction
  13. var dirCheck = false;
  14. for (i = 0; i < (ds_list_size(list)-1); i++) {
  15.     if (list[| i]) == wdir {
  16.         dirCheck = true;
  17.         ds_list_delete(list, i);
  18.         break;
  19.     }
  20. }
  21.  
  22. //Assign valid direction. If current direction is not valid, pick random
  23. //direction from the list. If current direction is valid, flip a coin to
  24. //see if direction changes anyway
  25. var rpos = irandom(ds_list_size(list)-1);
  26. if dirCheck == true {
  27.     if ds_list_size(list)-1 > 0 {
  28.         if coinflip() {
  29.             wdir = (list[| rpos]);
  30.         }
  31.     }
  32. }
  33. else {
  34.     wdir = (list[| rpos]);
  35. }
  36.  
  37. //Add current grid coordinates to the stack (Y,X to be read as X,Y later)
  38. ds_stack_push(stack, wy, wx);
  39.  
  40. //Remove chosen path from list
  41. ds_list_delete(list, ds_list_find_index(list, wdir));
  42.  
  43. //Mark remaining valid cells in list as WALL cells
  44. for (i = 0; i < (ds_list_size(list)-1); i++) {
  45.     var _x = wx;
  46.     var _y = wy;
  47.     _x += lengthdir_x(1, list[| i]);
  48.     _y += lengthdir_y(1, list[| i]);
  49.     grid[# _x, _y] = WALL;
  50. }
  51.  
  52. //Move the Walker to the selected valid cell
  53. wx += lengthdir_x(1, wdir);
  54. wy += lengthdir_y(1, wdir);
  55.  
  56. //Mark new current cell as a FLOOR cell
  57. grid[# wx, wy] = FLOOR;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement