GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2010-12-30 21:35:26

icuurd12b42
Member
Registered: 2008-12-11
Posts: 303

sister to range_finder...

Expand/*
**  Usage:
**      range_obj(x,y,dir,range,object,prec,notme)
**
**  Given:
**      x,y         position in room
**      dir         direction to look in degrees
**      range       the greatest distance to look in pixels
**      object      which objects to look for, or keyword all
**      prec        if true, use precise collision checking
**      notme       if true, ignore the calling instance
**
**  Returns:
**      instance id found or noone
**
**  Notes:
**      Computes the answer in log2(range) collision checks
**
**  GMLscripts.com
*/
{
    var ox,oy,dir,range,object,prec,notme,dx,dy,sx,sy,distance,o,oret;
    
    ox = argument0;
    oy = argument1;
    dir = argument2;
    range = argument3;
    object = argument4;
    prec = argument5;
    notme = argument6;
    sx = lengthdir_x(range,dir);
    sy = lengthdir_y(range,dir);
    dx = ox + sx;
    dy = oy + sy;
    o = collision_line(ox,oy,dx,dy,object,prec,notme);
    if (o < 0) {
        oret = noone;
    }else{
        while ((abs(sx) >= 1) || (abs(sy) >= 1)) {
            sx /= 2;
            sy /= 2;
            o = collision_line(ox,oy,dx,dy,object,prec,notme)
            if (o < 0) {
                dx += sx;
                dy += sy;
            }else{
                dx -= sx;
                dy -= sy;
                oret = o;
            }
        }
    }
    return oret;
}

Last edited by icuurd12b42 (2010-12-30 21:36:15)

Offline

#2 2011-02-08 10:47:44

xot
Administrator
Registered: 2007-08-18
Posts: 1,239

Re: sister to range_finder...

This is essentially collision_line_first with slightly different arguments.


Abusing forum power since 1986.

Offline

Board footer

Powered by FluxBB