projects
/
supertux.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Made buttjump a bit easier to perform
[supertux.git]
/
src
/
object
/
path_walker.cpp
diff --git
a/src/object/path_walker.cpp
b/src/object/path_walker.cpp
index
a44b157
..
0c8ae25
100644
(file)
--- a/
src/object/path_walker.cpp
+++ b/
src/object/path_walker.cpp
@@
-24,10
+24,9
@@
#include "path_walker.hpp"
PathWalker::PathWalker(const Path* path, bool running)
#include "path_walker.hpp"
PathWalker::PathWalker(const Path* path, bool running)
- : path(path), running(running), current_node_nr(0), next_node_nr(0), stop_at_node_nr(
-1
), node_time(0),
+ : path(path), running(running), current_node_nr(0), next_node_nr(0), stop_at_node_nr(
running?-1:0
), node_time(0),
walking_speed(1.0)
{
walking_speed(1.0)
{
- last_pos = path->nodes[0].position;
node_mult = 1 / path->nodes[0].time;
next_node_nr = path->nodes.size() > 1 ? 1 : 0;
}
node_mult = 1 / path->nodes[0].time;
next_node_nr = path->nodes.size() > 1 ? 1 : 0;
}
@@
-39,12
+38,12
@@
PathWalker::~PathWalker()
Vector
PathWalker::advance(float elapsed_time)
{
Vector
PathWalker::advance(float elapsed_time)
{
- if (!running) return
Vector(0,0)
;
+ if (!running) return
path->nodes[current_node_nr].position
;
assert(elapsed_time >= 0);
elapsed_time *= fabsf(walking_speed);
assert(elapsed_time >= 0);
elapsed_time *= fabsf(walking_speed);
-
+
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;
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;
@@
-63,20
+62,17
@@
PathWalker::advance(float elapsed_time)
node_mult = 1 / 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_mult;
const Path::Node* next_node = & (path->nodes[next_node_nr]);
node_time += elapsed_time * node_mult;
-
- Vector new_pos = current_node->position +
+
+ Vector new_pos = current_node->position +
(next_node->position - current_node->position) * node_time;
(next_node->position - current_node->position) * node_time;
-
- Vector result = new_pos - last_pos;
- last_pos = new_pos;
-
- return result;
+
+ return new_pos;
}
}
-void
+void
PathWalker::goto_node(int node_no)
{
if (node_no == stop_at_node_nr) return;
PathWalker::goto_node(int node_no)
{
if (node_no == stop_at_node_nr) return;
@@
-84,14
+80,14
@@
PathWalker::goto_node(int node_no)
stop_at_node_nr = node_no;
}
stop_at_node_nr = node_no;
}
-void
+void
PathWalker::start_moving()
{
running = true;
stop_at_node_nr = -1;
}
PathWalker::start_moving()
{
running = true;
stop_at_node_nr = -1;
}
-void
+void
PathWalker::stop_moving()
{
stop_at_node_nr = next_node_nr;
PathWalker::stop_moving()
{
stop_at_node_nr = next_node_nr;