#18451 - Darmstadium - Fri Mar 26, 2004 6:11 pm
I am having a bit of trouble getting my system of collision detection to work. It works like this: there is a struct called object that stores the x, y, height, and width of all of the stuff you can collide with. All of the objects are pointed to in an array of pointers to objects called objs. Here's my code:
When I test my demo the sprite I'm checking moves right on over all the other objects. I'm not at all sure why this is
Last edited by Darmstadium on Sat Mar 27, 2004 3:27 am; edited 1 time in total
Code: |
struct object { u8 n; u16 x; u16 y; u8 h, w; }; #define OBJSLEN 1 object * objs[OBJSLEN]; bool MoveOK(object * client, s16 xmove, s16 ymove) { u8 oks = 0; u16 loop; for (loop = 0; loop <= OBJSLEN; loop++) { if (objs[loop]->n != client->n) { if (objs[loop]->x > client->x + xmove + client->w) oks++; else if (objs[loop]->x + objs[loop]->w < client->x + xmove) oks++; else if (objs[loop]->y > client->y + ymove + client->h) oks++; else if (objs[loop]->y + objs[loop]->h < client->y + ymove) oks++; } } if (oks == OBJSLEN - 1) return true; return false; } |
When I test my demo the sprite I'm checking moves right on over all the other objects. I'm not at all sure why this is
Last edited by Darmstadium on Sat Mar 27, 2004 3:27 am; edited 1 time in total