# collision_rectangle_list_new

Sep 15th, 2020 (edited)
1,660
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. /// collision_rectangle_list(x1,y1,x2,y2,obj,prec,notme,list,order)
2. //
3. //  Populates a given list data structure with the ids of instances
4. //  colliding with a given rectangle. It optionally orders them by
5. //  distance and returns the number of colliding instances.
6. //
7. //      x1,y1       first corner of the collision rectangle (filled), real
8. //      x2,y2       opposite corner of the collision rectangle (filled), real
9. //      obj         object to check for collision (or all), real
10. //      prec        true for precise collision checking, bool
11. //      notme       true to ignore the calling instance, bool
12. //      list        list to store instance ids in, ds_list
13. //      order       true to order instances by distance, bool
14. //
16. {
17.     var x1,y1,x2,y2,obj,prec,notme,dsid,order,num,i;
18.     x1 = argument0;
19.     y1 = argument1;
20.     x2 = argument2;
21.     y2 = argument3;
22.     obj = argument4;
23.     prec = argument5;
24.     notme = argument6;
25.     dsid = argument7;
26.     order = argument8;
27.     num = 0;
28.
29.     if (order) {
30.
31.         var priority = ds_priority_create();
32.         var cx = mean(x1,x2);
33.         var cy = mean(y1,y2);
34.         with (obj) {
35.             if (!notme || id != other.id) {
36.                 i = collision_rectangle(x1,y1,x2,y2,id,prec,false);
37.                 if (i != noone) {
39.                     num++;
40.                 }
41.             }
42.         }
43.         while (ds_priority_size(priority)) {
45.         }
46.         ds_priority_destroy(priority);
47.
48.     } else {
49.
50.         with (obj) {
51.             if (!notme || id != other.id) {
52.                 i = collision_rectangle(x1,y1,x2,y2,id,prec,false);
53.                 if (i != noone) {
55.                     num++;
56.                 }
57.             }
58.         }
59.     }
60.
61.     return num;
62. }
RAW Paste Data