4 // Copyright (C) 2005 Philipp <balinor@pnxs.de>
5 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
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.
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.
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
28 #include "math/vector.hpp"
29 #include "game_object.hpp"
30 #include "lisp/lisp.hpp"
31 #include "serializable.hpp"
35 * Helper class that stores an individual node of a Path
40 Vector position; /**< position (in pixels) of this node */
41 float time; /**< time (in seconds) to get to this node */
46 * Path an object can travel along. Made up of multiple nodes of type PathNode.
48 class Path : public GameObject, public Serializable
51 Path(const lisp::Lisp& reader);
54 virtual void update(float elapsed_time);
55 virtual void draw(DrawingContext& context);
57 virtual void write(lisp::Writer& writer);
59 const Vector& GetPosition();
60 const Vector& GetLastMovement();
62 const std::string GetName();
64 // WARNING: returns NULL if not found !
65 static Path* GetByName(const std::string& name);
68 std::string name; /**< name this path can be referenced with, stored in PathRegistry */
69 bool circular; /**< true: start with the first node once the last one has been reached. false: path will stop at last node */
70 bool forward; /**< true: travel to nodes in the order they were defined. false: inverse order */
71 std::vector<PathNode> pathNodes; /**< list of nodes that make up this path */
73 Vector position; /**< current position */
74 Vector velocity; /**< current velocity */
75 Vector last_movement; /**< amount of pixels we moved in the last call to update */
77 int destinationNode; /**< current destination Node */
78 float timeToGo; /**< seconds until we arrive at the destination */
80 static std::map<std::string,Path*> registry;