Advertisement
Guest User

Untitled

a guest
Jan 6th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. ///scr_collision_line_accurate( x1, y1, x2, y2, object, precise, not me )
  2. //
  3. // This function finds the exact (x,y) position of a collision of an object with a line.
  4. // Arguments echo that of GM's native collision_line().
  5. //
  6. // Returns an array:
  7. // return[0] = x coordinate
  8. // return[1] = y coordinate
  9. // return[2] = whether a collision was found (boolean)
  10. //
  11. // Copyright (c) 2016, Julian Adams
  12. // /u/JujuAdam
  13. // @jujuadams
  14. //
  15. // Permission is hereby granted, free of charge, to any person obtaining a copy of this software
  16. // and associated documentation files (the "Software"), to deal in the Software without
  17. // restriction, including without limitation the rights to use, copy, modify, merge, publish,
  18. // distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
  19. // Software is furnished to do so, subject to the following conditions:
  20. //
  21. // The above copyright notice and this permission notice shall be included in all copies or
  22. // substantial portions of the Software.
  23. //
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
  25. // BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  27. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  28. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29.  
  30. var aX = argument0;
  31. var aY = argument1;
  32. var bX = argument2;
  33. var bY = argument3;
  34. var obj = argument4;
  35. var precise = argument5;
  36. var notme = argument6;
  37.  
  38. var result = collision_line( aX, aY, bX, bY, obj, precise, notme);
  39. var array;
  40.  
  41. if ( result > 0 ) {
  42.  
  43. do {
  44.  
  45. var mX = mean( aX, bX );
  46. var mY = mean( aY, bY );
  47.  
  48. var collisionA = collision_line( aX, aY, mX, mY, obj, precise, notme );
  49. if ( collisionA > 0 ) {
  50. bX = mX;
  51. bY = mY;
  52. } else {
  53. aX = mX;
  54. aY = mY;
  55. }
  56.  
  57. } until ( abs( bX - aX ) <= 1 ) and ( abs( bY - aY ) <= 1 );
  58.  
  59. resultX = mean( aX, bX );
  60. resultY = mean( aY, bY );
  61.  
  62. array[0] = resultX;
  63. array[1] = resultY;
  64. array[2] = true;
  65.  
  66. } else {
  67.  
  68. array[0] = aX;
  69. array[1] = aY;
  70. array[2] = false;
  71.  
  72. }
  73.  
  74. return array;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement