1// SuperTux
2// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17#ifndef HEADER_SUPERTUX_OBJECT_PATH_WALKER_HPP
18#define HEADER_SUPERTUX_OBJECT_PATH_WALKER_HPP
19
20#include <string.h>
21#include <memory>
22
23#include "object/path.hpp"
24#include "util/uid.hpp"
25
26class ObjectOption;
27
28/** A walker that travels along a path */
29class PathWalker final
30{
31public:
32 PathWalker(UID path_uid, bool running = true);
33 ~PathWalker();
34
35 /** advances the path walker on the path and returns its new position */
36 void update(float dt_sec);
37
38 /** current position of path walker */
39 Vector get_pos() const;
40
41 /** advance until at given node, then stop */
42 void goto_node(int node_no);
43
44 /** start advancing automatically */
45 void start_moving();
46
47 /** stop advancing automatically */
48 void stop_moving();
49
50 /** returns true if PathWalker is currently moving */
51 bool is_running() const { return m_running; }
52
53private:
54 void advance_node();
55 void goback_node();
56 Path* get_path() const;
57
58public:
59 UID m_path_uid;
60
61 /** set to false to immediately stop advancing */
62 bool m_running;
63
64private:
65 size_t m_current_node_nr;
66 size_t m_next_node_nr;
67
68 /** stop advancing automatically when this node is reached */
69 int m_stop_at_node_nr;
70
71 /** the position between the current node and the next node as
72 fraction between 0 and 1 */
73 float m_node_time;
74 float m_node_mult;
75
76 float m_walking_speed;
77
78private:
79 PathWalker(const PathWalker&) = delete;
80 PathWalker& operator=(const PathWalker&) = delete;
81};
82
83#endif
84
85/* EOF */
86