Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///scr_collision_line_accurate( x1, y1, x2, y2, object, precise, not me )
- //
- // This function finds the exact (x,y) position of a collision of an object with a line.
- // Arguments echo that of GM's native collision_line().
- //
- // Returns an array:
- // return[0] = x coordinate
- // return[1] = y coordinate
- // return[2] = whether a collision was found (boolean)
- //
- // Copyright (c) 2016, Julian Adams
- // /u/JujuAdam
- // @jujuadams
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy of this software
- // and associated documentation files (the "Software"), to deal in the Software without
- // restriction, including without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
- // Software is furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in all copies or
- // substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
- // BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- var aX = argument0;
- var aY = argument1;
- var bX = argument2;
- var bY = argument3;
- var obj = argument4;
- var precise = argument5;
- var notme = argument6;
- var result = collision_line( aX, aY, bX, bY, obj, precise, notme);
- var array;
- if ( result > 0 ) {
- do {
- var mX = mean( aX, bX );
- var mY = mean( aY, bY );
- var collisionA = collision_line( aX, aY, mX, mY, obj, precise, notme );
- if ( collisionA > 0 ) {
- bX = mX;
- bY = mY;
- } else {
- aX = mX;
- aY = mY;
- }
- } until ( abs( bX - aX ) <= 1 ) and ( abs( bY - aY ) <= 1 );
- resultX = mean( aX, bX );
- resultY = mean( aY, bY );
- array[0] = resultX;
- array[1] = resultY;
- array[2] = true;
- } else {
- array[0] = aX;
- array[1] = aY;
- array[2] = false;
- }
- return array;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement