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"
16 /** When to alert player they're low on time! */
17 static const float TIME_WARNING = 20;
19 LevelTime::LevelTime(const lisp::Lisp& reader)
22 lisp::ListIterator iter(&reader);
24 if(iter.item() == "time") {
25 iter.value()->get(time);
28 std::cerr << "Unknown token '" << iter.item()
29 << "' in LevelTime object.\n";
33 throw std::runtime_error("Invalid leveltime specified");
34 time_left.start(time);
37 LevelTime::~LevelTime()
41 LevelTime::update(float )
43 if(time_left.check()) {
44 Sector::current()->player->kill(Player::KILL);
49 LevelTime::draw(DrawingContext& context)
51 context.push_transform();
52 context.set_translation(Vector(0, 0));
56 if(time_left.get_timeleft() < 0) {
57 context.draw_text(white_text, _("TIME's UP"), Vector(SCREEN_WIDTH/2, 0),
58 CENTER_ALLIGN, LAYER_FOREGROUND1);
59 } else if (time_left.get_timeleft() > TIME_WARNING
60 || int(game_time * 2.5) % 2) {
61 snprintf(str, sizeof(str), " %d", int(time_left.get_timeleft()));
62 context.draw_text(white_text, _("TIME"),
63 Vector(SCREEN_WIDTH/2, 0), CENTER_ALLIGN, LAYER_FOREGROUND1);
64 context.draw_text(gold_text, str, Vector(SCREEN_WIDTH/2 + 4*16, 0),
65 CENTER_ALLIGN, LAYER_FOREGROUND1);
68 context.pop_transform();
71 IMPLEMENT_FACTORY(LevelTime, "leveltime");