object->width = <ACTUAL BITMAP WIDTH>;
object->height = <ACTUAL BITMAP HEIGHT>;
object->col_width = object->width * 0.80;
object->col_height = object->height * 0.80;
object->col_x_offset = (object->width - object->col_width) / 2;
object->col_y_offset = (object->height - object->col_height) / 2;
// Object-to-object, reduced bounding-box collision detector:
short int Sprite_Collide(sprite_ptr object1, sprite_ptr object2) {
int left1, left2;
int right1, right2;
int top1, top2;
int bottom1, bottom2;
left1 = object1->x + object1->col_x_offset;
left2 = object2->x + object2->col_x_offset;
right1 = left1 + object1->col_width;
right2 = left2 + object2->col_width;
top1 = object1->y + object1->col_y_offset;
top2 = object2->y + object1->col_y_offset;
bottom1 = top1 + object1->col_height;
bottom2 = top2 + object2->col_height;
if (bottom1 < top2) return(0);
if (top1 > bottom2) return(0);
if (right1 < left2) return(0);
if (left1 > right2) return(0);
return(1);
};
And I translated it into DM fairly well. However, I don't think I got my chain of greater than and less than's correct; it wrongly detects collision when I bump into an object while moving down (only when I collided with the top of an object and began to move down) and when I bump into an object's left side while moving right. I'm using the procs below:
atom/proc
set_loc()
pixx = pixel_x+32*x
pixy = pixel_y+32*y
top = pixy+col_height+col_y_offset
bottom = pixy+col_y_offset
left = pixx+col_x_offset
right = pixx+col_width+col_x_offset
midy = pixy+((col_height+col_y_offset) >> 1)
midx = pixx+((col_width+col_x_offset) >> 1)
set_size(nwidth,nheight)
width = nwidth
height = nheight
col_height = round(height*0.8)
col_width = round(width*0.8)
col_x_offset = round((width - col_width) >> 1)
col_y_offset = round((height - col_height) >> 1)
atom/movable/proc
iscolliding(xp,yp)
if(!density) return
var
top1 = top+yp
bottom1 = bottom+yp
left1 = left+xp
right1 = right+xp
var/list/L = range(1,src)-src
QuickSort(L,/proc/Sort_By_Dist,src)
for(var/atom/A in L)
if(!A.density) continue
if(bottom1 > A.top) continue
if(top1 < A.bottom) continue
if(right1 < A.left) continue
if(left1 > A.right) continue
return A
It worked correctly before I attempted to shrink the collision boxes, any insight into the issue?