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 #include "scripting/dispenser.hpp"
22 #include "squirrel/exposed_object.hpp"
23 
24 class Dispenser final : public BadGuy,
25  public ExposedObject<Dispenser, scripting::Dispenser>
26 {
27 private:
28  enum class DispenserType {
29  DROPPER, ROCKETLAUNCHER, CANNON, POINT
30  };
31 
32  static DispenserType DispenserType_from_string(const std::string& type_string);
33  static std::string DispenserType_to_string(DispenserType type);
34 
35 public:
36  Dispenser(const ReaderMapping& reader);
37 
38  virtual void draw(DrawingContext& context) override;
39  virtual void activate() override;
40  virtual void deactivate() override;
41  virtual void active_update(float dt_sec) override;
42 
43  virtual void freeze() override;
44  virtual void unfreeze() override;
45  virtual bool is_freezable() const override;
46  virtual bool is_flammable() const override;
47  virtual std::string get_class() const override { return "dispenser"; }
48  virtual std::string get_display_name() const override { return _("Dispenser"); }
49 
50  virtual ObjectSettings get_settings() override;
51  virtual void after_editor_set() override;
52 
53  void notify_dead() {
54  if (m_limit_dispensed_badguys) {
55  m_current_badguys--;
56  }
57  }
58 
59 protected:
60  virtual bool collision_squished(GameObject& object) override;
61  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
62  void launch_badguy();
63 
64 private:
65  void set_correct_action();
66 
67 private:
68  float m_cycle;
69  std::vector<std::string> m_badguys;
70  unsigned int m_next_badguy;
71  Timer m_dispense_timer;
72  bool m_autotarget;
73  bool m_swivel;
74  bool m_broken;
75  bool m_random;
76 
77  DispenserType m_type;
78  std::string m_type_str;
79 
81  bool m_limit_dispensed_badguys;
82 
84  int m_max_concurrent_badguys;
85 
87  int m_current_badguys;
88 
89 private:
90  Dispenser(const Dispenser&) = delete;
91  Dispenser& operator=(const Dispenser&) = delete;
92 };
93 
94 #endif
95 
96 /* EOF */
Base class for moving sprites that can hurt the Player.
Definition: badguy.hpp:31
virtual bool collision_squished(GameObject &object) override
Called when the player hit the badguy from above.
Definition: dispenser.cpp:178
virtual void active_update(float dt_sec) override
called each frame when the badguy is activated.
Definition: dispenser.cpp:227
virtual void draw(DrawingContext &context) override
Called when the badguy is drawn.
Definition: dispenser.cpp:146
virtual void deactivate() override
called when the badguy has been deactivated
Definition: dispenser.cpp:171
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
Called when a collision with another object occurred.
Definition: dispenser.cpp:203
This class binds a certain GameObject class to a scripting class.
Definition: exposed_object.hpp:45
virtual bool is_flammable() const override
Returns whether to call ignite() when a badguy gets hit by a fire bullet.
Definition: dispenser.cpp:408
Definition: object_settings.hpp:35
Definition: dispenser.hpp:24
virtual void unfreeze() override
Called to unfreeze the badguy.
Definition: dispenser.cpp:389
Base class for all the things that make up Levels&#39; Sectors.
Definition: game_object.hpp:46
virtual void activate() override
called when the badguy has been activated.
Definition: dispenser.cpp:154
virtual void freeze() override
Called when hit by an ice bullet, and is_freezable() returns true.
Definition: dispenser.cpp:353
Simple timer designed to be used in the update functions of objects.
Definition: timer.hpp:24
Definition: reader_mapping.hpp:31
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