Advertisement
Ulabael

BresenheimLineOfSight

Sep 23rd, 2022
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. /// @description
  2. var xoCell = x div CellWidth;
  3. var yoCell = y div CellHeight;
  4. var newCircle = scrMidpointCircle(xoCell, yoCell, radius);
  5. var circleLen = array_length(newCircle);
  6.  
  7. var lay_id_shadows = layer_get_id("ShadowTiles");
  8. var map_id_shadows = layer_tilemap_get_id(lay_id_shadows);
  9.  
  10. // Обнуляем старые линии видимости
  11. var linesLen = array_length(lineOfSight);
  12. if (linesLen > 0) {
  13. for (var i = 0; i < linesLen; ++i) {
  14. var lineLen = array_length(lineOfSight[i]);
  15. for (var j = 0; j < lineLen; ++j) {
  16. tilemap_set(map_id_shadows, 1,
  17. lineOfSight[i][j][0], lineOfSight[i][j][1]);
  18. }
  19. }
  20. }
  21.  
  22. // Строим новые - до точек круга
  23. for (var i = 0; i < circleLen; ++i) {
  24. var line = scrBresenham(xoCell, yoCell, newCircle[i][0], newCircle[i][1], global.grid);
  25. var lineLen = array_length(line);
  26. for (var j = 0; j < lineLen; ++j) {
  27. tilemap_set(map_id_shadows, 0, line[j][0], line[j][1]);
  28. }
  29. array_push(lineOfSight, line);
  30. }
  31.  
  32. // Обновляем наш круг
  33. circleSight = [];
  34. array_copy(circleSight, 0, newCircle, 0, array_length(newCircle));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement