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 "object/sticky_object.hpp"
21 #include "supertux/moving_object.hpp"
22 #include "supertux/object_remove_listener.hpp"
23 
24 #include <vector>
25 
26 class Player;
27 
32 {
33 public:
34  enum EventType {
38  };
39 
40 public:
41  TriggerBase();
42  ~TriggerBase() override;
43 
45  virtual void event(Player& player, EventType type) = 0;
46 
48  virtual void object_removed(GameObject* object) override;
49 
50 protected:
51  void update();
52  HitResponse collision(GameObject& other, const CollisionHit& hit);
53 
54 private:
55  std::vector<Player*> m_hit;
56 
58  std::vector<Player*> m_losetouch_listeners;
59 
60 private:
61  TriggerBase(const TriggerBase&) = delete;
62  TriggerBase& operator=(const TriggerBase&) = delete;
63 };
64 
65 
66 class Trigger : public MovingObject,
67  public TriggerBase
68 {
69 public:
70  Trigger(const ReaderMapping& reader);
71  virtual GameObjectClasses get_class_types() const override { return MovingObject::get_class_types().add(typeid(TriggerBase)).add(typeid(Trigger)); }
72 
73  virtual void update(float) override
74  {
75  TriggerBase::update();
76  }
77  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override
78  {
79  return TriggerBase::collision(other, hit);
80  }
81 
82  int get_layer() const override { return LAYER_TILES + 1; }
83 
84 private:
85  Trigger(const Trigger&) = delete;
86  Trigger& operator=(const Trigger&) = delete;
87 };
88 
89 
91  public TriggerBase
92 {
93 public:
94  SpritedTrigger(const ReaderMapping& reader, const std::string& sprite_name);
95  virtual GameObjectClasses get_class_types() const override { return MovingSprite::get_class_types().add(typeid(TriggerBase)).add(typeid(SpritedTrigger)); }
96 
97  virtual void update(float) override
98  {
99  TriggerBase::update();
100  }
101  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override
102  {
103  return TriggerBase::collision(other, hit);
104  }
105 
106 private:
107  SpritedTrigger(const SpritedTrigger&) = delete;
108  SpritedTrigger& operator=(const SpritedTrigger&) = delete;
109 };
110 
111 
113  public TriggerBase
114 {
115 public:
116  StickyTrigger(const ReaderMapping& reader, const std::string& sprite_name);
117  virtual GameObjectClasses get_class_types() const override { return StickyObject::get_class_types().add(typeid(TriggerBase)).add(typeid(StickyTrigger)); }
118 
119  virtual void update(float dt_sec) override
120  {
121  StickyObject::update(dt_sec);
122  TriggerBase::update();
123  }
124  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override
125  {
126  return TriggerBase::collision(other, hit);
127  }
128 
129 private:
130  StickyTrigger(const StickyTrigger&) = delete;
131  StickyTrigger& operator=(const StickyTrigger&) = delete;
132 };
133 
134 #endif
135 
136 /* EOF */
virtual void update(float) override
This function is called once per frame and allows the object to update it&#39;s state.
Definition: trigger_base.hpp:73
Object came into contact.
Definition: trigger_base.hpp:35
virtual void update(float) override
This function is called once per frame and allows the object to update it&#39;s state.
Definition: trigger_base.hpp:97
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
this function is called when the object collided with any other object
Definition: trigger_base.hpp:101
EventType
Definition: trigger_base.hpp:34
Definition: object_remove_listener.hpp:22
Definition: trigger_base.hpp:90
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
this function is called when the object collided with any other object
Definition: trigger_base.hpp:77
virtual void object_removed(GameObject *object) override
Called by GameObject destructor of an object in losetouch_listeners.
Definition: trigger_base.cpp:71
Definition: collision.cpp:24
Action button pressed.
Definition: trigger_base.hpp:37
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: trigger_base.hpp:71
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.hpp:119
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
this function is called when the object collided with any other object
Definition: trigger_base.hpp:124
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: trigger_base.hpp:95
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: moving_sprite.hpp:60
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
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: sticky_object.cpp:44
Lost contact with object.
Definition: trigger_base.hpp:36
virtual void event(Player &player, EventType type)=0
Receive trigger events.
Base class for all dynamic/moving game objects.
Definition: moving_object.hpp:35
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: sticky_object.hpp:34
This class is the base class for all objects you can interact with in some way.
Definition: trigger_base.hpp:31
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: moving_object.hpp:49
A helper structure to list all the type_indexes of the classes in the type hierarchy of a given class...
Definition: game_object.hpp:57
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: trigger_base.hpp:117
Definition: trigger_base.hpp:112
Definition: trigger_base.hpp:66
Definition: reader_mapping.hpp:32
This is a class for MovingSprites that can stick to the sides, top and bottom of MovingObjects, such as platforms, fallblock, tilemap, etc.
Definition: sticky_object.hpp:27
Abstract base class for ""MovingObject""s, that are represented by a sprite.
Definition: moving_sprite.hpp:33
This module contains methods controlling the player.
Definition: player.hpp:47
This class collects data about a collision.
Definition: collision_hit.hpp:44