diff options
| author | Magnus Auvinen <magnus.auvinen@gmail.com> | 2007-07-13 13:40:04 +0000 |
|---|---|---|
| committer | Magnus Auvinen <magnus.auvinen@gmail.com> | 2007-07-13 13:40:04 +0000 |
| commit | 125d04e51f4e444a38cf038d3ea095d92d3c6dbb (patch) | |
| tree | 2288bbe4b923ab4d695e9f852c177a12f74ea799 /src/game/mapres_col.cpp | |
| parent | 7be0ae1b2929a3c5dfedf542bce886deefa0f862 (diff) | |
| download | zcatch-125d04e51f4e444a38cf038d3ea095d92d3c6dbb.tar.gz zcatch-125d04e51f4e444a38cf038d3ea095d92d3c6dbb.zip | |
large rewrite and code cleanup
Diffstat (limited to 'src/game/mapres_col.cpp')
| -rw-r--r-- | src/game/mapres_col.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/game/mapres_col.cpp b/src/game/mapres_col.cpp index 29215d7d..d2f9d0c6 100644 --- a/src/game/mapres_col.cpp +++ b/src/game/mapres_col.cpp @@ -1,8 +1,12 @@ #include <baselib/system.h> +#include <baselib/vmath.h> +#include <baselib/math.h> #include "../engine/interface.h" #include "mapres_col.h" #include "mapres.h" +using namespace baselib; + /* Simple collision rutines! */ @@ -42,3 +46,24 @@ int col_check_point(int x, int y) return col.data[ny*col.w+nx]; } + +// TODO: rewrite this smarter! +bool col_intersect_line(vec2 pos0, vec2 pos1, vec2 *out) +{ + float d = distance(pos0, pos1); + + for(float f = 0; f < d; f++) + { + float a = f/d; + vec2 pos = mix(pos0, pos1, a); + if(col_check_point((int)pos.x, (int)pos.y)) + { + if(out) + *out = pos; + return true; + } + } + if(out) + *out = pos1; + return false; +} |