Included supertux.h stuff into it.
[supertux.git] / src / player.cpp
index 6052cc4..5c58bdd 100644 (file)
@@ -95,10 +95,11 @@ Player::init()
   keymap.right = SDLK_RIGHT;
   keymap.fire  = SDLK_LCTRL;
 
-  timer_init(&invincible_timer,true);
-  timer_init(&skidding_timer,true);
-  timer_init(&safe_timer,true);
-  timer_init(&frame_timer,true);
+  invincible_timer.init(true);
+  skidding_timer.init(true);
+  safe_timer.init(true);
+  frame_timer.init(true);
+
   physic.reset();
 }
 
@@ -148,15 +149,16 @@ Player::level_begin()
 
   player_input_init(&input);
 
-  timer_init(&invincible_timer,true);
-  timer_init(&skidding_timer,true);
-  timer_init(&safe_timer,true);
-  timer_init(&frame_timer,true);
+  invincible_timer.init(true);
+  skidding_timer.init(true);
+  safe_timer.init(true);
+  frame_timer.init(true);
+
   physic.reset();
 }
 
 void
-Player::action()
+Player::action(double frame_ratio)
 {
   bool jumped_in_solid = false;
 
@@ -168,7 +170,7 @@ Player::action()
   /* Move tux: */
   previous_base = base;
 
-  physic.apply(base.x, base.y);
+  physic.apply(frame_ratio, base.x, base.y);
 
   if (!dying)
     {
@@ -200,7 +202,7 @@ Player::action()
 
           physic.enable_gravity(false);
           /* Reset score multiplier (for multi-hits): */
-          score_multiplier = 1;
+          player_status.score_multiplier = 1;
         }
 
       if(jumped_in_solid)
@@ -208,26 +210,26 @@ Player::action()
           if (isbrick(base.x, base.y) ||
               isfullbox(base.x, base.y))
             {
-              trygrabdistro(base.x, base.y - 32,BOUNCE);
-              trybumpbadguy(base.x, base.y - 64);
+              World::current()->trygrabdistro(base.x, base.y - 32,BOUNCE);
+              World::current()->trybumpbadguy(base.x, base.y - 64);
 
-              trybreakbrick(base.x, base.y, size == SMALL);
+              World::current()->trybreakbrick(base.x, base.y, size == SMALL);
 
               bumpbrick(base.x, base.y);
-              tryemptybox(base.x, base.y, RIGHT);
+              World::current()->tryemptybox(base.x, base.y, RIGHT);
             }
 
           if (isbrick(base.x+ 31, base.y) ||
               isfullbox(base.x+ 31, base.y))
             {
-              trygrabdistro(base.x+ 31, base.y - 32,BOUNCE);
-              trybumpbadguy(base.x+ 31, base.y - 64);
+              World::current()->trygrabdistro(base.x+ 31, base.y - 32,BOUNCE);
+              World::current()->trybumpbadguy(base.x+ 31, base.y - 64);
 
               if(size == BIG)
-                trybreakbrick(base.x+ 31, base.y, size == SMALL);
+                World::current()->trybreakbrick(base.x+ 31, base.y, size == SMALL);
 
               bumpbrick(base.x+ 31, base.y);
-              tryemptybox(base.x+ 31, base.y, LEFT);
+              World::current()->tryemptybox(base.x+ 31, base.y, LEFT);
             }
         }
 
@@ -246,15 +248,13 @@ Player::action()
 
     }
 
-  timer_check(&safe_timer);
+  safe_timer.check();
 
 
   /* ---- DONE HANDLING TUX! --- */
 
   /* Handle invincibility timer: */
-
-
-  if (get_current_music() == HERRING_MUSIC && !timer_check(&invincible_timer))
+  if (get_current_music() == HERRING_MUSIC && !invincible_timer.check())
     {
       /*
          no, we are no more invincible
@@ -262,8 +262,8 @@ Player::action()
          but are we in hurry ?
        */
 
-
-      if (timer_get_left(&time_left) < TIME_WARNING)
+      // FIXME: Move this to gamesession
+      if (GameSession::current()->time_left.get_left() < TIME_WARNING)
         {
           /* yes, we are in hurry
              stop the herring_song, prepare to play the correct
@@ -285,10 +285,10 @@ Player::action()
   // timer_check(&skidding_timer); // disabled
 
   /* End of level? */
-
-  if (base.x >= endpos && endpos != 0)
+  if (base.x >= World::current()->get_level()->endpos
+      && World::current()->get_level()->endpos != 0)
     {
-      next_level = 1;
+      player_status.next_level = 1;
     }
 
 }
@@ -321,15 +321,15 @@ Player::handle_horizontal_input(int newdir)
 
   // skid if we're too fast
   if(dir != newdir && on_ground() && fabs(physic.get_velocity_x()) > SKID_XM 
-          && !timer_started(&skidding_timer))
+     && !skidding_timer.started())
     {
-      timer_start(&skidding_timer, SKID_TIME);
+      skidding_timer.start(SKID_TIME);
       play_sound(sounds[SND_SKID], SOUND_CENTER_SPEAKER);
       return;
     }
 
   if ((newdir ? (vx < 0) : (vx > 0)) && !isice(base.x, base.y + base.height) &&
-      !timer_started(&skidding_timer))
+      !skidding_timer.started())
     {
       //vx = 0;
     }
@@ -478,7 +478,7 @@ Player::handle_input()
 
   if (input.fire == DOWN && input.old_fire == UP && got_coffee)
     {
-      add_bullet(base.x, base.y, physic.get_velocity_x(), dir);
+      World::current()->add_bullet(base.x, base.y, physic.get_velocity_x(), dir);
     }
 
 
@@ -522,9 +522,9 @@ Player::handle_input()
 
   /* (Tux): */
 
