Merged changes from branches/supertux-milestone2-grumbel/ to trunk/supertux/
[supertux.git] / src / trigger / trigger_base.hpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #ifndef HEADER_SUPERTUX_TRIGGER_TRIGGER_BASE_HPP
18 #define HEADER_SUPERTUX_TRIGGER_TRIGGER_BASE_HPP
19
20 #include <list>
21 #include <memory>
22
23 #include "supertux/moving_object.hpp"
24 #include "supertux/object_remove_listener.hpp"
25
26 class Player;
27 class Sprite;
28
29 /** This class is the base class for all objects you can interact with in some
30  * way. There are several interaction types defined like touch and activate
31  */
32 class TriggerBase : public MovingObject, 
33                     public ObjectRemoveListener
34 {
35 public:
36   enum EventType {
37     EVENT_TOUCH,     /**< Object came into contact */
38     EVENT_LOSETOUCH, /**< Lost contact with object */
39     EVENT_ACTIVATE   /**< Action button pressed    */
40   };
41
42   TriggerBase();
43   ~TriggerBase();
44
45   void update(float elapsed_time);
46   void draw(DrawingContext& context);
47   HitResponse collision(GameObject& other, const CollisionHit& hit);
48
49   /**
50    * Receive trigger events
51    */
52   virtual void event(Player& player, EventType type) = 0;
53   
54   /**
55    * Called by GameObject destructor of an object in losetouch_listeners
56    */
57   virtual void object_removed(GameObject* object);
58
59 private:
60   std::auto_ptr<Sprite> sprite;
61   bool lasthit;
62   bool hit;
63
64   std::list<Player*> losetouch_listeners; /**< Players that will be informed when we lose touch with them */
65
66 private:
67   TriggerBase(const TriggerBase&);
68   TriggerBase& operator=(const TriggerBase&);
69 };
70
71 #endif /*SUPERTUX_INTERACTIVE_OBJECT_H*/
72
73 /* EOF */