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 <string>
21 
22 #include "trigger/trigger_base.hpp"
23 
24 class ReaderMapping;
25 
26 class Switch final : public TriggerBase
27 {
28 public:
29  Switch(const ReaderMapping& reader);
30  virtual ~Switch();
31 
32  virtual std::string get_class() const override { return "switch"; }
33 
34  virtual ObjectSettings get_settings() override;
35  virtual void after_editor_set() override;
36 
37  virtual void update(float dt_sec) override;
38  virtual void draw(DrawingContext& context) override;
39  virtual void event(Player& player, EventType type) override;
40 
41 private:
42  enum SwitchState {
43  OFF,
44  TURN_ON,
45  ON,
46  TURN_OFF
47  };
48 
49 private:
50  std::string sprite_name;
51  SpritePtr sprite;
52  std::string script;
53  std::string off_script;
54  SwitchState state;
55  bool bistable;
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:76
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: switch.cpp:113
EventType
Definition: trigger_base.hpp:35
virtual void event(Player &player, EventType type) override
Receive trigger events.
Definition: switch.cpp:119
Definition: switch.hpp:26
Definition: object_settings.hpp:35
This class is the base class for all objects you can interact with in some way.
Definition: trigger_base.hpp:31
Definition: reader_mapping.hpp:31
Definition: player.hpp:39
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42