Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function scr_neighbors(start, grid, CW = CELL_WIDTH, CH = CELL_HEIGHT, getClosed = false, fourSides = false, ignoreClosed = true, ignoreObjects = false, objectToIgnore = [])
- {
- var cellx, celly, cells;
- var neighborsAr = array_create(0, 0)
- var maxX = ds_grid_width(grid);
- if is_array(start) {
- cellx = start[0];
- celly = start[1];
- }
- else {
- cellx = start mod maxX;
- celly = start div maxX;
- }
- if (fourSides) cells = [[cellx-1, celly], [cellx, celly-1], [cellx+1, celly], [cellx, celly+1]]
- 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]]
- for (var i = 0; i < array_length(cells); ++i)
- {
- if cells[i][0] > -1 and cells[i][0] < room_width div CW
- and cells[i][1] > -1 and cells[i][1] < room_height div CH
- {
- // Если отслеживаем закрытые клетки и текущая клетка НЕ закрыта - игнор
- if (getClosed and ds_grid_get(grid, cells[i][0], cells[i][1]) != 0) {
- continue
- }
- if (ignoreClosed and ds_grid_get(grid, cells[i][0], cells[i][1]) == 0) {
- continue
- }
- if (ignoreObjects) {
- if scr_rect_meeting(cells[i][0] * CW, cells[i][1] * CH,
- cells[i][0] * (CW+1)-1, cells[i][1] * (CH+1)-1, objectToIgnore) {
- continue
- }
- }
- array_push(neighborsAr, cells[i][0] + cells[i][1] * maxX)
- }
- }
- // Возвращаем список доступных соседей
- return neighborsAr
- }
- function scr_rect_meeting(x1, y1, x2, y2, objects = []) {
- for (var i = 0; i < array_length(objects); ++i) {
- if collision_rectangle(x1, y1, x2, y2, objects[i], false, true) {
- return true;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement