supertux
bumper.hpp
1 // Copyright (C) 2020 Daniel Ward <weluvgoatz@gmail.com>
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
15 
16 #ifndef HEADER_SUPERTUX_OBJECT_BUMPER_HPP
17 #define HEADER_SUPERTUX_OBJECT_BUMPER_HPP
18 
19 #include "object/sticky_object.hpp"
20 
21 #include "supertux/physic.hpp"
22 
23 enum class Direction;
24 class Player;
25 
26 class Bumper final : public StickyObject
27 {
28 public:
29  Bumper(const ReaderMapping& reader);
30 
31  virtual ObjectSettings get_settings() override;
32 
33  virtual void update(float dt_sec) override;
34  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
35 
36  static std::string class_name() { return "bumper"; }
37  virtual std::string get_class_name() const override { return class_name(); }
38  static std::string display_name() { return _("Bumper"); }
39  virtual std::string get_display_name() const override { return display_name(); }
40  virtual GameObjectClasses get_class_types() const override { return StickyObject::get_class_types().add(typeid(Bumper)); }
41 
42  virtual void after_editor_set() override;
43  virtual void on_flip(float height) override;
44 
45  Physic& get_physic();
46 
47  void bounce();
48 
49 private:
50  Physic m_physic;
51 
52  Direction m_dir;
53  Vector m_original_pos;
54 
55 private:
56  Bumper(const Bumper&) = delete;
57  Bumper& operator=(const Bumper&) = delete;
58 };
59 
60 #endif
61 
62 /* EOF */
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: bumper.hpp:39
virtual void on_flip(float height) override
When level is flipped vertically.
Definition: bumper.cpp:139
Physics engine.
Definition: physic.hpp:27
Definition: bumper.hpp:26
Definition: object_settings.hpp:39
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: bumper.cpp:63
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: bumper.cpp:97
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: sticky_object.hpp:34
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
Definition: reader_mapping.hpp:32
This is a class for MovingSprites that can stick to the sides, top and bottom of MovingObjects, such as platforms, fallblock, tilemap, etc.
Definition: sticky_object.hpp:27
This module contains methods controlling the player.
Definition: player.hpp:47
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: bumper.hpp:40
This class collects data about a collision.
Definition: collision_hit.hpp:44