Advertisement
Ulabael

help

Oct 29th, 2022
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. function scr_neighbors(start, grid, CW = CELL_WIDTH, CH = CELL_HEIGHT, getClosed = false, fourSides = false, ignoreClosed = true, ignoreObjects = false, objectToIgnore = [])
  2. {
  3. var cellx, celly, cells;
  4. var neighborsAr = array_create(0, 0)
  5.  
  6. var maxX = ds_grid_width(grid);
  7. if is_array(start) {
  8. cellx = start[0];
  9. celly = start[1];
  10. }
  11. else {
  12. cellx = start mod maxX;
  13. celly = start div maxX;
  14. }
  15.  
  16. if (fourSides) cells = [[cellx-1, celly], [cellx, celly-1], [cellx+1, celly], [cellx, celly+1]]
  17. else cells = [[cellx -1, celly-1], [cellx, celly-1], [cellx+1, celly-1], [cellx-1, celly], [cellx+1, celly], [cellx-1, celly+1], [cellx, celly+1], [cellx+1, celly+1]]
  18.  
  19. for (var i = 0; i < array_length(cells); ++i)
  20. {
  21. if cells[i][0] > -1 and cells[i][0] < room_width div CW
  22. and cells[i][1] > -1 and cells[i][1] < room_height div CH
  23. {
  24. // Если отслеживаем закрытые клетки и текущая клетка НЕ закрыта - игнор
  25. if (getClosed and ds_grid_get(grid, cells[i][0], cells[i][1]) != 0) {
  26. continue
  27. }
  28. if (ignoreClosed and ds_grid_get(grid, cells[i][0], cells[i][1]) == 0) {
  29. continue
  30. }
  31.  
  32. if (ignoreObjects) {
  33. if scr_rect_meeting(cells[i][0] * CW, cells[i][1] * CH,
  34. cells[i][0] * (CW+1)-1, cells[i][1] * (CH+1)-1, objectToIgnore) {
  35. continue
  36. }
  37. }
  38. array_push(neighborsAr, cells[i][0] + cells[i][1] * maxX)
  39. }
  40. }
  41. // Возвращаем список доступных соседей
  42. return neighborsAr
  43. }
  44.  
  45. function scr_rect_meeting(x1, y1, x2, y2, objects = []) {
  46. for (var i = 0; i < array_length(objects); ++i) {
  47. if collision_rectangle(x1, y1, x2, y2, objects[i], false, true) {
  48. return true;
  49. }
  50. }
  51. return false;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement