3 #include "level_time.hpp"
7 #include "resources.hpp"
10 #include "object_factory.hpp"
11 #include "object/player.hpp"
12 #include "video/drawing_context.hpp"
13 #include "lisp/list_iterator.hpp"
15 /** When to alert player they're low on time! */
16 static const float TIME_WARNING = 20;
18 LevelTime::LevelTime(const lisp::Lisp& reader)
21 lisp::ListIterator iter(&reader);
23 if(iter.item() == "time") {
24 iter.value()->get(time);
27 std::cerr << "Unknown token '" << iter.item()
28 << "' in LevelTime object.\n";
32 throw std::runtime_error("Invalid leveltime specified");
33 time_left.start(time);
36 LevelTime::~LevelTime()
40 LevelTime::update(float )
42 if(time_left.check()) {
43 Sector::current()->player->kill(Player::KILL);
48 LevelTime::draw(DrawingContext& context)
50 context.push_transform();
51 context.set_translation(Vector(0, 0));
55 if(time_left.get_timeleft() < 0) {
56 context.draw_text(white_text, _("TIME's UP"), Vector(SCREEN_WIDTH/2, 0),
57 CENTER_ALLIGN, LAYER_FOREGROUND1);
58 } else if (time_left.get_timeleft() > TIME_WARNING
59 || int(game_time * 2.5) % 2) {
60 snprintf(str, sizeof(str), " %d", int(time_left.get_timeleft()));
61 context.draw_text(white_text, _("TIME"),
62 Vector(SCREEN_WIDTH/2, 0), CENTER_ALLIGN, LAYER_FOREGROUND1);
63 context.draw_text(gold_text, str, Vector(SCREEN_WIDTH/2 + 4*16, 0),
64 CENTER_ALLIGN, LAYER_FOREGROUND1);
67 context.pop_transform();
70 IMPLEMENT_FACTORY(LevelTime, "leveltime");