You are not logged in.
Pages: 1
/*
** 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
This is essentially collision_line_first with slightly different arguments.
Abusing forum power since 1986.
Offline
Pages: 1