12-20-2003, 05:31 PM
Here's my collision detection routine (collision between NPCs and nonwalkable tiles). It doesn't work. But I can't see the problem. So, could anyone show me at least the bug in that function??
Code:
short int _engine::npc_tile_collide(_npc npc1) {
int x1, y1, x2, y2;
for (int nx = -1; nx < 2; nx++)
for (int ny = -1; ny < 2; ny++)
if (!map_data[npc1.x_pos + nx][npc1.y_pos + ny]) {
x1 = sprite_x_wide * npc1.x_pos + npc1.x_pix;
y1 = sprite_y_wide * npc1.y_pos + npc1.y_pix;
x2 = sprite_x_wide * (npc1.x_pos + nx);
y2 = sprite_y_wide * (npc1.y_pos + ny);
if (!((x1 > x2 + sprite_x_wide) || (x2 > x1 + npc_sprite_x_wide)))
if (!((y1 > y2 + sprite_y_wide) || (y2 > y1 + npc_sprite_y_wide)))
return 1;
}
return 0;
}