3 // SuperTux - A Jump'n Run
4 // Copyright (C) 2004 Matthias Braun <matze@braunis.de>
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.
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.
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.
20 #ifndef SUPERTUX_GAMEOBJECT_H
21 #define SUPERTUX_GAMEOBJECT_H
30 class ObjectRemoveListener;
33 * Base class for all game objects. This contains functions for:
34 * -querying the actual type of the object
35 * -a flag that indicates if the object wants to be removed. Objects with this
36 * flag will be removed at the end of each frame. This is alot safer than
37 * having some uncontrollable "delete this" in the code.
38 * -an action function that is called once per frame and allows the object to
41 * Most GameObjects will also implement the DrawableObject interface so that
42 * they can actually be drawn on screen.
48 virtual ~GameObject();
50 /** This function is called once per frame and allows the object to update
51 * it's state. The elapsed_time is the time since the last frame in
52 * seconds and should be the base for all timed calculations (don't use
53 * SDL_GetTicks directly as this will fail in pause mode)
55 virtual void action(float elapsed_time) = 0;
57 /** The GameObject should draw itself onto the provided DrawingContext if this
60 virtual void draw(DrawingContext& context) = 0;
62 /** returns true if the object is not scheduled to be removed yet */
67 /** schedules this object to be removed at the end of the frame */
72 /** registers a remove listener which will be called if the object
73 * gets removed/destroyed
75 void add_remove_listener(ObjectRemoveListener* listener)
77 RemoveListenerListEntry* entry = new RemoveListenerListEntry();
78 entry->next = remove_listeners;
79 entry->listener = listener;
81 remove_listeners = entry;
86 /// the tile so you can stand on it
88 /// can be used to temporatily disable collision detection
89 FLAG_NO_COLLDET = 0x0002
98 /** this flag indicates if the object should be removed at the end of the
103 struct RemoveListenerListEntry
105 RemoveListenerListEntry* next;
106 ObjectRemoveListener* listener;
108 RemoveListenerListEntry* remove_listeners;
115 #endif /*SUPERTUX_GAMEOBJECT_H*/