about summary refs log tree commit diff
path: root/src/game/mapres_col.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/mapres_col.cpp')
-rw-r--r--src/game/mapres_col.cpp25
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;
+}