supertux
coin.hpp
1 // SuperTux
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.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_COIN_HPP
18 #define HEADER_SUPERTUX_OBJECT_COIN_HPP
19 
20 #include "object/path_object.hpp"
21 #include "object/moving_sprite.hpp"
22 #include "supertux/physic.hpp"
23 
24 class Path;
25 class PathWalker;
26 class TileMap;
27 
28 class Coin : public MovingSprite,
29  public PathObject
30 {
31  friend class HeavyCoin;
32 
33 public:
34  Coin(const Vector& pos, bool count_stats = true,
35  const std::string& sprite_path = "images/objects/coin/coin.sprite");
36  Coin(const ReaderMapping& reader, bool count_stats = true);
37  virtual void finish_construction() override;
38 
39  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
40 
41  virtual void update(float dt_sec) override;
42  static std::string class_name() { return "coin"; }
43  virtual std::string get_class_name() const override { return class_name(); }
44  static std::string display_name() { return _("Coin"); }
45  virtual std::string get_display_name() const override { return display_name(); }
46  virtual GameObjectClasses get_class_types() const override { return MovingSprite::get_class_types().add(typeid(PathObject)).add(typeid(Coin)); }
47 
48  virtual ObjectSettings get_settings() override;
49  GameObjectTypes get_types() const override;
50  std::string get_default_sprite_name() const override;
51 
52  virtual void after_editor_set() override;
53  virtual void editor_update() override;
54 
55  void save_state() override;
56  void check_state() override;
57 
58  virtual void move_to(const Vector& pos) override;
59 
60  virtual void on_flip(float height) override;
61 
62  void collect();
63 
64 private:
65  enum Type {
66  NORMAL,
67  RETRO
68  };
69 
70 private:
71  Vector m_offset;
72  bool m_from_tilemap;
73  bool m_add_path;
74  Physic m_physic;
75  std::string m_collect_script;
76 
77  int m_starting_node;
78 
79  const bool m_count_stats;
80 
81 private:
82  Coin(const Coin&) = delete;
83  Coin& operator=(const Coin&) = delete;
84 };
85 
86 class HeavyCoin final : public Coin
87 {
88 public:
89  HeavyCoin(const Vector& pos, const Vector& init_velocity, bool count_stats = true,
90  const std::string& sprite_path = "images/objects/coin/coin.sprite");
91  HeavyCoin(const ReaderMapping& reader, bool count_stats = true);
92 
93  virtual void update(float dt_sec) override;
94  virtual void collision_solid(const CollisionHit& hit) override;
95 
96  static std::string class_name() { return "heavycoin"; }
97  virtual std::string get_class_name() const override { return class_name(); }
98  static std::string display_name() { return _("Heavy Coin"); }
99  virtual std::string get_display_name() const override { return display_name(); }
100  virtual GameObjectClasses get_class_types() const override { return Coin::get_class_types().add(typeid(HeavyCoin)); }
101 
102  virtual ObjectSettings get_settings() override;
103  virtual void after_editor_set() override;
104 
105  virtual void on_flip(float height) override;
106 
107 private:
108  Physic m_physic;
109  CollisionHit m_last_hit;
110 
111 private:
112  HeavyCoin(const HeavyCoin&) = delete;
113  HeavyCoin& operator=(const HeavyCoin&) = delete;
114 };
115 
116 #endif
117 
118 /* EOF */
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: coin.hpp:100
GameObjectTypes get_types() const override
Get all types of the object, if available.
Definition: coin.cpp:66
A walker that travels along a path.
Definition: path_walker.hpp:31
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: coin.hpp:45
virtual void editor_update() override
Called each frame in the editor, used to keep linked objects together (e.g.
Definition: coin.cpp:124
virtual void collision_solid(const CollisionHit &) override
this function is called when the object collided with something solid
Definition: moving_object.hpp:51
Physics engine.
Definition: physic.hpp:27
Definition: object_settings.hpp:39
void save_state() override
Save/check the current state of the object.
Definition: coin.cpp:144
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
this function is called when the object collided with any other object
Definition: coin.cpp:237
virtual void finish_construction() override
Called after all objects have been added to the Sector and the Sector is fully constructed.
Definition: coin.cpp:87
Definition: path.hpp:48
Definition: coin.hpp:28
Definition: coin.hpp:86
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: moving_sprite.hpp:60
virtual void on_flip(float height) override
When level is flipped vertically.
Definition: coin.cpp:359
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
A base class for all objects that contain, or make use of a path.
Definition: path_object.hpp:36
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
This class is responsible for managing an array of tiles.
Definition: tilemap.hpp:49
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: coin.cpp:102
Abstract base class for ""MovingObject""s, that are represented by a sprite.
Definition: moving_sprite.hpp:33
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: coin.hpp:99
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: coin.hpp:46
This class collects data about a collision.
Definition: collision_hit.hpp:44