fixed background drawing problems introduced with my last commit
[supertux.git] / src / gameloop.cpp
index 8500001..1b2914b 100644 (file)
 #include "app/setup.h"
 #include "high_scores.h"
 #include "gui/menu.h"
-#include "badguy.h"
 #include "sector.h"
-#include "player.h"
 #include "level.h"
 #include "scene.h"
-#include "collision.h"
 #include "tile.h"
-#include "particlesystem.h"
+#include "object/particlesystem.h"
+#include "object/background.h"
+#include "object/tilemap.h"
+#include "object/camera.h"
+#include "object/player.h"
 #include "resources.h"
-#include "background.h"
-#include "tilemap.h"
 #include "app/gettext.h"
 #include "worldmap.h"
 #include "intro.h"
 #include "misc.h"
-#include "camera.h"
 #include "statistics.h"
 #include "timer.h"
 #include "object/fireworks.h"
@@ -81,15 +79,14 @@ bool compare_last(std::string& haystack, std::string needle)
   return false;
 }
 
-GameSession::GameSession(const std::string& levelname_, int mode,
+GameSession::GameSession(const std::string& levelfile_, int mode,
     bool flip_level_, Statistics* statistics)
   : level(0), currentsector(0), st_gl_mode(mode),
-    end_sequence(NO_ENDSEQUENCE), levelname(levelname_), flip_level(flip_level_),
-    best_level_statistics(statistics)
+    end_sequence(NO_ENDSEQUENCE), levelfile(levelfile_),
+    flip_level(flip_level_), best_level_statistics(statistics)
 {
   current_ = this;
   
-  global_frame_counter = 0;
   game_pause = false;
   fps_fps = 0;
 
@@ -126,7 +123,7 @@ GameSession::restart_level()
   currentsector = 0;
 
   level = new Level;
-  level->load(levelname);
+  level->load(levelfile);
   if(flip_level)
     level->do_vertical_flip();
 
@@ -188,8 +185,13 @@ GameSession::levelintro(void)
   char str[60];
 
   DrawingContext context;
-  if(currentsector->background)
-    currentsector->background->draw(context);
+  for(Sector::GameObjects::iterator i = currentsector->gameobjects.begin();
+      i != currentsector->gameobjects.end(); ++i) {
+    Background* background = dynamic_cast<Background*> (*i);
+    if(background) {
+      background->draw(context);
+    }
+  }
 
 //  context.draw_text(gold_text, level->get_name(), Vector(screen->w/2, 160),
 //      CENTER_ALLIGN, LAYER_FOREGROUND1);
@@ -200,9 +202,10 @@ GameSession::levelintro(void)
   context.draw_text(white_text, str, Vector(screen->w/2, 210),
       CENTER_ALLIGN, LAYER_FOREGROUND1);
 
-  if(level->get_author().size())
+  if((level->get_author().size()) && (level->get_author() != "SuperTux Team"))
+    //TODO make author check case/blank-insensitive
     context.draw_text(white_small_text,
-      std::string(_("by ")) + level->get_author(), 
+      std::string(_("contributed by ")) + level->get_author(), 
       Vector(screen->w/2, 350), CENTER_ALLIGN, LAYER_FOREGROUND1);
 
 
@@ -464,6 +467,11 @@ GameSession::process_events()
                           tux.kill(tux.KILL);
                           last_keys.clear();
                           }
+                        if(compare_last(last_keys, "grid"))
+                          {    // toggle debug grid
+                          debug_grid = !debug_grid;
+                          last_keys.clear();
+                          }
                         if(compare_last(last_keys, "hover"))
                           {    // toggle hover ability on/off
                           tux.enable_hover = !tux.enable_hover;
@@ -719,20 +727,17 @@ GameSession::run()
   Uint32 lastticks = SDL_GetTicks();
   fps_ticks = SDL_GetTicks();
 
-  frame_timer.start(.025, true);
   while (exit_status == ES_NONE) {
     Uint32 ticks = SDL_GetTicks();
     float elapsed_time = float(ticks - lastticks) / 1000.;
-    global_time += elapsed_time;
+    if(!game_pause)
+      global_time += elapsed_time;
     lastticks = ticks;
+
     // 40fps is minimum
-    if(elapsed_time > .05)
-      elapsed_time = .05;
+    if(elapsed_time > .025)
+      elapsed_time = .025;
     
-    if(frame_timer.check()) {
-      ++global_frame_counter;
-    }
-
     /* Handle events: */
     currentsector->player->input.old_fire = currentsector->player->input.fire;
     currentsector->player->input.old_up = currentsector->player->input.old_up;
@@ -858,7 +863,7 @@ GameSession::drawstatus(DrawingContext& context)
     context.draw_text(white_text, _("TIME's UP"), Vector(screen->w/2, 0),
         CENTER_ALLIGN, LAYER_FOREGROUND1);
   } else if (time_left.get_timeleft() > TIME_WARNING
-      || (global_frame_counter % 10) < 5) {
+      || int(global_time * 2.5) % 2) {
     sprintf(str, " %d", int(time_left.get_timeleft()));
     context.draw_text(white_text, _("TIME"),
         Vector(screen->w/2, 0), CENTER_ALLIGN, LAYER_FOREGROUND1);
@@ -905,12 +910,18 @@ GameSession::drawstatus(DrawingContext& context)
 }
 
 void
-GameSession::drawresultscreen(void)
+GameSession::drawresultscreen()
 {
   char str[80];
 
   DrawingContext context;
-  currentsector->background->draw(context);  
+  for(Sector::GameObjects::iterator i = currentsector->gameobjects.begin();
+      i != currentsector->gameobjects.end(); ++i) {
+    Background* background = dynamic_cast<Background*> (*i);
+    if(background) {
+      background->draw(context);
+    }
+  }
 
   context.draw_text(blue_text, _("Result:"), Vector(screen->w/2, 200),
       CENTER_ALLIGN, LAYER_FOREGROUND1);