From 371e8623161095b8f74d51d37f3de368b5cd584c Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Sun, 11 Jan 2009 10:26:17 +0000 Subject: fixed so the laser bounces correctly at low angles --- src/game/collision.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/game/collision.cpp') diff --git a/src/game/collision.cpp b/src/game/collision.cpp index 2747b22f..73f4a9c5 100644 --- a/src/game/collision.cpp +++ b/src/game/collision.cpp @@ -60,22 +60,28 @@ int col_is_solid(int x, int y) // TODO: rewrite this smarter! -int col_intersect_line(vec2 pos0, vec2 pos1, vec2 *out) +int col_intersect_line(vec2 pos0, vec2 pos1, vec2 *out_collision, vec2 *out_before_collision) { float d = distance(pos0, pos1); + vec2 last = pos0; for(float f = 0; f < d; f++) { float a = f/d; vec2 pos = mix(pos0, pos1, a); - if(col_is_solid((int)pos.x, (int)pos.y)) + if(col_is_solid(round(pos.x), round(pos.y))) { - if(out) - *out = pos; - return col_get((int)pos.x, (int)pos.y); + if(out_collision) + *out_collision = pos; + if(out_before_collision) + *out_before_collision = last; + return col_get(round(pos.x), round(pos.y)); } + last = pos; } - if(out) - *out = pos1; + if(out_collision) + *out_collision = pos1; + if(out_before_collision) + *out_before_collision = pos1; return 0; } -- cgit 1.4.1