New Path based on time intervals; see levels/test/platform.stl
[supertux.git] / src / object / path.hpp
1 //  $Id$
2 // 
3 //  SuperTux Path
4 //  Copyright (C) 2005 Philipp <balinor@pnxs.de>
5 //  Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
6 //
7 //  This program is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU General Public License
9 //  as published by the Free Software Foundation; either version 2
10 //  of the License, or (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 // 
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 //  02111-1307, USA.
21 #ifndef __PATH_HPP__
22 #define __PATH_HPP__
23
24 #include <string>
25 #include <list>
26 #include <map>
27
28 #include "math/vector.hpp"
29 #include "game_object.hpp"
30 #include "lisp/lisp.hpp"
31
32
33 /**
34  * Helper class that stores an individual node of a Path
35  */
36 class PathNode
37 {
38 public:
39   Vector position; /**< position (in pixels) of this node */
40   float time; /**< time (in seconds) to get to this node */
41 };
42
43
44 /**
45  * Path an object can travel along. Made up of multiple nodes of type PathNode.
46  */
47 class Path : public GameObject
48 {
49 public:
50   Path(const lisp::Lisp& reader);
51   ~Path();
52
53   virtual void update(float elapsed_time);
54   virtual void draw(DrawingContext& context);
55
56   const Vector& GetPosition();
57   const Vector& GetLastMovement();
58
59   // WARNING: returns NULL if not found !
60   static Path* GetByName(const std::string& name);
61
62 private:
63   std::string name; /**< name this path can be referenced with, stored in PathRegistry */
64   bool circular; /**< true: start with the first node once the last one has been reached. false: path will stop at last node */
65   bool forward; /**< true: travel to nodes in the order they were defined. false: inverse order */
66   std::vector<PathNode> pathNodes; /**< list of nodes that make up this path */
67
68   Vector position; /**< current position */
69   Vector velocity; /**< current velocity */
70   Vector last_movement; /**< amount of pixels we moved in the last call to update */
71
72   int destinationNode; /**< current destination Node */
73   float timeToGo; /**< seconds until we arrive at the destination */
74
75   static std::map<std::string,Path*> registry;
76 };
77
78 #endif