supertux
path_walker.hpp
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 
26 class ObjectOption;
27 
29 class PathWalker final
30 {
31 public:
32  PathWalker(UID path_uid, bool running = true);
33  ~PathWalker();
34 
36  void update(float dt_sec);
37 
39  Vector get_pos() const;
40 
42  void goto_node(int node_no);
43 
45  void start_moving();
46 
48  void stop_moving();
49 
51  bool is_running() const { return m_running; }
52 
53 private:
54  void advance_node();
55  void goback_node();
56  Path* get_path() const;
57 
58 public:
59  UID m_path_uid;
60 
62  bool m_running;
63 
64 private:
65  size_t m_current_node_nr;
66  size_t m_next_node_nr;
67 
69  int m_stop_at_node_nr;
70 
73  float m_node_time;
74  float m_node_mult;
75 
76  float m_walking_speed;
77 
78 private:
79  PathWalker(const PathWalker&) = delete;
80  PathWalker& operator=(const PathWalker&) = delete;
81 };
82 
83 #endif
84 
85 /* EOF */
A walker that travels along a path.
Definition: path_walker.hpp:29
bool m_running
set to false to immediately stop advancing
Definition: path_walker.hpp:62
Simple two dimensional vector.
Definition: vector.hpp:24
Definition: object_option.hpp:48
Vector get_pos() const
current position of path walker
Definition: path_walker.cpp:101
void goto_node(int node_no)
advance until at given node, then stop
Definition: path_walker.cpp:117
void start_moving()
start advancing automatically
Definition: path_walker.cpp:128
Definition: path.hpp:44
Definition: uid.hpp:37
bool is_running() const
returns true if PathWalker is currently moving
Definition: path_walker.hpp:51
void stop_moving()
stop advancing automatically
Definition: path_walker.cpp:135
void update(float dt_sec)
advances the path walker on the path and returns its new position
Definition: path_walker.cpp:69