converted player to new object system
[supertux.git] / src / game_object.h
1 #ifndef __GAMEOBJECT_HPP__
2 #define __GAMEOBJECT_HPP__
3
4 #include <string>
5
6 class DisplayManager;
7
8 /**
9  * Base class for all game objects. This contains functions for:
10  *  -querying the actual type of the object
11  *  -a flag that indicates if the object wants to be removed. Objects with this
12  *   flag will be removed at the end of each frame. This is alot safer than
13  *   having some uncontrollable "delete this" in the code.
14  *  -an action function that is called once per frame and allows the object to
15  *   update it's state.
16  * 
17  * Most GameObjects will also implement the DrawableObject interface so that
18  * they can actually be drawn on screen.
19  */
20 class _GameObject // TODO rename this once the game has been converted
21 {
22 public:
23   _GameObject();
24   virtual ~_GameObject();
25
26   /** returns the name of the objecttype, this is mainly usefull for the editor.
27    * For the coding part you should use C++ RTTI (ie. typeid and dynamic_cast)
28    * instead.
29    */
30   virtual std::string type() const = 0;
31   /** This function is called once per frame and allows the object to update
32    * it's state. The elapsed_time is the time since the last frame and should be
33    * the base for all timed things.
34    */
35   virtual void action(float elapsed_time) = 0;
36
37   /** returns true if the object is not scheduled to be removed yet */
38   bool is_valid() const
39   { return !wants_to_die; }
40   /** schedules this object to be removed at the end of the frame */
41   void remove_me()
42   { wants_to_die = true; }
43   
44 private:
45   /** this flag indicates if the object should be removed at the end of the
46    * frame
47    */
48   bool wants_to_die;
49 };
50
51 #endif
52