eliminated global scroll_x and scroll_y variables
[supertux.git] / src / game_object.h
1 //  $Id$
2 //
3 //  SuperTux -  A Jump'n Run
4 //  Copyright (C) 2004 Matthias Braun <matze@braunis.de
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 #ifndef __GAMEOBJECT_HPP__
20 #define __GAMEOBJECT_HPP__
21
22 #include <string>
23
24 class DisplayManager;
25
26 /**
27  * Base class for all game objects. This contains functions for:
28  *  -querying the actual type of the object
29  *  -a flag that indicates if the object wants to be removed. Objects with this
30  *   flag will be removed at the end of each frame. This is alot safer than
31  *   having some uncontrollable "delete this" in the code.
32  *  -an action function that is called once per frame and allows the object to
33  *   update it's state.
34  * 
35  * Most GameObjects will also implement the DrawableObject interface so that
36  * they can actually be drawn on screen.
37  */
38 class GameObject // TODO rename this once the game has been converted
39 {
40 public:
41   GameObject();
42   virtual ~GameObject();
43
44   /** returns the name of the objecttype, this is mainly usefull for the editor.
45    * For the coding part you should use C++ RTTI (ie. typeid and dynamic_cast)
46    * instead.
47    */
48   virtual std::string type() const = 0;
49   /** This function is called once per frame and allows the object to update
50    * it's state. The elapsed_time is the time since the last frame and should be
51    * the base for all timed things.
52    */
53   virtual void action(float elapsed_time) = 0;
54
55   /** returns true if the object is not scheduled to be removed yet */
56   bool is_valid() const
57   { return !wants_to_die; }
58   /** schedules this object to be removed at the end of the frame */
59   void remove_me()
60   { wants_to_die = true; }
61   
62 private:
63   /** this flag indicates if the object should be removed at the end of the
64    * frame
65    */
66   bool wants_to_die;
67 };
68
69 #endif
70