supertux
fallblock.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_FALLBLOCK_HPP
17 #define HEADER_SUPERTUX_OBJECT_FALLBLOCK_HPP
18 
19 #include "object/moving_sprite.hpp"
20 
21 #include "supertux/physic.hpp"
22 #include "supertux/timer.hpp"
23 
24 class Player;
25 
26 class FallBlock : public MovingSprite
27 
28 {
29 public:
30  FallBlock(const ReaderMapping& reader);
31 
32  virtual void update(float dt_sec) override;
33 
34  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
35  virtual void collision_solid(const CollisionHit& hit) override;
36 
37  virtual void draw(DrawingContext& context) override;
38 
39  static std::string class_name() { return "fallblock"; }
40  virtual std::string get_class_name() const override { return class_name(); }
41  static std::string display_name() { return _("Falling Platform"); }
42  virtual std::string get_display_name() const override { return display_name(); }
43  virtual GameObjectClasses get_class_types() const override { return MovingSprite::get_class_types().add(typeid(FallBlock)); }
44 
45  virtual void on_flip(float height) override;
46 
47 public:
48  Physic& get_physic() { return m_physic; }
49 
50  enum State
51  {
52  IDLE,
53  SHAKE,
54  FALL,
55  LAND
56  };
57 
58  State get_state() const { return m_state; }
59 
60 private:
61  State m_state;
62 
63  Physic m_physic;
64  Timer m_timer;
65 
66 private:
67  bool found_victim_down() const;
68 
69  FallBlock(const FallBlock&) = delete;
70  FallBlock& operator=(const FallBlock&) = delete;
71 };
72 
73 #endif
74 
75 /* EOF */
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: fallblock.cpp:41
Physics engine.
Definition: physic.hpp:27
Definition: fallblock.hpp:26
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
this function is called when the object collided with any other object
Definition: fallblock.cpp:71
virtual void collision_solid(const CollisionHit &hit) override
this function is called when the object collided with something solid
Definition: fallblock.cpp:91
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: moving_sprite.hpp:60
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: fallblock.cpp:107
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: fallblock.hpp:43
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: fallblock.hpp:42
virtual void on_flip(float height) override
When level is flipped vertically.
Definition: fallblock.cpp:139
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
Simple timer designed to be used in the update functions of objects.
Definition: timer.hpp:24
Definition: reader_mapping.hpp:32
Abstract base class for ""MovingObject""s, that are represented by a sprite.
Definition: moving_sprite.hpp:33
This module contains methods controlling the player.
Definition: player.hpp:47
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