diff options
| author | Magnus Auvinen <magnus.auvinen@gmail.com> | 2007-12-12 20:05:18 +0000 |
|---|---|---|
| committer | Magnus Auvinen <magnus.auvinen@gmail.com> | 2007-12-12 20:05:18 +0000 |
| commit | 7d7975644369e393d44950d3b0083743b39db173 (patch) | |
| tree | 09b4a5a541c61aafc1ac595f7d042ace661f0a20 /src/game/game.cpp | |
| parent | f7ea0b2ba8851e4c0ceaef0a8b2361adfc218443 (diff) | |
| download | zcatch-7d7975644369e393d44950d3b0083743b39db173.tar.gz zcatch-7d7975644369e393d44950d3b0083743b39db173.zip | |
solved corner case issue
Diffstat (limited to 'src/game/game.cpp')
| -rw-r--r-- | src/game/game.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/game/game.cpp b/src/game/game.cpp index cb00ae0e..29e4da14 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -75,18 +75,30 @@ void move_box(vec2 *inout_pos, vec2 *inout_vel, vec2 size, float elasticity) vec2 new_pos = pos + vel*fraction; // TODO: this row is not nice - // make sure that we quantize. this is to make sure that when we set - // the final position that we don't move it into the ground. - if(test_box(vec2((int)new_pos.x,(int) new_pos.y), size)) + if(test_box(vec2(new_pos.x, new_pos.y), size)) { - if(test_box(vec2((int)pos.x, (int)new_pos.y), size)) + int hits = 0; + + if(test_box(vec2(pos.x, new_pos.y), size)) { new_pos.y = pos.y; vel.y *= -elasticity; + hits++; + } + + if(test_box(vec2(new_pos.x, pos.y), size)) + { + new_pos.x = pos.x; + vel.x *= -elasticity; + hits++; } - if(test_box(vec2((int)new_pos.x, (int)pos.y), size)) + // neither of the tests got a collision. + // this is a real _corner case_! + if(hits == 0) { + new_pos.y = pos.y; + vel.y *= -elasticity; new_pos.x = pos.x; vel.x *= -elasticity; } |