supertux
bonus_block.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_BONUS_BLOCK_HPP
18 #define HEADER_SUPERTUX_OBJECT_BONUS_BLOCK_HPP
19 
20 #include "object/block.hpp"
21 
22 #include "supertux/direction.hpp"
23 #include "supertux/player_status.hpp"
24 
25 class Player;
26 
27 class BonusBlock final : public Block
28 {
29 public:
30  enum class Content {
31  COIN,
32  FIREGROW,
33  ICEGROW,
34  AIRGROW,
35  EARTHGROW,
36  RETROGROW,
37  STAR,
38  RETROSTAR,
39  ONEUP,
40  CUSTOM,
41  SCRIPT,
42  LIGHT,
43  LIGHT_ON,
44  TRAMPOLINE,
45  PORTABLE_TRAMPOLINE,
46  RAIN,
47  EXPLODE,
48  ROCK,
49  POTION
50  };
51 
52 public:
53  BonusBlock(const Vector& pos, int tile_data);
54  BonusBlock(const ReaderMapping& mapping);
55 
56  virtual void hit(Player& player) override;
57  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
58  virtual void draw(DrawingContext& context) override;
59 
60  static std::string class_name() { return "bonusblock"; }
61  virtual std::string get_class_name() const override { return class_name(); }
62  static std::string display_name() { return _("Bonus Block"); }
63  virtual std::string get_display_name() const override { return display_name(); }
64  virtual GameObjectClasses get_class_types() const override { return Block::get_class_types().add(typeid(BonusBlock)); }
65 
66  virtual ObjectSettings get_settings() override;
67  GameObjectTypes get_types() const override;
68  std::string get_default_sprite_name() const override;
69 
70  Content get_contents() const { return m_contents; }
71  int get_hit_counter() const { return m_hit_counter; }
72 
73  void try_open(Player* player);
74 
75 private:
76  void add_object(std::unique_ptr<GameObject> object);
77  void set_object(std::unique_ptr<GameObject> object);
78 
79  void on_type_change(int old_type) override;
80 
81  int get_default_hit_counter() const;
82  std::string get_default_coin_sprite() const;
83 
84  void try_drop(Player* player);
85 
86  void preload_contents(int d);
87  void raise_growup_bonus(Player* player, const BonusType& bonus, const Direction& dir,
88  const std::string& growup_sprite = "", const std::string& flower_sprite = "");
89  void drop_growup_bonus(Player* player, int type, const Direction& dir, bool& countdown,
90  const std::string& growup_sprite = "");
91 
92  BonusBlock::Content get_content_by_data(int tile_data) const;
93  BonusBlock::Content get_content_from_string(const std::string& contentstring) const;
94 
95 private:
96  enum Type {
97  BLUE,
98  ORANGE,
99  PURPLE,
100  RETRO
101  };
102 
103 private:
104  Content m_contents;
105 
109  std::vector<std::unique_ptr<GameObject>> m_objects;
110  GameObject* m_object;
111 
112  int m_hit_counter;
113  std::string m_script;
114  SurfacePtr m_lightsprite;
115  std::string m_coin_sprite;
116 
117 private:
118  BonusBlock(const BonusBlock&) = delete;
119  BonusBlock& operator=(const BonusBlock&) = delete;
120 };
121 
122 #endif
123 
124 /* EOF */
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: bonus_block.hpp:63
Definition: object_settings.hpp:39
GameObjectTypes get_types() const override
Get all types of the object, if available.
Definition: bonus_block.cpp:169
Definition: bonus_block.hpp:27
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: bonus_block.cpp:682
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
this function is called when the object collided with any other object
Definition: bonus_block.cpp:293
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: bonus_block.hpp:64
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
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