supertux
door.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_TRIGGER_DOOR_HPP
18 #define HEADER_SUPERTUX_TRIGGER_DOOR_HPP
19 
20 #include "trigger/trigger_base.hpp"
21 
22 #include "supertux/timer.hpp"
23 
24 class Door final : public SpritedTrigger
25 {
26 public:
27  Door(const ReaderMapping& reader);
28 
29  static std::string class_name() { return "door"; }
30  virtual std::string get_class_name() const override { return class_name(); }
31  static std::string display_name() { return _("Door"); }
32  virtual std::string get_display_name() const override { return display_name(); }
33  virtual GameObjectClasses get_class_types() const override { return SpritedTrigger::get_class_types().add(typeid(Door)); }
34 
35  virtual ObjectSettings get_settings() override;
36  virtual void after_editor_set() override;
37 
38  virtual void update(float dt_sec) override;
39  virtual void draw(DrawingContext& context) override;
40  virtual void event(Player& player, EventType type) override;
41 
42  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
43 
44  virtual void on_flip(float height) override;
45 
46  bool is_locked() const { return m_locked; }
47  void unlock();
48 
49  Color get_lock_color() const { return m_lock_color; }
50 
51 private:
52  enum DoorState {
53  CLOSED,
54  OPENING,
55  OPEN,
56  CLOSING,
57  LOCKED,
58  UNLOCKING
59  };
60 
61 private:
62  DoorState m_state;
63  std::string m_target_sector;
64  std::string m_target_spawnpoint;
65  std::string m_script;
66  SpritePtr m_lock_sprite;
67  Timer m_stay_open_timer;
68  Timer m_unlocking_timer;
69  Timer m_lock_warn_timer;
70  bool m_locked;
71  Color m_lock_color;
72  bool m_transition_triggered;
73  Player* m_triggering_player;
74 
75 private:
76  Door(const Door&) = delete;
77  Door& operator=(const Door&) = delete;
78 };
79 
80 #endif
81 
82 /* EOF */
EventType
Definition: trigger_base.hpp:34
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: door.cpp:164
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: door.cpp:99
Definition: trigger_base.hpp:90
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
this function is called when the object collided with any other object
Definition: door.cpp:206
Definition: door.hpp:24
Definition: object_settings.hpp:39
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: door.hpp:33
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: trigger_base.hpp:95
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
virtual void on_flip(float height) override
When level is flipped vertically.
Definition: door.cpp:252
virtual void event(Player &player, EventType type) override
Receive trigger events.
Definition: door.cpp:178
Definition: color.hpp:26
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
This module contains methods controlling the player.
Definition: player.hpp:47
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: door.hpp:32
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