add code to debug collision rectangles
[supertux.git] / src / object / path_walker.cpp
index fa3669b..007c387 100644 (file)
@@ -22,6 +22,7 @@
 #include <config.h>
 
 #include <math.h>
+#include <assert.h>
 #include "path_walker.hpp"
 
 PathWalker::PathWalker(const Path* path)
@@ -30,6 +31,7 @@ PathWalker::PathWalker(const Path* path)
 {
   last_pos = path->nodes[0].position;
   node_mult = 1 / path->nodes[0].time;
+  next_node_nr = path->nodes.size() > 1 ? 1 : 0;
 }
 
 PathWalker::~PathWalker()
@@ -45,7 +47,7 @@ PathWalker::advance(float elapsed_time)
   
   const Path::Node* current_node = & (path->nodes[current_node_nr]);
   while(node_time + elapsed_time * node_mult >= 1) {
-    elapsed_time -= (1 - node_time) * node_mult;
+    elapsed_time -= (1 - node_time) / node_mult;
 
     if(walking_speed > 0) {
       advance_node();
@@ -119,6 +121,7 @@ PathWalker::goback_node()
   switch(path->mode) {
     case Path::PING_PONG:
       walking_speed = -walking_speed;
+      next_node_nr = path->nodes.size() > 1 ? 1 : 0;
       return;
     default:
       break;