16
General / Line in box collision
« on: November 07, 2010, 10:28:33 pm »
oww, thank you, i will try! and not, i'm brazillian
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
bool line_collision(int x1, int y1,int x2,int y2,const gameobj& other,int precise) {
int x,y,angle,dist;
angle = point_direction(x1,y1,x2,y2);
dist = point_distance(x1,y1,x2,y2);
for(int i = 0 ; i < dist ; i+=precise) {
x = (x1-cos(angle*(DEG))*i);
y = (y1-sin(angle*(DEG))*i);
if (x >= other.x + other.rect.Left and x <= other.x + other.rect.Right) {
if (y >= other.y + other.rect.Top and y <= other.y + other.rect.Bottom) {
return 1;
}
}
}
return 0;
}