1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
bool collide(float x1, float y1, float sx1, float sy1, float x2, float y2,float sx2,float sy2) {
if (x1 >= x2 + sx2) //left of first right of second
return false;
if (x2 >= x1 + sx1) // left of second right of first
return false;
if (y1 >= y2 + sy2) // top of first below second
return false;
if (y2 >= y1 + sy1) // top of second below first
return false;
return true; // must be colliding =)
}
collisions get_collision(float x1, float y1, float sx1, float sy1, float x2, float y2,float sx2,float sy2) {
collisions tcol;
tcol.bottom = tcol.top = tcol.right = tcol.left = 0;
if (x1 >= x2 + sx2) //left of first right of second
return tcol;
if (x2 >= x1 + sx1) // left of second right of first
return tcol;
if (y1 >= y2 + sy2) // top of first below second
return tcol;
if (y2 >= y1 + sy1) // top of second below first
return tcol;
tcol.bottom =(y1+sy1)-y2;
tcol.top =(y2+sy2)-y1;
tcol.right =(x2+sx2)-x1;
tcol.left =(x1+sx1)-x2;
return tcol;
}
collisions get_collision(obj* first, obj* second) {
return get_collision(first->get_position().x,first->get_position().y,
first->get_img()->get_width(),first->get_img()->get_height(),
second->get_position().x,second->get_position().y,
second->get_img()->get_width(),second->get_img()->get_height());
}
bool collide(obj first, obj second) {
return collide(first.get_position().x,first.get_position().y,
first.get_img()->get_width(),first.get_img()->get_height(),
second.get_position().x,second.get_position().y,
second.get_img()->get_width(),second.get_img()->get_height());
}
bool collide(obj* first, obj* second) {
return collide(first->get_position().x,first->get_position().y,
first->get_img()->get_width(),first->get_img()->get_height(),
second->get_position().x,second->get_position().y,
second->get_img()->get_width(),second->get_img()->get_height());
}
|