- Tile *tile;
- int x, y;
-} tileinfo;
-
-bool rectcollision(const base_type& one, const base_type& two)
-{
- 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& base)
-{
- const TileMap& tilemap = *Sector::current()->solids;
-
- // we make the collision rectangle 1 pixel smaller
- int starttilex = int(base.x+1) / 32;
- int starttiley = int(base.y+1) / 32;
- int max_x = int(base.x + base.width);
- int max_y = int(base.y + base.height);
-
- tileinfo.tile = NULL;
-
- for(int x = starttilex; x*32 < max_x; ++x) {
- for(int y = starttiley; y*32 < max_y; ++y) {
- Tile* tile = tilemap.get_tile(x, y);
- if(tile && tile->attributes & Tile::SOLID)
- {
- tileinfo.tile = tile;
- tileinfo.x = x*32;
- tileinfo.y = y*32;
- return true;
- }
- }
- }
-
- return false;
-}
-
-void* collision_func(const base_type& base, tiletestfunction function)
-{
- const TileMap& tilemap = *Sector::current()->solids;
-
- int starttilex = int(base.x) / 32;
- int starttiley = int(base.y) / 32;
- int max_x = int(base.x + base.width);
- int max_y = int(base.y + base.height);
-
- for(int x = starttilex; x*32 < max_x; ++x) {
- for(int y = starttiley; y*32 < max_y; ++y) {
- Tile* tile = tilemap.get_tile(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;