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 
32 friend class HeavyCoin;
33 
34 public:
35  Coin(const Vector& pos);
36  Coin(const ReaderMapping& reader);
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  virtual std::string get_class() const override { return "coin"; }
43  virtual std::string get_display_name() const override { return _("Coin"); }
44 
45  virtual ObjectSettings get_settings() override;
46  virtual void after_editor_set() override;
47  virtual void editor_update() override;
48 
49  virtual void move_to(const Vector& pos) override;
50 
51  void collect();
52 
53 private:
54  Vector m_offset;
55  bool m_from_tilemap;
56  bool m_add_path;
57  Physic m_physic;
58  std::string m_collect_script;
59 
60 private:
61  Coin(const Coin&) = delete;
62  Coin& operator=(const Coin&) = delete;
63 };
64 
65 class HeavyCoin final : public Coin
66 {
67 public:
68  HeavyCoin(const Vector& pos, const Vector& init_velocity);
69  HeavyCoin(const ReaderMapping& reader);
70 
71  virtual void update(float dt_sec) override;
72  virtual void collision_solid(const CollisionHit& hit) override;
73 
74  virtual std::string get_class() const override { return "heavycoin"; }
75  virtual std::string get_display_name() const override { return _("Heavy coin"); }
76 
77  virtual ObjectSettings get_settings() override;
78  virtual void after_editor_set() override;
79 
80 private:
81  Physic m_physic;
82 
83 private:
84  HeavyCoin(const HeavyCoin&) = delete;
85  HeavyCoin& operator=(const HeavyCoin&) = delete;
86 };
87 
88 #endif
89 
90 /* EOF */
A walker that travels along a path.
Definition: path_walker.hpp:29
virtual void editor_update() override
Called each frame in the editor, used to keep linked objects together (e.g.
Definition: coin.cpp:93
virtual void collision_solid(const CollisionHit &) override
this function is called when the object collided with something solid
Definition: moving_object.hpp:42
Simple two dimensional vector.
Definition: vector.hpp:24
Physics engine.
Definition: physic.hpp:27
Definition: object_settings.hpp:35
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
this function is called when the object collided with any other object
Definition: coin.cpp:183
virtual void finish_construction() override
Called after all objects have been added to the Sector and the Sector is fully constructed.
Definition: coin.cpp:59
Definition: path.hpp:44
Definition: coin.hpp:28
Definition: coin.hpp:65
Base class for all the things that make up Levels&#39; Sectors.
Definition: game_object.hpp:46
A class for all objects that contain / make use of a path.
Definition: path_object.hpp:28
This class is responsible for drawing the level tiles.
Definition: tilemap.hpp:39
Definition: reader_mapping.hpp:31
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:71
Abstract base class for MovingObjects that are represented by a Sprite.
Definition: moving_sprite.hpp:29
This class collects data about a collision.
Definition: collision_hit.hpp:44