• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Aug 18th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. /// @param _x1
2. /// @param _y1
3. /// @param _x2
4. /// @param _y2
5. /// @param grid
6. /// @param dist = 0;
7. /// return true/false
8.
9. var _x1 = argument[0], _y1 = argument[1], _x2 = argument[2], _y2 = argument[3], grid = argument[4];
10. var dist = argument_count > 5 ? argument[5] : 0;;
11.
12. if (dist and dist < point_distance(_x1, _y1, _x2, _y2)) {
13.     var dir = point_direction(_x1, _y1, _x2, _y2);
14.     _x2 = _x1 + lengthdir_x(dist, dir);
15.     _y2 = _y1 + lengthdir_y(dist, dir);
16. }
17.
18. var x1 = _x1 div GRID_CELL_WIDTH; // iso_from_normal_x(_x1, _y1);
19. var y1 = _y1 div GRID_CELL_HEIGHT; // iso_from_normal_y(_x1, _y1);
20. var x2 = _x2 div GRID_CELL_WIDTH; // iso_from_normal_x(_x2, _y2);
21. var y2 = _y2 div GRID_CELL_HEIGHT; // iso_from_normal_y(_x2, _y2);
22.
23. // if (floor(x1) == floor(x2) or floor(y1) == floor(y2) or abs(floor(x1) - floor(x2)) == abs(floor(y1) - floor(y2))) {
24. //     return collision_line_grid_2(floor(x1), floor(y1), floor(x2), floor(y2), grid);
25. // }
26.
27. if (grid[# floor(x1), floor(y1)] < 0) {
28.     return true;
29. }
30.
31.
32. if (grid[# floor(x2), floor(y2)] < 0) {
33.     return true;
34. }
35.
36. var k = (y2 - y1) / (x2 - x1);
37. var b = y1 - k * x1;
38.
39. var xs = min(x1, x2);
40. var xe = max(x1, x2);
41. for (var xx = ceil(xs); xx <= floor(xe); xx++) {
42.     if (grid[# floor(xx) - (y2 < y1), floor(k * xx + b)] < 0) {
43.         return true;
44.     }
45. }
46.
47. var ys = min(y1, y2);
48. var ye = max(y1, y2);
49. for (var yy = ceil(ys); yy <= floor(ye); yy++) {
50.     if (grid[# floor((yy - b) / k), floor(yy) - (x2 < x1)] < 0) {
51.         return true;
52.     }
53. }
54.
55. return false;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top