supertux
unstable_tile.hpp
1 // SuperTux - Unstable Tile
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
4 // Copyright (C) 2010 Florian Forster <supertux at octo.it>
5 // 2023 Vankata453
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 
20 #ifndef HEADER_SUPERTUX_OBJECT_UNSTABLE_TILE_HPP
21 #define HEADER_SUPERTUX_OBJECT_UNSTABLE_TILE_HPP
22 
23 #include "object/moving_sprite.hpp"
24 
25 #include "supertux/physic.hpp"
26 #include "supertux/timer.hpp"
27 #include "util/fade_helper.hpp"
28 
30 class UnstableTile final : public MovingSprite
31 {
32 public:
33  UnstableTile(const ReaderMapping& mapping, int type = -1);
34 
35  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
36  virtual void update(float dt_sec) override;
37  virtual void draw(DrawingContext& context) override;
38  virtual void on_flip(float height) override;
39 
40  static std::string class_name() { return "unstable_tile"; }
41  virtual std::string get_class_name() const override { return class_name(); }
42  static std::string display_name() { return _("Unstable Tile"); }
43  virtual std::string get_display_name() const override { return display_name(); }
44  virtual GameObjectClasses get_class_types() const override { return MovingSprite::get_class_types().add(typeid(UnstableTile)); }
45 
46  GameObjectTypes get_types() const override;
47  std::string get_default_sprite_name() const override;
48 
49 public:
50  enum Type {
51  ICE,
52  BRICK,
53  DELAYED
54  };
55 
56 private:
57  enum State {
58  STATE_NORMAL,
59  STATE_SHAKE,
60  STATE_DISSOLVE,
61  STATE_SLOWFALL,
62  STATE_FALL
63  };
64 
65 private:
66  void shake();
67  void dissolve();
68  void fall_down();
69  void slow_fall();
70  void revive();
71 
72 private:
73  Physic physic;
74  State state;
75  float slowfall_timer;
76 
77  Timer m_revive_timer;
78  std::unique_ptr<FadeHelper> m_respawn;
79  float m_alpha;
80  Vector m_original_pos;
81 
83  Timer m_fall_timer;
84  bool m_player_hit;
85 
86 private:
87  UnstableTile(const UnstableTile&) = delete;
88  UnstableTile& operator=(const UnstableTile&) = delete;
89 };
90 
91 #endif
92 
93 /* EOF */
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: unstable_tile.hpp:43
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: unstable_tile.cpp:206
Physics engine.
Definition: physic.hpp:27
GameObjectTypes get_types() const override
Get all types of the object, if available.
Definition: unstable_tile.cpp:67
virtual void on_flip(float height) override
When level is flipped vertically.
Definition: unstable_tile.cpp:310
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: unstable_tile.hpp:44
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
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
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: unstable_tile.cpp:299
Definition: reader_mapping.hpp:32
Abstract base class for ""MovingObject""s, that are represented by a sprite.
Definition: moving_sprite.hpp:33
A block that disintegrates when stood on.
Definition: unstable_tile.hpp:30
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
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
this function is called when the object collided with any other object
Definition: unstable_tile.cpp:91