supertux
level_time.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_OBJECT_LEVEL_TIME_HPP
18 #define HEADER_SUPERTUX_OBJECT_LEVEL_TIME_HPP
19 
20 #include "supertux/game_object.hpp"
21 #include "video/color.hpp"
22 #include "video/surface_ptr.hpp"
23 
24 class ReaderMapping;
25 
32 class LevelTime final : public GameObject
33 {
34  static Color text_color;
35 
36 public:
37  static void register_class(ssq::VM& vm);
38 
39 public:
40  LevelTime(const ReaderMapping& reader);
41 
42  virtual void update(float dt_sec) override;
43  virtual void draw(DrawingContext& context) override;
44 
52  void start();
57  void stop();
62  float get_time() const;
68  void set_time(float time_left);
69 
72  static std::string class_name() { return "leveltime"; }
73  virtual std::string get_class_name() const override { return class_name(); }
74  virtual std::string get_exposed_class_name() const override { return "LevelTime"; }
75  static std::string display_name() { return _("Time Limit"); }
76  virtual std::string get_display_name() const override { return display_name(); }
77  virtual GameObjectClasses get_class_types() const override { return GameObject::get_class_types().add(typeid(LevelTime)); }
78 
79  virtual ObjectSettings get_settings() override;
80 
81  virtual const std::string get_icon_path() const override { return "images/engine/editor/clock.png"; }
82 
83 private:
84  SurfacePtr time_surface;
85  bool running;
86  float time_left;
87 
88 private:
89  LevelTime(const LevelTime&) = delete;
90  LevelTime& operator=(const LevelTime&) = delete;
91 };
92 
93 #endif
94 
95 /* EOF */
float get_time() const
Returns the number of seconds left on the clock.
Definition: level_time.cpp:148
A ""LevelTime"" that was given a name can be controlled by scripts.
Definition: level_time.hpp:32
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: level_time.hpp:77
Definition: object_settings.hpp:39
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: level_time.cpp:105
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: level_time.hpp:76
void stop()
Pauses the countdown (assuming it isn&#39;t already stopped, in which case it does nothing).
Definition: level_time.cpp:142
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
void set_time(float time_left)
Sets the number of seconds left on the clock.
Definition: level_time.cpp:154
virtual GameObjectClasses get_class_types() const
List notable classes in inheritance hierarchy of class.
Definition: game_object.cpp:113
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
void start()
Resumes the countdown (assuming it isn&#39;t already started, in which case it does nothing).
Definition: level_time.cpp:136
Definition: reader_mapping.hpp:32
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
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: level_time.cpp:61