* Coins inside boxes are now being counted. (We'll have to decide if we want the...
[supertux.git] / src / object / level_time.cpp
index bf86db6..5ac1ba2 100644 (file)
@@ -68,10 +68,18 @@ LevelTime::update(float elapsed_time)
 {
   if (!running) return;
 
-  time_left = std::max(time_left - elapsed_time, 0.0f);
+  int prev_time = (int) floor(time_left*5);
+  time_left -= elapsed_time;
   if(time_left <= 0) {
-    Sector::current()->player->kill(true);
-    stop();
+    if(time_left <= -5 || !Sector::current()->player->get_coins())
+    {
+      Sector::current()->player->kill(true);
+      stop();
+    }
+    if(prev_time != (int) floor(time_left*5))
+    {
+      Sector::current()->player->add_coins(-1);
+    }
   }
 }
 
@@ -108,8 +116,8 @@ LevelTime::stop()
 {
   running = false;
 }
-    
-float 
+
+float
 LevelTime::get_time()
 {
   return time_left;