Fixed creating level-subset again.
[supertux.git] / src / player.cpp
index d6f60e9..179b533 100644 (file)
@@ -27,6 +27,8 @@
 #include "sprite.h"
 #include "screen.h"
 
+#define AUTOSCROLL_DEAD_INTERVAL 300
+
 Surface* tux_life;
 
 Sprite* smalltux_gameover;
@@ -78,6 +80,7 @@ Player::init()
   base.ym = 0;
   previous_base = old_base = base;
   dir = RIGHT;
+  old_dir = dir;
   duck = false;
 
   dying   = DYING_NOT;
@@ -191,7 +194,7 @@ Player::action(double frame_ratio)
           base.x += frame_ratio * WALK_SPEED * (dir ? 1 : -1);
           previous_base = old_base = base;
         }
-      keep_in_bounds();
+      check_bounds();
 
       // Land:
       if (!on_ground())
@@ -295,9 +298,11 @@ Player::handle_horizontal_input()
 
   float dirsign = 0;
   if(input.left == DOWN && input.right == UP && (!duck || physic.get_velocity_y() != 0)) {
+      old_dir = dir;
       dir = LEFT;
       dirsign = -1;
   } else if(input.left == UP && input.right == DOWN && (!duck || physic.get_velocity_y() != 0)) {
+      old_dir = dir;
       dir = RIGHT;
       dirsign = 1;
   }
@@ -718,7 +723,7 @@ Player::is_dying()
 
 bool Player::is_dead()
 {
-  if(base.y > screen->h)
+  if(base.y > screen->h || base.x < scroll_x - AUTOSCROLL_DEAD_INTERVAL)  // last condition can happen in auto-scrolling
     return true;
   else
     return false;
@@ -734,20 +739,14 @@ Player::remove_powerups()
 }
 
 void
-Player::keep_in_bounds()
+Player::check_bounds()
 {
-  Level* plevel = World::current()->get_level();
-
   /* Keep tux in bounds: */
   if (base.x < 0)
     { // Lock Tux to the size of the level, so that he doesn't fall of
       // on the left side
       base.x = 0;
     }
-  else if (base.x < scroll_x)
-    { 
-      base.x = scroll_x;
-    }
 
   /* Keep in-bounds, vertically: */
   if (base.y > screen->h)
@@ -755,37 +754,17 @@ Player::keep_in_bounds()
       kill(KILL);
     }
 
-  int scroll_threshold = screen->w/2 - 80;
-  if (debug_mode)
-    {
-      scroll_x += screen->w/2;
-      // Backscrolling for debug mode
-      if (scroll_x < base.x - 80)
-        scroll_x = base.x - 80;
-      else if (scroll_x > base.x + 80)
-        scroll_x = base.x + 80;
-      scroll_x -= screen->w/2;
-
-      if(scroll_x < 0)
-        scroll_x = 0;
-    }
-  else
-    {
-      if (base.x > scroll_threshold + scroll_x
-          && scroll_x < ((World::current()->get_level()->width * 32) - screen->w))
-        {
-          // FIXME: Scrolling needs to be handled by a seperate View
-          // class, doing it as a player huck is ugly
-          
-          // Scroll the screen in past center:
-          scroll_x = base.x - scroll_threshold;
-          
-          // Lock the scrolling to the levelsize, so that we don't
-          // scroll over the right border
-          if (scroll_x > 32 * plevel->width - screen->w)
-            scroll_x = 32 * plevel->width - screen->w;
-        }
-    }
+  if(base.x < scroll_x)  // can happen if back scrolling is disabled
+    base.x = scroll_x;
+
+  if(base.x == scroll_x)
+    if(issolid(base.x, base.y) || issolid(base.x, base.y+32))
+      kill(KILL);
+
+  if(base.x + base.width > scroll_x + screen->w)
+    base.x = scroll_x + screen->w - base.width;
+
+    
 }
 
 // EOF //