Advertisement
Guest User

Untitled

a guest
Jun 4th, 2020
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // collision list will be a ds_list holding instance ids, or noone
  2. var radius = sprite_get_width(sprite_index) / 2; // assumes object is circular
  3. var collision_list = scr_collision_circle_list(x, y, radius, obj_collidables, true, true);
  4.  
  5. // check list isn't empty
  6. if (collision_list != noone) {
  7.  
  8.     // iterate through the list
  9.     for (var n = 0; n < ds_list_size(collision_list); n++) { // all objects that can collide should have a common parent object
  10.  
  11.             var inst = ds_list_find_value(collision_list, n);
  12.    
  13.             // get direction to instance
  14.             var dir = point_direction(x, y, inst.x, inst.y);
  15.  
  16.             // only bounce the object if it hasn't already been bounced
  17.             if (inst.direction != dir( {
  18.                 inst.speed *= speed_multiplier;
  19.                 inst.direction = dir;  
  20.             }
  21.     }
  22.  
  23.     // clean up ds objects when you're done with them, else they sit in memory even when their pointer is a local var
  24.     ds_list_destroy(collision_list);
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement