supertux
mrbomb.hpp
1 // SuperTux
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 // Copyright (C) 2024 MatusGuy <matusguy@supertuxproject.org>
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 #ifndef HEADER_SUPERTUX_BADGUY_MRBOMB_HPP
19 #define HEADER_SUPERTUX_BADGUY_MRBOMB_HPP
20 
21 #include "badguy/walking_badguy.hpp"
22 
23 class SoundSource;
24 
25 class MrBomb : public WalkingBadguy
26 {
27 public:
28  MrBomb(const ReaderMapping& reader);
29  MrBomb(const ReaderMapping& reader, const std::string& sprite,
30  const std::string& glow_sprite = "images/creatures/mr_bomb/ticking_glow/ticking_glow.sprite");
31 
32  virtual void collision_solid(const CollisionHit& hit) override;
33  virtual HitResponse collision(GameObject& object, const CollisionHit& hit) override;
34  virtual HitResponse collision_player(Player& player, const CollisionHit& hit) override;
35  virtual HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit) override;
36 
37  virtual void active_update(float dt_sec) override;
38  virtual void draw(DrawingContext& context) override;
39 
40  virtual void grab(MovingObject& object, const Vector& pos, Direction dir) override;
41  virtual void ungrab(MovingObject& object, Direction dir) override;
42  virtual bool is_portable() const override;
43 
44  virtual void freeze() override;
45  virtual bool is_freezable() const override;
46 
47  bool is_ticking() const { return m_state == MB_STATE_TICKING; }
48  virtual void trigger(Player* player);
49  virtual void explode();
50 
51  virtual void kill_fall() override;
52  virtual void ignite() override;
53  static std::string class_name() { return "mrbomb"; }
54  virtual std::string get_class_name() const override { return class_name(); }
55  static std::string display_name() { return _("Mr. Bomb"); }
56  virtual std::string get_display_name() const override { return display_name(); }
57  virtual GameObjectClasses get_class_types() const override { return WalkingBadguy::get_class_types().add(typeid(MrBomb)); }
58  virtual bool is_snipable() const override { return true; }
59 
60  virtual void stop_looping_sounds() override;
61  virtual void play_looping_sounds() override;
62 
63 protected:
64  void update_ticking(float dt_sec);
65 
66  virtual bool collision_squished(GameObject& object) override;
67 
68 protected:
69  enum State : uint8_t {
70  MB_STATE_NORMAL,
71  MB_STATE_TICKING,
72 
73  MB_STATE_COUNT
74  };
75 
76  uint8_t m_state;
77 
78  std::unique_ptr<SoundSource> m_ticking_sound;
79  SpritePtr m_exploding_sprite;
80 
81 private:
82  MrBomb(const MrBomb&) = delete;
83  MrBomb& operator=(const MrBomb&) = delete;
84 };
85 
86 #endif
87 
88 /* 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: mrbomb.hpp:56
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: walking_badguy.hpp:55
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: mrbomb.hpp:57
virtual void draw(DrawingContext &context) override
Called when the badguy is drawn.
Definition: mrbomb.cpp:151
Base class for Badguys that walk on the floor.
Definition: walking_badguy.hpp:25
virtual HitResponse collision_badguy(BadGuy &badguy, const CollisionHit &hit) override
Called when the badguy collided with another badguy.
Definition: mrbomb.cpp:108
virtual bool collision_squished(GameObject &object) override
Called when the player hit the badguy from above.
Definition: mrbomb.cpp:121
virtual void collision_solid(const CollisionHit &hit) override
Called when the badguy collided with solid ground.
Definition: mrbomb.cpp:61
virtual bool is_snipable() const override
Can enemy be sniped by sliding or swimboosting Tux? Returns false if enemy is spiky or too large...
Definition: mrbomb.hpp:58
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
Definition: mrbomb.hpp:25
Base class for all dynamic/moving game objects.
Definition: moving_object.hpp:35
virtual void play_looping_sounds() override
continues all looping sounds
Definition: mrbomb.cpp:320
A sound source represents the source of audio output.
Definition: sound_source.hpp:25
virtual void grab(MovingObject &object, const Vector &pos, Direction dir) override
called each frame when the object has been grabbed.
Definition: mrbomb.cpp:227
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 stop_looping_sounds() override
stops all looping sounds
Definition: mrbomb.cpp:312
virtual HitResponse collision_player(Player &player, const CollisionHit &hit) override
Called when the badguy collided with a player.
Definition: mrbomb.cpp:94
virtual HitResponse collision(GameObject &object, const CollisionHit &hit) override
Called when a collision with another object occurred.
Definition: mrbomb.cpp:77
Definition: reader_mapping.hpp:32
virtual void freeze() override
Called when hit by an ice bullet, and is_freezable() returns true.
Definition: mrbomb.cpp:291
This module contains methods controlling the player.
Definition: player.hpp:47
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
virtual void active_update(float dt_sec) override
called each frame when the badguy is activated.
Definition: mrbomb.cpp:139
This class collects data about a collision.
Definition: collision_hit.hpp:44
virtual void ignite() override
Kills the badguy by igniting it.
Definition: mrbomb.cpp:219
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: mrbomb.cpp:194