Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Mazerunner instructions while in "walking" state
- //Refresh list of valid cells (VOID cells)
- mr_get_list(wx, wy);
- //Check to see if list is empty, if so, go to "backtracking" state
- if ds_list_size(list) == 0 {
- state = mazerunner.backtracking;
- exit;
- }
- //Check to see if current direction is a valid direction
- var dirCheck = false;
- for (i = 0; i < (ds_list_size(list)-1); i++) {
- if (list[| i]) == wdir {
- dirCheck = true;
- ds_list_delete(list, i);
- break;
- }
- }
- //Assign valid direction. If current direction is not valid, pick random
- //direction from the list. If current direction is valid, flip a coin to
- //see if direction changes anyway
- var rpos = irandom(ds_list_size(list)-1);
- if dirCheck == true {
- if ds_list_size(list)-1 > 0 {
- if coinflip() {
- wdir = (list[| rpos]);
- }
- }
- }
- else {
- wdir = (list[| rpos]);
- }
- //Add current grid coordinates to the stack (Y,X to be read as X,Y later)
- ds_stack_push(stack, wy, wx);
- //Remove chosen path from list
- ds_list_delete(list, ds_list_find_index(list, wdir));
- //Mark remaining valid cells in list as WALL cells
- for (i = 0; i < (ds_list_size(list)-1); i++) {
- var _x = wx;
- var _y = wy;
- _x += lengthdir_x(1, list[| i]);
- _y += lengthdir_y(1, list[| i]);
- grid[# _x, _y] = WALL;
- }
- //Move the Walker to the selected valid cell
- wx += lengthdir_x(1, wdir);
- wy += lengthdir_y(1, wdir);
- //Mark new current cell as a FLOOR cell
- grid[# wx, wy] = FLOOR;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement