supertux
dispenser.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_BADGUY_DISPENSER_HPP
18 #define HEADER_SUPERTUX_BADGUY_DISPENSER_HPP
19 
20 #include "badguy/badguy.hpp"
21 
22 class GameObject;
23 
30 class Dispenser final : public BadGuy
31 {
32 public:
33  static void register_class(ssq::VM& vm);
34 
35 private:
36  enum DispenserType {
37  DROPPER, CANNON, POINT, GRANITO
38  };
39 
40 public:
41  Dispenser(const ReaderMapping& reader);
42 
43  virtual void draw(DrawingContext& context) override;
44  virtual void initialize() override;
49  virtual void activate() override;
54  virtual void deactivate() override;
55  virtual void active_update(float dt_sec) override;
56 
57  virtual void kill_fall() override;
58  virtual void freeze() override;
59  virtual void unfreeze(bool melt = true) override;
60  virtual bool is_freezable() const override;
61  virtual bool is_flammable() const override;
62  virtual bool always_active() const override { return true; }
63  virtual bool is_portable() const override;
64 
65  static std::string class_name() { return "dispenser"; }
66  virtual std::string get_class_name() const override { return class_name(); }
67  virtual std::string get_exposed_class_name() const override { return "Dispenser"; }
68  static std::string display_name() { return _("Dispenser"); }
69  virtual std::string get_display_name() const override { return display_name(); }
70  virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(Dispenser)); }
71 
72  virtual ObjectSettings get_settings() override;
73  virtual GameObjectTypes get_types() const override;
74  std::string get_default_sprite_name() const override;
75 
76  virtual void on_flip(float height) override;
77 
78  virtual void after_editor_set() override;
79 
80  void notify_dead() {
81  if (m_limit_dispensed_badguys) {
82  m_current_badguys--;
83  }
84  }
85 
86 protected:
87  void add_object(std::unique_ptr<GameObject> object);
88 
89  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
90  void launch_object();
91 
92  void on_type_change(int old_type) override;
93 
94 private:
95  void set_correct_action();
96  void set_correct_colgroup();
97 
98 private:
99  float m_cycle;
100  std::vector<std::unique_ptr<GameObject>> m_objects;
101  unsigned int m_next_object;
102  Timer m_dispense_timer;
103  bool m_autotarget;
104  bool m_random;
105  bool m_gravity;
106 
108  bool m_limit_dispensed_badguys;
109 
111  int m_max_concurrent_badguys;
112 
114  int m_current_badguys;
115 
116 private:
117  Dispenser(const Dispenser&) = delete;
118  Dispenser& operator=(const Dispenser&) = delete;
119 };
120 
121 #endif
122 
123 /* EOF */
Base class for moving sprites that can hurt the Player.
Definition: badguy.hpp:38
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: dispenser.hpp:69
virtual void unfreeze(bool melt=true) override
Called to unfreeze the badguy.
Definition: dispenser.cpp:331
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: badguy.hpp:71
virtual GameObjectTypes get_types() const override
Get all types of the object, if available.
Definition: dispenser.cpp:434
virtual void active_update(float dt_sec) override
called each frame when the badguy is activated.
Definition: dispenser.cpp:141
virtual void draw(DrawingContext &context) override
Called when the badguy is drawn.
Definition: dispenser.cpp:105
virtual void deactivate() override
Stops the dispenser from dispensing badguys.
Definition: dispenser.cpp:125
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
Called when a collision with another object occurred.
Definition: dispenser.cpp:131
virtual bool is_flammable() const override
Returns whether to call ignite() when a badguy gets hit by a fire bullet.
Definition: dispenser.cpp:347
Definition: object_settings.hpp:39
A ""Dispenser"" that was given a name can be controlled by scripts.
Definition: dispenser.hpp:30
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: dispenser.hpp:70
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
virtual void activate() override
Makes the dispenser start dispensing badguys.
Definition: dispenser.cpp:118
virtual void on_flip(float height) override
When level is flipped vertically.
Definition: dispenser.cpp:459
virtual void kill_fall() override
Set the badguy to kill/falling state, which makes him falling of the screen (his sprite is turned ups...
Definition: dispenser.cpp:177
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 void freeze() override
Called when hit by an ice bullet, and is_freezable() returns true.
Definition: dispenser.cpp:298
virtual void initialize() override
called immediately before the first call to initialize
Definition: dispenser.cpp:112
Simple timer designed to be used in the update functions of objects.
Definition: timer.hpp:24
Definition: reader_mapping.hpp:32
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