supertux
switch.hpp
1 // SuperTux - Switch Trigger
2 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.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_SWITCH_HPP
18 #define HEADER_SUPERTUX_TRIGGER_SWITCH_HPP
19 
20 #include "trigger/trigger_base.hpp"
21 
22 class Switch final : public StickyTrigger
23 {
24 public:
25  Switch(const ReaderMapping& reader);
26  ~Switch() override;
27 
28  static std::string class_name() { return "switch"; }
29  virtual std::string get_class_name() const override { return class_name(); }
30  static std::string display_name() { return _("Switch"); }
31  virtual std::string get_display_name() const override { return display_name(); }
32  virtual GameObjectClasses get_class_types() const override { return StickyTrigger::get_class_types().add(typeid(Switch)); }
33 
34  virtual ObjectSettings get_settings() override;
35 
36  virtual void update(float dt_sec) override;
37  virtual void event(Player& player, EventType type) override;
38 
39  virtual void after_editor_set() override;
40  virtual void on_flip(float height) override;
41 
42 private:
43  enum SwitchState {
44  OFF,
45  TURN_ON,
46  ON,
47  TURN_OFF
48  };
49 
50 private:
51  std::string m_script;
52  std::string m_off_script;
53  SwitchState m_state;
54  bool m_bistable;
55  Direction m_dir;
56 
57 private:
58  Switch(const Switch&) = delete;
59  Switch& operator=(const Switch&) = delete;
60 };
61 
62 #endif
63 
64 /* 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: switch.cpp:75
EventType
Definition: trigger_base.hpp:34
virtual void event(Player &player, EventType type) override
Receive trigger events.
Definition: switch.cpp:115
Definition: switch.hpp:22
Definition: object_settings.hpp:39
virtual void on_flip(float height) override
When level is flipped vertically.
Definition: switch.cpp:148
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: switch.hpp:31
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
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: switch.hpp:32
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: trigger_base.hpp:117
Definition: trigger_base.hpp:112
Definition: reader_mapping.hpp:32
This module contains methods controlling the player.
Definition: player.hpp:47