supertux
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 
22 #include "sprite/sprite_ptr.hpp"
23 #include "supertux/moving_object.hpp"
24 #include "supertux/object_remove_listener.hpp"
25 
26 class Player;
27 
31 class TriggerBase : public MovingObject,
33 {
34 public:
35  enum EventType {
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 
51  virtual void event(Player& player, EventType type) = 0;
52 
54  virtual void object_removed(GameObject* object) override;
55 
56 private:
57  SpritePtr m_sprite;
58  bool m_lasthit;
59  bool m_hit;
60 
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 */
Object came into contact.
Definition: trigger_base.hpp:36
virtual void update(float dt_sec) override
This function is called once per frame and allows the object to update it&#39;s state.
Definition: trigger_base.cpp:51
EventType
Definition: trigger_base.hpp:35
Definition: object_remove_listener.hpp:22
virtual void object_removed(GameObject *object) override
Called by GameObject destructor of an object in losetouch_listeners.
Definition: trigger_base.cpp:90
Action button pressed.
Definition: trigger_base.hpp:38
Base class for all the things that make up Levels&#39; Sectors.
Definition: game_object.hpp:46
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: trigger_base.cpp:65
Lost contact with object.
Definition: trigger_base.hpp:37
virtual void event(Player &player, EventType type)=0
Receive trigger events.
Base class for all dynamic/moving game objects.
Definition: moving_object.hpp:31
This class is the base class for all objects you can interact with in some way.
Definition: trigger_base.hpp:31
Definition: reader_mapping.hpp:31
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
this function is called when the object collided with any other object
Definition: trigger_base.cpp:74
Definition: player.hpp:39
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
This class collects data about a collision.
Definition: collision_hit.hpp:44