-  if(!timer_check(&frame_timer))
+  if(!frame_timer.check())
     {
-      timer_start(&frame_timer,25);
+      frame_timer.start(25);
       if (input.right == UP && input.left == UP)
         {
           frame_main = 1;
@@ -551,16 +551,16 @@ Player::grabdistros()
   /* Grab distros: */
   if (!dying)
     {
-      trygrabdistro(base.x, base.y, NO_BOUNCE);
-      trygrabdistro(base.x+ 31, base.y, NO_BOUNCE);
+      World::current()->trygrabdistro(base.x, base.y, NO_BOUNCE);
+      World::current()->trygrabdistro(base.x+ 31, base.y, NO_BOUNCE);
 
-      trygrabdistro(base.x, base.y + base.height, NO_BOUNCE);
-      trygrabdistro(base.x+ 31, base.y + base.height, NO_BOUNCE);
+      World::current()->trygrabdistro(base.x, base.y + base.height, NO_BOUNCE);
+      World::current()->trygrabdistro(base.x+ 31, base.y + base.height, NO_BOUNCE);
 
       if(size == BIG)
         {
-          trygrabdistro(base.x, base.y + base.height / 2, NO_BOUNCE);
-          trygrabdistro(base.x+ 31, base.y + base.height / 2, NO_BOUNCE);
+          World::current()->trygrabdistro(base.x, base.y + base.height / 2, NO_BOUNCE);
+          World::current()->trygrabdistro(base.x+ 31, base.y + base.height / 2, NO_BOUNCE);
         }
 
     }
@@ -579,11 +579,11 @@ Player::grabdistros()
 void
 Player::draw()
 {
-  if (!timer_started(&safe_timer) || (global_frame_counter % 2) == 0)
+  if (!safe_timer.started() || (global_frame_counter % 2) == 0)
     {
       if (size == SMALL)
         {
-          if (timer_started(&invincible_timer))
+          if (invincible_timer.started())
             {
               /* Draw cape: */
 
@@ -602,7 +602,7 @@ Player::draw()
 
           if (!got_coffee)
             {
-              if (physic.get_velocity_y() > 0)
+              if (physic.get_velocity_y() != 0)
                 {
                   if (dir == RIGHT)
                     texture_draw(&smalltux_jump_right, base.x - scroll_x, base.y - 10);
@@ -645,7 +645,7 @@ Player::draw()
         }
       else
         {
-          if (timer_started(&invincible_timer))
+          if (invincible_timer.started())
             {
               /* Draw cape: */
               if (dir == RIGHT)
@@ -664,7 +664,7 @@ Player::draw()
             {
               if (!duck)
                 {
-                  if (!timer_started(&skidding_timer))
+                  if (!skidding_timer.started())
                     {
                       if (!jumping || physic.get_velocity_y() > 0)
                         {
@@ -725,7 +725,7 @@ Player::draw()
 
               if (!duck)
                 {
-                  if (!timer_started(&skidding_timer))
+                  if (!skidding_timer.started())
                     {
                       if (!jumping || physic.get_velocity_y() > 0)
                         {
@@ -799,7 +799,7 @@ Player::collision(void* p_c_object, int c_object)
       /* Hurt the player if he just touched it: */
 
       if (!pbad_c->dying && !dying &&
-          !timer_started(&safe_timer) &&
+          !safe_timer.started() &&
           pbad_c->mode != HELD)
         {
           if (pbad_c->mode == FLAT && input.fire == DOWN)
@@ -819,7 +819,7 @@ Player::collision(void* p_c_object, int c_object)
               else
                 {
                   /* Hurt if you get hit by kicked laptop: */
-                  if (!timer_started(&invincible_timer))
+                  if (!invincible_timer.started())
                     {
                       kill(SHRINK);
                     }
@@ -827,15 +827,15 @@ Player::collision(void* p_c_object, int c_object)
                     {
                       pbad_c->dying = DYING_FALLING;
                       play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
-                      add_score(pbad_c->base.x - scroll_x,
-                                pbad_c->base.y,
-                                25 * score_multiplier);
+                      World::current()->add_score(pbad_c->base.x - scroll_x,
+                                                  pbad_c->base.y,
+                                                  25 * player_status.score_multiplier);
                     }
                 }
             }
           else
             {
-              if (!timer_started(&invincible_timer ))
+              if (!invincible_timer.started())
                 {
                   kill(SHRINK);
                 }
@@ -844,7 +844,7 @@ Player::collision(void* p_c_object, int c_object)
                   pbad_c->kill_me();
                 }
             }
-          score_multiplier++;
+          player_status.score_multiplier++;
         }
       break;
     default:
@@ -870,7 +870,7 @@ Player::kill(int mode)
       size = SMALL;
       base.height = 32;
 
-      timer_start(&safe_timer,TUX_SAFE_TIME);
+      safe_timer.start(TUX_SAFE_TIME);
     }
   else
     {
@@ -914,6 +914,8 @@ Player::remove_powerups()
 void
 Player::keep_in_bounds()
 {
+  Level* plevel = World::current()->get_level();
+
   /* Keep tux in bounds: */
   if (base.x< 0)
     base.x= 0;
@@ -928,15 +930,17 @@ Player::keep_in_bounds()
         scroll_x = 0;
 
     }
-  else if (base.x> screen->w / 2 + scroll_x && scroll_x < ((current_level.width * 32) - screen->w))
+  else if (base.x > screen->w / 2 + scroll_x
+           && scroll_x < ((World::current()->get_level()->width * 32) - screen->w))
     {
-      /* Scroll the screen in past center: */
+      // FIXME: Scrolling needs to be handled by a seperate View
+      // class, doing it as a player huck is ugly
 
-      scroll_x = base.x- screen->w / 2;
-      /*base.x= 320 + scroll_x;*/
+      // Scroll the screen in past center:
+      scroll_x = base.x - screen->w / 2;
 
-      if (scroll_x > ((current_level.width * 32) - screen->w))
-        scroll_x = ((current_level.width * 32) - screen->w);
+      if (scroll_x > ((plevel->width * 32) - screen->w))
+        scroll_x = ((plevel->width * 32) - screen->w);
     }
   else if (base.x> 608 + scroll_x)
     {