- converted text_type into a class
[supertux.git] / src / gameloop.cpp
index d2aadba..e711334 100644 (file)
@@ -65,10 +65,10 @@ GameSession::GameSession(const std::string& filename)
   //assert(!"Don't call me");
   current_ = this;
 
-  world = new World; // &::global_world;
+  world = new World;
 
-  timer_init(&fps_timer, true);
-  timer_init(&frame_timer, true);
+  fps_timer.init(true);
+  frame_timer.init(true);
 
   world->load(filename);
 }
@@ -81,10 +81,10 @@ GameSession::GameSession(const std::string& subset_, int levelnb_, int mode)
 
   current_ = this;
 
-  world = new World; // &::global_world;
+  world = new World;
 
-  timer_init(&fps_timer, true);
-  timer_init(&frame_timer, true);
+  fps_timer.init(true);
+  frame_timer.init(true);
 
   st_gl_mode = mode;
   
@@ -104,7 +104,6 @@ GameSession::GameSession(const std::string& subset_, int levelnb_, int mode)
     }
 
   world->get_level()->load_gfx();
-  loadshared();
   
   world->activate_bad_guys();
   world->activate_particle_systems();
@@ -116,7 +115,7 @@ GameSession::GameSession(const std::string& subset_, int levelnb_, int mode)
   if(st_gl_mode == ST_GL_PLAY || st_gl_mode == ST_GL_LOAD_LEVEL_FILE)
     levelintro();
 
-  timer_init(&time_left,true);
+  time_left.init(true);
   start_timers();
 
   if(st_gl_mode == ST_GL_LOAD_GAME)
@@ -138,13 +137,16 @@ GameSession::levelintro(void)
   clearscreen(0, 0, 0);
 
   sprintf(str, "LEVEL %d", levelnb);
-  text_drawf(&blue_text, str, 0, 200, A_HMIDDLE, A_TOP, 1);
+  blue_text->drawf(str, 0, 200, A_HMIDDLE, A_TOP, 1);
 
   sprintf(str, "%s", world->get_level()->name.c_str());
-  text_drawf(&gold_text, str, 0, 224, A_HMIDDLE, A_TOP, 1);
+  gold_text->drawf(str, 0, 224, A_HMIDDLE, A_TOP, 1);
 
+  sprintf(str, "by %s", world->get_level()->author.c_str());
+  gold_text->drawf(str, 0, 256, A_HMIDDLE, A_TOP, 1);
+  
   sprintf(str, "TUX x %d", tux.lives);
-  text_drawf(&white_text, str, 0, 256, A_HMIDDLE, A_TOP, 1);
+  white_text->drawf(str, 0, 288, A_HMIDDLE, A_TOP, 1);
 
   flipscreen();
 
@@ -156,7 +158,7 @@ GameSession::levelintro(void)
 void
 GameSession::start_timers()
 {
-  timer_start(&time_left, world->get_level()->time_left*1000);
+  time_left.start(world->get_level()->time_left*1000);
   st_pause_ticks_init();
   update_time = st_get_ticks();
 }
@@ -171,7 +173,7 @@ GameSession::process_events()
     {
       /* Check for menu-events, if the menu is shown */
       if(show_menu)
-        menu_event(event);
+        current_menu->event(event);
 
       switch(event.type)
         {
@@ -261,7 +263,7 @@ GameSession::process_events()
                 break;
               case SDLK_INSERT:
                 if(debug_mode)
-                  timer_start(&tux.invincible_timer,TUX_INVINCIBLE_TIME);
+                  tux.invincible_timer.start(TUX_INVINCIBLE_TIME);
                 break;
               case SDLK_l:
                 if(debug_mode)
@@ -363,7 +365,6 @@ GameSession::action(double frame_ratio)
               world->get_level()->free_song();
               world->arrays_free();
 
-              unloadshared();
               return(0);
             }
           tux.level_begin();
@@ -390,7 +391,6 @@ GameSession::action(double frame_ratio)
               world->get_level()->free_song();
               world->arrays_free();
 
-              unloadshared();
               return(0);
             } /* if (lives < 0) */
         }
@@ -449,7 +449,7 @@ GameSession::draw()
           fillrect(i % 2 ? (pause_menu_frame * i)%screen->w : -((pause_menu_frame * i)%screen->w) ,(i*20+pause_menu_frame)%screen->h,screen->w,10,20,20,20, rand() % 20 + 1);
         }
       fillrect(0,0,screen->w,screen->h,rand() % 50, rand() % 50, rand() % 50, 128);
-      text_drawf(&blue_text, "PAUSE - Press 'P' To Play", 0, 230, A_HMIDDLE, A_TOP, 1);
+      blue_text->drawf("PAUSE - Press 'P' To Play", 0, 230, A_HMIDDLE, A_TOP, 1);
     }
 
   if(show_menu)
@@ -473,8 +473,10 @@ GameSession::run()
 
   global_frame_counter = 0;
   game_pause = false;
-  timer_init(&fps_timer,true);
-  timer_init(&frame_timer,true);
+
+  fps_timer.init(true);
+  frame_timer.init(true);
+
   last_update_time = st_get_ticks();
   fps_cnt = 0;
 
@@ -500,9 +502,9 @@ GameSession::run()
       if(frame_ratio > 1.5) /* Quick hack to correct the unprecise CPU clocks a little bit. */
         frame_ratio = 1.5 + (frame_ratio - 1.5) * 0.85;
 
-      if(!timer_check(&frame_timer))
+      if(!frame_timer.check())
         {
-          timer_start(&frame_timer,25);
+          frame_timer.start(25);
           ++global_frame_counter;
         }
 
@@ -604,10 +606,10 @@ GameSession::run()
         SDL_Delay((11 - (update_time - last_update_time))/2);*/
 
       /* Handle time: */
