From 6b08e6dca589020b650cbaadd7c2713eac560d66 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Fri, 31 Mar 2006 10:07:43 +0000 Subject: [PATCH] fix collision against spikes too wide, fix paths, try to fix jumping on badguys that go up problem... SVN-Revision: 3142 --- data/levels/test/platform.stl | 4 ++-- data/levels/world2/christoph2.stl | 30 ------------------------------ src/badguy/badguy.cpp | 9 +++++++-- src/object/path_walker.cpp | 16 ++++++++-------- src/object/path_walker.hpp | 6 +++++- src/sector.cpp | 8 ++++---- 6 files changed, 26 insertions(+), 47 deletions(-) diff --git a/data/levels/test/platform.stl b/data/levels/test/platform.stl index e25eb38ac..cf3c7db20 100644 --- a/data/levels/test/platform.stl +++ b/data/levels/test/platform.stl @@ -133,7 +133,7 @@ (path (mode "pingpong") (node (x 200) (y 850)) - (node (x 200) (y 750)) + (node (x 200) (y 750) (time 0.5)) (node (x 100) (y 750)) ) (sprite "images/objects/platforms/small.sprite") @@ -160,7 +160,7 @@ (platform (path (mode "circular") - (node (x 392) (y 850) (time 1)) + (node (x 392) (y 850) (time 1)) (node (x 392) (y 750) (time 1)) (node (x 392) (y 650) (time 0.6)) (node (x 392) (y 750) (time 1)) diff --git a/data/levels/world2/christoph2.stl b/data/levels/world2/christoph2.stl index 15f956309..6dc3262ed 100644 --- a/data/levels/world2/christoph2.stl +++ b/data/levels/world2/christoph2.stl @@ -41,36 +41,6 @@ (speed 0.5) (speed-y 1.0) ) - (path - (name "path1") - (circular #t) - (nodes - (node (x 0) (y 0) (time 3)) - (node (x 0) (y 0) (time 1)) - (node (x 0) (y -416) (time 3)) - (node (x 0) (y -416) (time 1)) - ) - ) - (path - (name "path2") - (circular #t) - (nodes - (node (x 0) (y 0) (time 3)) - (node (x 0) (y 0) (time 1)) - (node (x 0) (y 416) (time 3)) - (node (x 0) (y 416) (time 1)) - ) - ) - (path - (name "path3") - (circular #t) - (nodes - (node (x 0) (y 0) (time 1)) - (node (x 0) (y 0) (time 1)) - (node (x 0) (y -448) (time 2)) - (node (x 0) (y -448) (time 1)) - ) - ) (spawnpoint (x 96) (y 1306) diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index 5cbcf1a58..6ffe20cbe 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -165,15 +165,20 @@ BadGuy::collision_solid(GameObject& , const CollisionHit& ) } HitResponse -BadGuy::collision_player(Player& player, const CollisionHit& ) +BadGuy::collision_player(Player& player, const CollisionHit& hit) { if(player.is_invincible()) { kill_fall(); return ABORT_MOVE; } + printf("PlayerHit: PM: %3.1f %3.1f BM: %3.1f %3.1f Hit: %3.1f %3.1f\n", + player.get_movement().x, player.get_movement().y, + get_movement().x, get_movement().y, + hit.normal.x, hit.normal.y); // hit from above? - if(player.get_movement().y - get_movement().y > 0 && player.get_bbox().p2.y < + if(player.get_movement().y /*- get_movement().y*/ > 0 + && player.get_bbox().p2.y < (get_bbox().p1.y + get_bbox().p2.y) / 2) { // if it's not possible to squish us, then this will hurt if(collision_squished(player)) diff --git a/src/object/path_walker.cpp b/src/object/path_walker.cpp index 1eca37023..fa3669bc9 100644 --- a/src/object/path_walker.cpp +++ b/src/object/path_walker.cpp @@ -29,7 +29,7 @@ PathWalker::PathWalker(const Path* path) walking_speed(1.0) { last_pos = path->nodes[0].position; - node_time = path->nodes[0].time; + node_mult = 1 / path->nodes[0].time; } PathWalker::~PathWalker() @@ -44,8 +44,8 @@ PathWalker::advance(float elapsed_time) elapsed_time *= fabsf(walking_speed); const Path::Node* current_node = & (path->nodes[current_node_nr]); - while(node_time - elapsed_time < 0) { - elapsed_time -= current_node->time - node_time; + while(node_time + elapsed_time * node_mult >= 1) { + elapsed_time -= (1 - node_time) * node_mult; if(walking_speed > 0) { advance_node(); @@ -54,19 +54,19 @@ PathWalker::advance(float elapsed_time) } current_node = & (path->nodes[current_node_nr]); + node_time = 0; if(walking_speed > 0) { - node_time = current_node->time; + node_mult = 1 / current_node->time; } else { - node_time = path->nodes[next_node_nr].time; + node_mult = 1 / path->nodes[next_node_nr].time; } } const Path::Node* next_node = & (path->nodes[next_node_nr]); - node_time -= elapsed_time; + node_time += elapsed_time * node_mult; Vector new_pos = current_node->position + - (next_node->position - current_node->position) - * (1 - (node_time / current_node->time)); + (next_node->position - current_node->position) * node_time; Vector result = new_pos - last_pos; last_pos = new_pos; diff --git a/src/object/path_walker.hpp b/src/object/path_walker.hpp index 016de8a3f..2f759fd56 100644 --- a/src/object/path_walker.hpp +++ b/src/object/path_walker.hpp @@ -53,8 +53,12 @@ private: Vector last_pos; - /** the time we already spend in the current node */ + /** + * the position between the current node and the next node as fraction + * between 0 and 1 + */ float node_time; + float node_mult; float walking_speed; }; diff --git a/src/sector.cpp b/src/sector.cpp index 9e33ce7c0..cf5e8f5d3 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -665,10 +665,10 @@ Sector::collision_tile_attributes(const Rect& dest) const float y2 = dest.p2.y; // test with all tiles in this rectangle - int starttilex = int(x1-1) / 32; - int starttiley = int(y1-1) / 32; - int max_x = int(x2+1); - int max_y = int(y2+1); + int starttilex = int(x1) / 32; + int starttiley = int(y1) / 32; + int max_x = int(x2); + int max_y = int(y2); uint32_t result = 0; for(int x = starttilex; x*32 < max_x; ++x) { -- 2.11.0