supertux
explosion.hpp
1 // SuperTux -- Explosion object
2 // Copyright (C) 2007 Christoph Sommer <christoph.sommer@2007.expires.deltadevelopment.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_OBJECT_EXPLOSION_HPP
18 #define HEADER_SUPERTUX_OBJECT_EXPLOSION_HPP
19 
20 #include "object/moving_sprite.hpp"
21 
22 #define EXPLOSION_STRENGTH_DEFAULT (1464.8f * 32.0f * 32.0f)
23 #define EXPLOSION_STRENGTH_NEAR (1000.f * 32.0f * 32.0f)
24 
26 class Explosion final : public MovingSprite
27 {
28 public:
30  Explosion(const Vector& pos, float push_strength, int num_particles=100, bool short_fuse = false);
31  Explosion(const ReaderMapping& reader);
32 
33  static std::string class_name() { return "explosion"; }
34  virtual std::string get_class_name() const override { return class_name(); }
35  static std::string display_name() { return _("Explosion"); }
36  virtual std::string get_display_name() const override { return display_name(); }
37  virtual GameObjectClasses get_class_types() const override { return MovingSprite::get_class_types().add(typeid(Explosion)); }
38 
39  virtual void update(float dt_sec) override;
40  virtual void draw(DrawingContext& context) override;
41  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
42  virtual bool is_saveable() const override { return false; }
43 
44  bool hurts() const { return hurt; }
45  void hurts (bool val) { hurt = val; }
46 
47 private:
49  void explode();
50 
51 private:
52  enum State {
53  STATE_WAITING,
54  STATE_EXPLODING
55  };
56 
57 private:
58  bool hurt;
59  float push_strength;
60  int num_particles;
61  State state;
62  SpritePtr lightsprite;
63  bool short_fuse;
64 
65 private:
66  Explosion(const Explosion&) = delete;
67  Explosion& operator=(const Explosion&) = delete;
68 };
69 
70 #endif
71 
72 /* EOF */
Just your average explosion - goes boom, hurts Tux.
Definition: explosion.hpp:26
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: explosion.cpp:152
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
this function is called when the object collided with any other object
Definition: explosion.cpp:174
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: explosion.hpp:36
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 draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: explosion.cpp:167
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: explosion.hpp:37
Explosion(const Vector &pos, float push_strength, int num_particles=100, bool short_fuse=false)
Create new Explosion centered(!) at pos.
Definition: explosion.cpp:34
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
Definition: reader_mapping.hpp:32
Abstract base class for ""MovingObject""s, that are represented by a sprite.
Definition: moving_sprite.hpp:33
virtual bool is_saveable() const override
Indicates if the object will be saved.
Definition: explosion.hpp:42
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