- 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(const base_type& one, const 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(const 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_func(const base_type& base, tiletestfunction function)
-{
- for(float x = base.x; x < base.x + base.width; x += 32) {
- for(float y = base.y; y < base.y + base.height; y += 32) {
- Tile* tile = gettile(x, y);
- void* result = function(tile);
- if(result != 0)
- return result;
+ 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;