supertux
brick.hpp
1 // SuperTux
2 // Copyright (C) 2009 Ingo Ruhnke <grumbel@gmail.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_BRICK_HPP
18 #define HEADER_SUPERTUX_OBJECT_BRICK_HPP
19 
20 #include "object/block.hpp"
21 
22 class Crusher;
23 
24 class Brick : public Block
25 {
26 public:
27  Brick(const Vector& pos, int data, const std::string& sprite_name);
28  Brick(const ReaderMapping& mapping, const std::string& sprite_name = "images/objects/bonus_block/brick.sprite");
29 
30  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
31  virtual ObjectSettings get_settings() override;
32  static std::string class_name() { return "brick"; }
33  virtual std::string get_class_name() const override { return class_name(); }
34  static std::string display_name() { return _("Brick"); }
35  virtual std::string get_display_name() const override { return display_name(); }
36  virtual GameObjectClasses get_class_types() const override { return Block::get_class_types().add(typeid(Brick)); }
37 
38  GameObjectTypes get_types() const override;
39  std::string get_default_sprite_name() const override;
40 
41  void try_break(Player* player, bool slider = false);
42  void break_for_crusher(Crusher* crusher);
43 
44 protected:
45  virtual void hit(Player& player) override;
46 
47 private:
48  enum Type {
49  NORMAL,
50  RETRO
51  };
52 
53 private:
54  bool m_breakable;
55  int m_coin_counter;
56 
57 private:
58  Brick(const Brick&) = delete;
59  Brick& operator=(const Brick&) = delete;
60 };
61 
62 class HeavyBrick : public Brick
63 {
64 public:
65  HeavyBrick(const Vector& pos, int data, const std::string& spriteName);
66  HeavyBrick(const ReaderMapping& mapping);
67 
68  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
69  static std::string class_name() { return "heavy-brick"; }
70  virtual std::string get_class_name() const override { return class_name(); }
71  static std::string display_name() { return _("Heavy Brick"); }
72  virtual std::string get_display_name() const override { return display_name(); }
73  virtual GameObjectClasses get_class_types() const override { return Brick::get_class_types().add(typeid(HeavyBrick)); }
74 
75  GameObjectTypes get_types() const override { return {}; }
76 
77 protected:
78  virtual void hit(Player& player) override;
79 
80 private:
81  void ricochet(GameObject* collider);
82 
83 private:
84  HeavyBrick(const HeavyBrick&) = delete;
85  HeavyBrick& operator=(const HeavyBrick&) = delete;
86 };
87 
88 #endif
89 
90 /* EOF */
Definition: brick.hpp:24
GameObjectTypes get_types() const override
Get all types of the object, if available.
Definition: brick.cpp:56
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: brick.hpp:72
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: brick.hpp:36
Definition: object_settings.hpp:39
This class is the base class for crushers that tux can stand on.
Definition: crusher.hpp:26
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
this function is called when the object collided with any other object
Definition: brick.cpp:86
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: brick.hpp:35
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
GameObjectTypes get_types() const override
Get all types of the object, if available.
Definition: brick.hpp:75
Definition: brick.hpp:62
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 GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: block.hpp:33
Definition: reader_mapping.hpp:32
This module contains methods controlling the player.
Definition: player.hpp:47
Definition: block.hpp:25
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: brick.hpp:73
This class collects data about a collision.
Definition: collision_hit.hpp:44