3 #include "level_time.hpp"
8 #include "resources.hpp"
10 #include "gettext.hpp"
11 #include "object_factory.hpp"
12 #include "object/player.hpp"
13 #include "video/drawing_context.hpp"
14 #include "lisp/list_iterator.hpp"
17 /** When to alert player they're low on time! */
18 static const float TIME_WARNING = 20;
20 LevelTime::LevelTime(const lisp::Lisp& reader)
21 : final_level_time(0.f), final_remaining_time(0.f)
24 lisp::ListIterator iter(&reader);
26 if(iter.item() == "time") {
27 iter.value()->get(time);
30 msg_warning("Unknown token '" << iter.item()
31 << "' in LevelTime object");
35 throw std::runtime_error("Invalid leveltime specified");
36 time_left.start(time);
39 LevelTime::~LevelTime()
43 LevelTime::update(float )
45 if(time_left.check()) {
46 Sector::current()->player->kill(Player::KILL);
51 LevelTime::draw(DrawingContext& context)
53 context.push_transform();
54 context.set_translation(Vector(0, 0));
58 if(get_remaining_time() < 0) {
59 context.draw_text(white_text, _("TIME's UP"), Vector(SCREEN_WIDTH/2, BORDER_Y),
60 CENTER_ALLIGN, LAYER_FOREGROUND1);
61 } else if (get_remaining_time() > TIME_WARNING
62 || int(game_time * 2.5) % 2) {
63 snprintf(str, sizeof(str), " %d", int(get_remaining_time()));
64 context.draw_text(white_text, _("TIME"),
65 Vector(SCREEN_WIDTH/2, BORDER_Y), CENTER_ALLIGN, LAYER_FOREGROUND1);
66 context.draw_text(gold_text, str, Vector(SCREEN_WIDTH/2 + 4*16, BORDER_Y),
67 CENTER_ALLIGN, LAYER_FOREGROUND1);
70 context.pop_transform();
74 LevelTime::get_level_time()
76 if (!time_left.started())
77 return final_level_time;
78 return time_left.get_period();
82 LevelTime::get_remaining_time()
84 if (!time_left.started())
85 return final_remaining_time;
86 return time_left.get_timeleft();
92 final_level_time = time_left.get_period();
93 final_remaining_time = time_left.get_timeleft();
97 IMPLEMENT_FACTORY(LevelTime, "leveltime");