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 |
19 | |
20 | #include <list> |
21 | |
22 | #include "sprite/sprite_ptr.hpp" |
23 | #include "supertux/moving_object.hpp" |
24 | #include "supertux/object_remove_listener.hpp" |
25 | |
26 | class Player; |
27 | |
28 | /** This class is the base class for all objects you can interact with |
29 | in some way. There are several interaction types defined like |
30 | touch and activate */ |
31 | class TriggerBase : public MovingObject, |
32 | public ObjectRemoveListener |
33 | { |
34 | public: |
35 | enum EventType { |
36 | EVENT_TOUCH, /**< Object came into contact */ |
37 | EVENT_LOSETOUCH, /**< Lost contact with object */ |
38 | EVENT_ACTIVATE /**< Action button pressed */ |
39 | }; |
40 | |
41 | public: |
42 | TriggerBase(const ReaderMapping& mapping); |
43 | TriggerBase(); |
44 | ~TriggerBase(); |
45 | |
46 | virtual void update(float dt_sec) override; |
47 | virtual void draw(DrawingContext& context) override; |
48 | virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override; |
49 | |
50 | /** Receive trigger events */ |
51 | virtual void event(Player& player, EventType type) = 0; |
52 | |
53 | /** Called by GameObject destructor of an object in losetouch_listeners */ |
54 | virtual void object_removed(GameObject* object) override; |
55 | |
56 | private: |
57 | SpritePtr m_sprite; |
58 | bool m_lasthit; |
59 | bool m_hit; |
60 | |
61 | /** Players that will be informed when we lose touch with them */ |
62 | std::vector<Player*> m_losetouch_listeners; |
63 | |
64 | private: |
65 | TriggerBase(const TriggerBase&) = delete; |
66 | TriggerBase& operator=(const TriggerBase&) = delete; |
67 | }; |
68 | |
69 | #endif |
70 | |
71 | /* EOF */ |
72 | |