-      if (timer_check(&time_left))
+      if (time_left.check())
         {
           /* are we low on time ? */
-          if ((timer_get_left(&time_left) < TIME_WARNING)
+          if (time_left.get_left() < TIME_WARNING
               && (get_current_music() != HURRYUP_MUSIC))     /* play the fast music */
             {
               set_current_music(HURRYUP_MUSIC);
@@ -615,18 +617,18 @@ GameSession::run()
             }
 
         }
-      else
+      else if(tux.dying == DYING_NOT)
         tux.kill(KILL);
 
       /* Calculate frames per second */
       if(show_fps)
         {
           ++fps_cnt;
-          fps_fps = (1000.0 / (float)timer_get_gone(&fps_timer)) * (float)fps_cnt;
+          fps_fps = (1000.0 / (float)fps_timer.get_gone()) * (float)fps_cnt;
 
-          if(!timer_check(&fps_timer))
+          if(!fps_timer.check())
             {
-              timer_start(&fps_timer,1000);
+              fps_timer.start(1000);
               fps_cnt = 0;
             }
         }
@@ -638,7 +640,6 @@ GameSession::run()
   world->get_level()->cleanup();
   world->get_level()->free_song();
 
-  unloadshared();
   world->arrays_free();
 
   return quit;
@@ -661,43 +662,43 @@ GameSession::drawstatus()
   char str[60];
 
   sprintf(str, "%d", player_status.score);
-  text_draw(&white_text, "SCORE", 0, 0, 1);
-  text_draw(&gold_text, str, 96, 0, 1);
+  white_text->draw("SCORE", 0, 0, 1);
+  gold_text->draw(str, 96, 0, 1);
 
   if(st_gl_mode != ST_GL_TEST)
     {
       sprintf(str, "%d", hs_score);
-      text_draw(&white_text, "HIGH", 0, 20, 1);
-      text_draw(&gold_text, str, 96, 20, 1);
+      white_text->draw("HIGH", 0, 20, 1);
+      gold_text->draw(str, 96, 20, 1);
     }
   else
     {
-      text_draw(&white_text,"Press ESC To Return",0,20,1);
+      white_text->draw("Press ESC To Return",0,20,1);
     }
 
-  if (timer_get_left(&time_left) > TIME_WARNING || (global_frame_counter % 10) < 5)
+  if (time_left.get_left() > TIME_WARNING || (global_frame_counter % 10) < 5)
     {
-      sprintf(str, "%d", timer_get_left(&time_left) / 1000 );
-      text_draw(&white_text, "TIME", 224, 0, 1);
-      text_draw(&gold_text, str, 304, 0, 1);
+      sprintf(str, "%d", time_left.get_left() / 1000 );
+      white_text->draw("TIME", 224, 0, 1);
+      gold_text->draw(str, 304, 0, 1);
     }
 
   sprintf(str, "%d", player_status.distros);
-  text_draw(&white_text, "DISTROS", screen->h, 0, 1);
-  text_draw(&gold_text, str, 608, 0, 1);
+  white_text->draw("DISTROS", screen->h, 0, 1);
+  gold_text->draw(str, 608, 0, 1);
 
-  text_draw(&white_text, "LIVES", screen->h, 20, 1);
+  white_text->draw("LIVES", screen->h, 20, 1);
 
   if(show_fps)
     {
       sprintf(str, "%2.1f", fps_fps);
-      text_draw(&white_text, "FPS", screen->h, 40, 1);
-      text_draw(&gold_text, str, screen->h + 60, 40, 1);
+      white_text->draw("FPS", screen->h, 40, 1);
+      gold_text->draw(str, screen->h + 60, 40, 1);
     }
 
   for(int i= 0; i < tux.lives; ++i)
     {
-      texture_draw(&tux_life,565+(18*i),20);
+      tux_life->draw(565+(18*i),20);
     }
 }
 
@@ -708,13 +709,13 @@ GameSession::drawendscreen()
 
   clearscreen(0, 0, 0);
 
-  text_drawf(&blue_text, "GAMEOVER", 0, 200, A_HMIDDLE, A_TOP, 1);
+  blue_text->drawf("GAMEOVER", 0, 200, A_HMIDDLE, A_TOP, 1);
 
   sprintf(str, "SCORE: %d", player_status.score);
-  text_drawf(&gold_text, str, 0, 224, A_HMIDDLE, A_TOP, 1);
+  gold_text->drawf(str, 0, 224, A_HMIDDLE, A_TOP, 1);
 
   sprintf(str, "DISTROS: %d", player_status.distros);
-  text_drawf(&gold_text, str, 0, 256, A_HMIDDLE, A_TOP, 1);
+  gold_text->drawf(str, 0, 256, A_HMIDDLE, A_TOP, 1);
 
   flipscreen();
   
@@ -729,13 +730,13 @@ GameSession::drawresultscreen(void)
 
   clearscreen(0, 0, 0);
 
-  text_drawf(&blue_text, "Result:", 0, 200, A_HMIDDLE, A_TOP, 1);
+  blue_text->drawf("Result:", 0, 200, A_HMIDDLE, A_TOP, 1);
 
   sprintf(str, "SCORE: %d", player_status.score);
-  text_drawf(&gold_text, str, 0, 224, A_HMIDDLE, A_TOP, 1);
+  gold_text->drawf(str, 0, 224, A_HMIDDLE, A_TOP, 1);
 
   sprintf(str, "DISTROS: %d", player_status.distros);
-  text_drawf(&gold_text, str, 0, 256, A_HMIDDLE, A_TOP, 1);
+  gold_text->drawf(str, 0, 256, A_HMIDDLE, A_TOP, 1);
 
   flipscreen();