X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fcollision.cpp;h=716c05aa53beddcb56e8e3c443a3cdea47e74170;hb=935c2f6a2a27248de63fba86b74a724675761487;hp=e36327f5b58578affe3eb11b56b97297e4aeafda;hpb=2074a5e3f8167dec24989c008ddadda14687a3a6;p=supertux.git diff --git a/src/collision.cpp b/src/collision.cpp index e36327f5b..716c05aa5 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -18,6 +18,7 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA. +#include #include "defines.h" #include "collision.h" #include "bitmask.h" @@ -26,6 +27,12 @@ #include "tilemap.h" #include "tile.h" +struct TileInfo +{ + Tile *tile; + int x, y; +} tileinfo; + bool rectcollision(const base_type& one, const base_type& two) { return (one.x >= two.x - one.width + 1 && @@ -52,11 +59,18 @@ bool collision_object_map(const base_type& base) 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->attributes & Tile::SOLID) + if(tile && tile->attributes & Tile::SOLID) + { + tileinfo.tile = tile; + tileinfo.x = x*32; + tileinfo.y = y*32; return true; + } } } @@ -175,6 +189,21 @@ void collision_swept_object_map(base_type* old, base_type* current) if(collision_object_map(*old)) { + if(tileinfo.tile->slope_angle != 0) + { // in case this is a slope, set the right Y position + // left-right slope: + if(tileinfo.tile->slope_angle > 0 && tileinfo.tile->slope_angle < M_PI/2) + current->y = tileinfo.y - current->height + + (tileinfo.x - current->x)*tan(M_PI/2 - tileinfo.tile->slope_angle) + - 1; + // right-left slope: + if(tileinfo.tile->slope_angle > M_PI/2 && tileinfo.tile->slope_angle < M_PI) + current->y = tileinfo.y - current->height + + (current->x - tileinfo.x)*tan(M_PI - tileinfo.tile->slope_angle) + - 1; + } + else + { switch(h) { case 1: @@ -225,6 +254,7 @@ void collision_swept_object_map(base_type* old, base_type* current) } break; } + } } if((xd > 0 && current->x < orig_x) || (xd < 0 && current->x > orig_x))