X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Fpath_walker.cpp;h=d0d55ddfa416eb961dfc94e51ef61d60a58e6508;hb=113cdbf07f441329690714a53a436503ab1d4b35;hp=007c3871ce69944e4c9e5f733a41b72e48978ad1;hpb=6ccf05311fd4dc238ac7733c487bdf580b2f1ad7;p=supertux.git diff --git a/src/object/path_walker.cpp b/src/object/path_walker.cpp index 007c3871c..d0d55ddfa 100644 --- a/src/object/path_walker.cpp +++ b/src/object/path_walker.cpp @@ -1,8 +1,6 @@ -// $Id: path.hpp 3114 2006-03-23 23:47:04Z sommer $ -// -// SuperTux Path -// Copyright (C) 2005 Philipp -// Copyright (C) 2006 Christoph Sommer +// $Id$ +// +// SuperTux // Copyright (C) 2006 Matthias Braun // // This program is free software; you can redistribute it and/or @@ -14,19 +12,19 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -// 02111-1307, USA. +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + #include #include #include #include "path_walker.hpp" -PathWalker::PathWalker(const Path* path) - : path(path), current_node_nr(0), next_node_nr(0), node_time(0), +PathWalker::PathWalker(const Path* path, bool running) + : 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) { last_pos = path->nodes[0].position; @@ -41,6 +39,8 @@ PathWalker::~PathWalker() Vector PathWalker::advance(float elapsed_time) { + if (!running) return Vector(0,0); + assert(elapsed_time >= 0); elapsed_time *= fabsf(walking_speed); @@ -76,10 +76,33 @@ PathWalker::advance(float elapsed_time) return result; } +void +PathWalker::goto_node(int node_no) +{ + if (node_no == stop_at_node_nr) return; + running = true; + stop_at_node_nr = node_no; +} + +void +PathWalker::start_moving() +{ + running = true; + stop_at_node_nr = -1; +} + +void +PathWalker::stop_moving() +{ + stop_at_node_nr = next_node_nr; +} + + void PathWalker::advance_node() { current_node_nr = next_node_nr; + if (static_cast(current_node_nr) == stop_at_node_nr) running = false; if(next_node_nr + 1 < path->nodes.size()) { next_node_nr++;