supertux
particle_zone.hpp
1 // SuperTux - Particle zone : Spawn
2 // Copyright (C) 2020 A. Semphris <semphris@protonmail.com>
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_OBJECT_PARTICLE_ZONE_HPP
18 #define HEADER_SUPERTUX_OBJECT_PARTICLE_ZONE_HPP
19 
20 #include "supertux/moving_object.hpp"
21 
22 #include "video/layer.hpp"
23 
25 class ParticleZone final : public MovingObject
26 {
27  // TODO: Scripting interface
28 
29 public:
30  ParticleZone(const ReaderMapping& reader);
31 
32  virtual void update(float dt_sec) override;
33  virtual void draw(DrawingContext& context) override;
34 
35  virtual bool has_variable_size() const override { return true; }
36  static std::string class_name() { return "particle-zone"; }
37  virtual std::string get_class_name() const override { return class_name(); }
38  static std::string display_name() { return _("Particle zone"); }
39  virtual std::string get_display_name() const override { return display_name(); }
40  virtual GameObjectClasses get_class_types() const override { return MovingObject::get_class_types().add(typeid(ParticleZone)); }
41  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
42 
43  virtual ObjectSettings get_settings() override;
44  virtual GameObjectTypes get_types() const override;
45 
46  virtual int get_layer() const override { return LAYER_OBJECTS; }
47 
48  Rectf get_rect() {return m_col.m_bbox;}
49 
61  };
62 
67  void set_enabled(bool enabled) {m_enabled = enabled;}
68 
70  bool get_enabled() const {return m_enabled;}
71 
73  void set_particle_name(std::string& particle_name) {m_particle_name = particle_name;}
74 
76  const std::string& get_particle_name() const { return m_particle_name; }
77 
81  //void displace(int x, int y, float time, std::string easing);
82 
86  //void resize(int width, int height, float time, std::string easing);
87 
89  float current_x() const { return m_col.m_bbox.get_left(); }
90 
92  float current_y() const { return m_col.m_bbox.get_top(); }
93 
95  //float target_x() {return m_col.m_bbox.get_left();}
96 
98  //float target_y() {return m_col.m_bbox.get_left();}
99 
102  class ZoneDetails {
103  public:
104  std::string m_particle_name;
105  ParticleZoneType m_type;
106  Rectf m_rect;
107 
108  ZoneDetails(std::string name, ParticleZoneType type, const Rectf& rect) :
109  m_particle_name(std::move(name)),
110  m_type(type),
111  m_rect(rect)
112  {
113  }
114 
115  Rectf get_rect() const {return m_rect;}
116  ParticleZoneType get_type() const {return m_type;}
117  const std::string& get_particle_name() const {return m_particle_name;}
118  };
119 
120  ZoneDetails get_details() {
121  return ZoneDetails(m_particle_name, static_cast<ParticleZoneType>(m_type), m_col.m_bbox);
122  }
123 
124 private:
125  bool m_enabled;
126  std::string m_particle_name;
127 
128 private:
129  ParticleZone(const ParticleZone&) = delete;
130  ParticleZone& operator=(const ParticleZone&) = delete;
131 };
132 
133 #endif
134 
135 /* EOF */
void set_enabled(bool enabled)
Sets whether or not particles can spawn in this area.
Definition: particle_zone.hpp:67
Defines an area where a certain particle type can spawn.
Definition: particle_zone.hpp:25
Particles will disappear instantly if they leave this area.
Definition: particle_zone.hpp:56
Particles will spawn in this area.
Definition: particle_zone.hpp:52
Particles will die if they leave this area.
Definition: particle_zone.hpp:54
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: particle_zone.hpp:40
float current_y() const
Returns the current Y position of the zone.
Definition: particle_zone.hpp:92
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: particle_zone.hpp:39
float current_x() const
Move the area around.
Definition: particle_zone.hpp:89
Definition: object_settings.hpp:39
Rectf m_bbox
The bounding box of the object (as used for collision detection, this isn&#39;t necessarily the bounding ...
Definition: collision_object.hpp:150
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
this function is called when the object collided with any other object
Definition: particle_zone.cpp:111
Definition: rectf.hpp:31
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: particle_zone.cpp:77
const std::string & get_particle_name() const
Returns the name of the particle object for this area.
Definition: particle_zone.hpp:76
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
Particles will start dying if they touch this area.
Definition: particle_zone.hpp:58
Particles will disappear instantly if they touch this area.
Definition: particle_zone.hpp:60
Base class for all dynamic/moving game objects.
Definition: moving_object.hpp:35
ParticleZoneType
Definition: particle_zone.hpp:50
bool get_enabled() const
Returns whether or not particles can spawn in this area.
Definition: particle_zone.hpp:70
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: moving_object.hpp:49
void set_particle_name(std::string &particle_name)
Sets the name of the particle object for this area.
Definition: particle_zone.hpp:73
virtual GameObjectTypes get_types() const override
Get all types of the object, if available.
Definition: particle_zone.cpp:58
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
Returns the target X position of the zone.
Definition: particle_zone.hpp:102
Definition: reader_mapping.hpp:32
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: particle_zone.cpp:70
virtual bool has_variable_size() const override
Does this object have variable size (secret area trigger, wind, etc.)
Definition: particle_zone.hpp:35
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