Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- path = argument[0];
- density = argument[1];
- minLen = argument[2];
- maxLen = argument[3];
- edgeEncourageFactor = argument[4];
- //Enum used for direction
- enum Direction { right = 0, up = 1, down = 2, left = 3 };
- //Plot first point in center
- path_add_point(path, room_width / 2, room_height / 2, 1);
- //Keep track of previously chosen direciton
- prevDir = 0;
- //Iteratively create new points
- for (i = 0; i < density; i++)
- {
- //Randomize the random seed
- randomize();
- //Get random point index to append line to
- chosenPoint = irandom_range(0, path_get_number(path));
- //Make sure its inside screen, if not, skip iteration, subtracting from i
- if (path_get_point_x(path, chosenPoint) < 0 || path_get_point_x(path, chosenPoint) > window_get_width() ||
- path_get_point_y(path, chosenPoint) < 0 || path_get_point_y(path, chosenPoint) > window_get_height())
- {
- i--;
- continue;
- }
- //Get the inverse of prev dir to avoid
- invPrevDir = -1;
- if (prevDir == Direction.right) invPrevDir = Direction.left;
- else if (prevDir == Direction.left) invPrevDir = Direction.right;
- else if (prevDir == Direction.up) invPrevDir = Direction.down;
- else if (prevDir == Direction.down) invPrevDir = Direction.up;
- //Get random direction
- dir = -1;
- while (dir == -1 || dir == prevDir || dir == invPrevDir)
- {
- randomize();
- dir = irandom_range(0, 3);
- }
- prevDir = dir;
- //Get random length
- len = irandom_range(minLen, maxLen);
- //Calc new location
- ptX = path_get_point_x(path, chosenPoint);
- ptY = path_get_point_y(path, chosenPoint);
- if (ptX == 0 || ptY == 0) continue;
- if (dir == Direction.right)
- ptX += len;
- else if (dir == Direction.left)
- ptX -= len;
- else if (dir == Direction.up)
- ptY -= len;
- else if (dir == Direction.down)
- ptY += len;
- //Check the distance from center in normalized screen space
- distX = (ptX - (room_width / 2)) / (room_width / 2);
- distY = (ptY - (room_height / 2)) / (room_height / 2);
- dist = sqrt(sqr(distX) + sqr(distY));
- //Randomly skip over with chances based on the distance (closer = likely skipped)
- if (dist < random_range(0, edgeEncourageFactor)) continue;
- //Add a point at the chosen point to use to split
- path_insert_point(path, chosenPoint, path_get_point_x(path, chosenPoint), path_get_point_y(path, chosenPoint), 1);
- //Add point from other chosen point, in the correct length and direction
- path_insert_point(path, chosenPoint + 1, ptX, ptY, 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement