- return (one->x >= two->x - one->width + 1 &&
- one->x <= two->x + two->width - 1 &&
- one->y >= two->y - one->height + 1 &&
- one->y <= two->y + two->height - 1);
-}
-
-bool rectcollision_offset(base_type* one, base_type* two, float off_x, float off_y)
-{
- return (one->x >= two->x - one->width +off_x + 1 &&
- one->x <= two->x + two->width + off_x - 1 &&
- one->y >= two->y - one->height + off_y + 1 &&
- one->y <= two->y + two->height + off_y - 1);
-}
-
-bool collision_object_map(base_type* pbase)
-{
- int v = (int)pbase->height / 16;
- int h = (int)pbase->width / 16;
-
- if(issolid(pbase->x + 1, pbase->y + 1) ||
- issolid(pbase->x + pbase->width -1, pbase->y + 1) ||
- issolid(pbase->x +1, pbase->y + pbase->height -1) ||
- issolid(pbase->x + pbase->width -1, pbase->y + pbase->height - 1))
- return true;
-
- for(int i = 1; i < h; ++i)
- {
- if(issolid(pbase->x + i*16,pbase->y + 1))
- return true;
- }
-
- for(int i = 1; i < h; ++i)
- {
- if( issolid(pbase->x + i*16,pbase->y + pbase->height - 1))
- return true;
- }
-
- for(int i = 1; i < v; ++i)
- {
- if( issolid(pbase->x + 1, pbase->y + i*16))
- return true;
- }
- for(int i = 1; i < v; ++i)
- {
- if( issolid(pbase->x + pbase->width - 1, pbase->y + i*16))
- return true;
- }
-
- return false;
-}
-
-
-void collision_swept_object_map(base_type* old, base_type* current)
-{
- int steps; /* Used to speed up the collision tests, by stepping every 16pixels in the path. */
- int h;
- float lpath; /* Holds the longest path, which is either in X or Y direction. */
- float xd,yd; /* Hold the smallest steps in X and Y directions. */
- float temp, xt, yt; /* Temporary variable. */
-
- lpath = 0;
- xd = 0;
- yd = 0;
-
- if(old->x == current->x && old->y == current->y)
- {
- return;
- }
- else if(old->x == current->x && old->y != current->y)
- {
- lpath = current->y - old->y;
- if(lpath < 0)
- {
- yd = -1;
- lpath = -lpath;
- }
- else
- {
- yd = 1;
- }
-
- h = 1;
- xd = 0;
+ if(r1.p2.x < r2.p1.x || r1.p1.x > r2.p2.x)
+ return false;
+ if(r1.p2.y < r2.p1.y || r1.p1.y > r2.p2.y)
+ return false;
+
+ if(movement.x > DELTA) {
+ hit.depth = r1.p2.x - r2.p1.x;
+ hit.time = hit.depth / movement.x;
+ hit.normal.x = -1;
+ hit.normal.y = 0;
+ } else if(movement.x < -DELTA) {
+ hit.depth = r2.p2.x - r1.p1.x;
+ hit.time = hit.depth / -movement.x;
+ hit.normal.x = 1;
+ hit.normal.y = 0;
+ } else {
+ if(movement.y > -DELTA && movement.y < DELTA) {
+ hit.time = 0;
+ hit.depth = 0;
+ hit.normal.x = 1;
+ hit.normal.y = 0;
+ return true;